Added backend and integration for FilterPage and CourseTable done
This commit is contained in:
51
server/routes/appointmentRoutes.js
Normal file
51
server/routes/appointmentRoutes.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const express = require("express");
|
||||
const Appointment = require("../models/Appointment");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Get all appointments
|
||||
router.get("/", async (req, res) => {
|
||||
try {
|
||||
const appointments = await Appointment.find()
|
||||
.populate("courseId", "name department")
|
||||
.populate("facultyId", "name email");
|
||||
res.json(appointments);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Failed to fetch appointments" });
|
||||
}
|
||||
});
|
||||
|
||||
// Create a new appointment
|
||||
router.post("/", async (req, res) => {
|
||||
try {
|
||||
const { courseId, facultyId, appointmentType } = req.body;
|
||||
|
||||
const newAppointment = new Appointment({
|
||||
courseId,
|
||||
facultyId,
|
||||
appointmentType,
|
||||
});
|
||||
|
||||
await newAppointment.save();
|
||||
res.status(201).json(newAppointment);
|
||||
} catch (error) {
|
||||
res.status(400).json({ error: "Failed to create appointment" });
|
||||
}
|
||||
});
|
||||
|
||||
// Get appointment by ID
|
||||
router.get("/:id", async (req, res) => {
|
||||
try {
|
||||
const appointment = await Appointment.findOne({ appointmentId: req.params.id })
|
||||
.populate("courseId", "name department")
|
||||
.populate("facultyId", "name email");
|
||||
if (!appointment) {
|
||||
return res.status(404).json({ error: "Appointment not found" });
|
||||
}
|
||||
res.json(appointment);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Failed to fetch appointment" });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
38
server/routes/courseRoutes.js
Normal file
38
server/routes/courseRoutes.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const express = require("express");
|
||||
const Course = require("../models/Course");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/", async (req, res) => {
|
||||
try {
|
||||
const filter = {};
|
||||
|
||||
if (req.query.department) filter.department = req.query.department;
|
||||
if (req.query.program) filter.program = req.query.program;
|
||||
if (req.query.semester) filter.semester = Number(req.query.semester); // Convert to number if needed
|
||||
if (req.query.scheme) filter.scheme = req.query.scheme;
|
||||
|
||||
const courses = await Course.find(filter);
|
||||
res.json(courses);
|
||||
} catch (error) {
|
||||
console.error("Error fetching courses:", error);
|
||||
res.status(500).json({ error: "Failed to fetch courses" });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Get course by ID
|
||||
router.get("/:id", async (req, res) => {
|
||||
try {
|
||||
const course = await Course.findOne({ courseId: req.params.id });
|
||||
if (!course) {
|
||||
return res.status(404).json({ error: "Course not found" });
|
||||
}
|
||||
res.json(course);
|
||||
} catch (error) {
|
||||
console.error("Error fetching course:", error);
|
||||
res.status(500).json({ error: "Failed to fetch course" });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
29
server/routes/facultyRoutes.js
Normal file
29
server/routes/facultyRoutes.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const express = require("express");
|
||||
const Faculty = require("../models/Faculty");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Get all faculty members
|
||||
router.get("/", async (req, res) => {
|
||||
try {
|
||||
const faculty = await Faculty.find();
|
||||
res.json(faculty);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Failed to fetch faculty members" });
|
||||
}
|
||||
});
|
||||
|
||||
// Get faculty by ID
|
||||
router.get("/:id", async (req, res) => {
|
||||
try {
|
||||
const faculty = await Faculty.findOne({ facultyId: req.params.id });
|
||||
if (!faculty) {
|
||||
return res.status(404).json({ error: "Faculty member not found" });
|
||||
}
|
||||
res.json(faculty);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Failed to fetch faculty member" });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user