Added backend and integration for FilterPage and CourseTable done
This commit is contained in:
11
server/models/Appointment.js
Normal file
11
server/models/Appointment.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const mongoose = require("mongoose");
|
||||
const { v4: uuidv4 } = require("uuid"); // For UUID generation
|
||||
|
||||
const AppointmentSchema = new mongoose.Schema({
|
||||
appointmentId: { type: String, default: uuidv4 }, // Auto-generate using UUID
|
||||
courseId: { type: String, required: true, ref: "Course" },
|
||||
facultyId: { type: String, required: true, ref: "Faculty" },
|
||||
appointmentType: { type: [String], required: true }, // Array of appointment types
|
||||
});
|
||||
|
||||
module.exports = mongoose.model("Appointment", AppointmentSchema);
|
||||
13
server/models/Course.js
Normal file
13
server/models/Course.js
Normal file
@@ -0,0 +1,13 @@
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const CourseSchema = new mongoose.Schema({
|
||||
courseId: { type: String, required: true, unique: true },
|
||||
name: { type: String, required: true },
|
||||
department: { type: String, required: true },
|
||||
program: { type: String, required: true },
|
||||
scheme: { type: String, required: true },
|
||||
semester: { type: Number, required: true },
|
||||
status: { type: String, enum: ["submitted", "not submitted"], default: "not submitted" },
|
||||
});
|
||||
|
||||
module.exports = mongoose.model("Course", CourseSchema);
|
||||
11
server/models/Faculty.js
Normal file
11
server/models/Faculty.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const FacultySchema = new mongoose.Schema({
|
||||
facultyId: { type: String, required: true, unique: true },
|
||||
name: { type: String, required: true },
|
||||
email: { type: String, required: true },
|
||||
department: { type: String, required: true },
|
||||
program: { type: String, required: true },
|
||||
});
|
||||
|
||||
module.exports = mongoose.model("Faculty", FacultySchema);
|
||||
36
server/package-lock.json
generated
36
server/package-lock.json
generated
@@ -25,7 +25,8 @@
|
||||
"passport": "^0.7.0",
|
||||
"passport-google-oauth20": "^2.0.0",
|
||||
"passport-local": "^1.0.0",
|
||||
"passport-local-mongoose": "^8.0.0"
|
||||
"passport-local-mongoose": "^8.0.0",
|
||||
"uuid": "^11.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^3.1.0"
|
||||
@@ -712,6 +713,18 @@
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/gaxios/node_modules/uuid": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
|
||||
"integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==",
|
||||
"funding": [
|
||||
"https://github.com/sponsors/broofa",
|
||||
"https://github.com/sponsors/ctavan"
|
||||
],
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/gcp-metadata": {
|
||||
"version": "5.3.0",
|
||||
"resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-5.3.0.tgz",
|
||||
@@ -898,6 +911,18 @@
|
||||
"node": ">=14.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/googleapis-common/node_modules/uuid": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
|
||||
"integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==",
|
||||
"funding": [
|
||||
"https://github.com/sponsors/broofa",
|
||||
"https://github.com/sponsors/ctavan"
|
||||
],
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/gopd": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.1.0.tgz",
|
||||
@@ -2219,16 +2244,15 @@
|
||||
}
|
||||
},
|
||||
"node_modules/uuid": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
|
||||
"integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==",
|
||||
"version": "11.0.3",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-11.0.3.tgz",
|
||||
"integrity": "sha512-d0z310fCWv5dJwnX1Y/MncBAqGMKEzlBb1AOf7z9K8ALnd0utBX/msg/fA0+sbyN1ihbMsLhrBlnl1ak7Wa0rg==",
|
||||
"funding": [
|
||||
"https://github.com/sponsors/broofa",
|
||||
"https://github.com/sponsors/ctavan"
|
||||
],
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
"uuid": "dist/esm/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/vary": {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"main": "sever.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build" : "npm install --prefix ../client && npm run build --prefix ../client && npm install",
|
||||
"build": "npm install --prefix ../client && npm run build --prefix ../client && npm install",
|
||||
"start": "nodemon server.js"
|
||||
},
|
||||
"repository": {
|
||||
@@ -34,7 +34,8 @@
|
||||
"passport": "^0.7.0",
|
||||
"passport-google-oauth20": "^2.0.0",
|
||||
"passport-local": "^1.0.0",
|
||||
"passport-local-mongoose": "^8.0.0"
|
||||
"passport-local-mongoose": "^8.0.0",
|
||||
"uuid": "^11.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^3.1.0"
|
||||
|
||||
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;
|
||||
@@ -1,25 +1,38 @@
|
||||
const express = require("express");
|
||||
const User = require("./models/User");
|
||||
const mongoose = require("mongoose");
|
||||
const bodyParser = require("body-parser");
|
||||
const cors = require("cors");
|
||||
require("dotenv").config();
|
||||
const passport = require("passport");
|
||||
const session = require("express-session");
|
||||
const bodyParser = require("body-parser");
|
||||
const bcrypt = require("bcryptjs");
|
||||
const LocalStrategy = require("passport-local").Strategy;
|
||||
const PasswordRouter = require("./routes/authRoutes");
|
||||
const crypto = require("crypto");
|
||||
const jwt = require("jsonwebtoken");
|
||||
const path = require("path");
|
||||
|
||||
const User = require("./models/User");
|
||||
const PasswordRouter = require("./routes/authRoutes");
|
||||
const courseRoutes = require("./routes/courseRoutes");
|
||||
const facultyRoutes = require("./routes/facultyRoutes");
|
||||
const appointmentRoutes = require("./routes/appointmentRoutes");
|
||||
|
||||
// Existing Database Connection
|
||||
const { connectdb } = require("./ConnectionDb");
|
||||
connectdb();
|
||||
|
||||
// MongoDB Connection
|
||||
mongoose
|
||||
.connect(process.env.mongoURI)
|
||||
.then(() => console.log("MongoDB connected"))
|
||||
.catch((err) => console.error("MongoDB connection error:", err));
|
||||
|
||||
const app = express();
|
||||
|
||||
// Middleware
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
app.use(
|
||||
session({
|
||||
secret: "secret",
|
||||
@@ -39,7 +52,7 @@ app.use(
|
||||
})
|
||||
);
|
||||
|
||||
// Passport configuration
|
||||
// Passport Configuration
|
||||
require("./config/passport");
|
||||
|
||||
passport.use(
|
||||
@@ -76,7 +89,11 @@ passport.deserializeUser((id, done) => {
|
||||
|
||||
// Routes
|
||||
app.use("/password", PasswordRouter);
|
||||
app.use("/api/courses", courseRoutes);
|
||||
app.use("/api/faculty", facultyRoutes);
|
||||
app.use("/api/appointments", appointmentRoutes);
|
||||
|
||||
// OAuth Routes
|
||||
app.get(
|
||||
"/auth/google",
|
||||
passport.authenticate("google", { scope: ["profile", "email"] })
|
||||
@@ -86,7 +103,7 @@ app.get(
|
||||
"/auth/google/callback",
|
||||
passport.authenticate("google", { failureRedirect: "/" }),
|
||||
function (req, res) {
|
||||
res.redirect("http://localhost:3000/Welcom");
|
||||
res.redirect("http://localhost:3000/Welcom");
|
||||
}
|
||||
);
|
||||
|
||||
@@ -174,15 +191,17 @@ app.get("/api/user/profile", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Serve static files
|
||||
// Serve Static Files
|
||||
app.use(express.static(path.join(__dirname, "../client/build")));
|
||||
|
||||
// Catch-all route to serve React app
|
||||
// Catch-All Route
|
||||
app.get("*", (req, res) =>
|
||||
res.sendFile(path.join(__dirname, "../client/build/index.html"))
|
||||
);
|
||||
|
||||
const Port = 8080;
|
||||
|
||||
// Start Server
|
||||
const Port = process.env.PORT || 8080;
|
||||
app.listen(Port, () => {
|
||||
console.log(`Server is Running at port ${Port}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user