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;