Added backend and integration for FilterPage and CourseTable done

This commit is contained in:
Harshitha Shetty
2024-12-09 05:06:08 +05:30
parent 6b06b9722f
commit e22727eefd
16 changed files with 756 additions and 118 deletions

View 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;

View 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;

View 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;