Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash-Vashishth authored Oct 14, 2024
2 parents 9c88341 + 1aa7bcb commit 02dd932
Show file tree
Hide file tree
Showing 37 changed files with 127,388 additions and 795 deletions.
47 changes: 47 additions & 0 deletions backend/controllers/StationController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Station from "../models/Stations.js";

export const createStation = async (req, res) => {
try {
const { name, location, stationCode, capacity, services } = req.body;

const newStation = new Station({
name,
location,
stationCode,
capacity,
services,
});

const savedStation = await newStation.save();

res.status(201).json({
message: "Station created successfully",
station: savedStation,
});
} catch (error) {
console.error("Error creating station:", error);
res.status(500).json({
message: "Failed to create station",
error: error.message,
});
}
};

export const getAllStations = async (req, res) => {
try {
const stations = await Station.find()
.populate("coolies", "name")
.populate("wheelchairs", "name")
.populate("cloakrooms", "name");

if (!stations || stations.length === 0) {
return res.status(404).json({ message: "No stations found" });
}

return res.status(200).json(stations);
} catch (error) {
return res
.status(500)
.json({ message: "Server error", error: error.message });
}
};
2 changes: 1 addition & 1 deletion backend/controllers/WheelchairController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import WheelchairBooking from "../models/WheelChairBooking.js";
import WheelchairBooking from "../models/WheelchairBooking.js";
import { io } from "../index.js";

// Controller to handle booking creation
Expand Down
74 changes: 74 additions & 0 deletions backend/controllers/stationBookingsController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import Station from "../models/Stations.js";
import CoolieBooking from "../models/CoolieBooking.js";
import WheelchairBooking from "../models/WheelchairBooking.js";
import CloakroomBooking from "../models/CloakroomBooking.js";

export const getStationBookings = async (req, res) => {
try {
const stationId = req.params.id;

const station = await Station.findById(stationId);
if (!station) {
return res.status(404).json({ message: "Station not found" });
}

const coolieBookings = await CoolieBooking.find({ station: stationId });
const wheelchairBookings = await WheelchairBooking.find({
station: stationId,
});
const cloakroomBookings = await CloakroomBooking.find({
station: stationId,
});

const response = {
station: station,
coolieBookings: coolieBookings,
wheelchairBookings: wheelchairBookings,
cloakroomBookings: cloakroomBookings,
};

return res.status(200).json(response);
} catch (error) {
return res.status(500).json({ message: error.message });
}
};

export const getCoolieBookingsByStation = async (req, res) => {
try {
const stationId = req.params.id;

const coolieBookings = await CoolieBooking.find({ station: stationId });

return res.status(200).json(coolieBookings);
} catch (error) {
return res.status(500).json({ message: error.message });
}
};

export const getWheelchairBookingsByStation = async (req, res) => {
try {
const stationId = req.params.id;

const wheelchairBookings = await WheelchairBooking.find({
station: stationId,
});

return res.status(200).json(wheelchairBookings);
} catch (error) {
return res.status(500).json({ message: error.message });
}
};

export const getCloakroomBookingsByStation = async (req, res) => {
try {
const stationId = req.params.id;

const cloakroomBookings = await CloakroomBooking.find({
station: stationId,
});

return res.status(200).json(cloakroomBookings);
} catch (error) {
return res.status(500).json({ message: error.message });
}
};
14 changes: 14 additions & 0 deletions backend/controllers/stationsController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import stations from "../dataset/stations.js"


//sending the data to frontend

export const sendStations = async (req,res) =>{

// console.log()
try{
res.json(stations);
}catch(err){
console.log("Error : ",err)
}
}
Loading

0 comments on commit 02dd932

Please sign in to comment.