diff --git a/server/controllers/feedbackController.js b/server/controllers/feedbackController.js
index 50bf67d..7ae26b1 100644
--- a/server/controllers/feedbackController.js
+++ b/server/controllers/feedbackController.js
@@ -1,12 +1,20 @@
const asyncHandler = require('express-async-handler');
-const Feedback = require('../models/studentfeedback');
-const { validationResult } = require('express-validator'); // For input validation
-// Middleware for input validation (example using express-validator)
-const validateFeedback = [
- check('message').notEmpty().withMessage('Message is required'),
- check('canteenId').notEmpty().withMessage('Canteen ID is required'),
- check('userId').notEmpty().withMessage('User ID is required')
-];
+const Feedback = require("../models/studentfeeback");
+
+const getFeedbacksByCanteen = asyncHandler(async (req, res) => {
+ const { canteenId } = req.params;
+
+ if (!canteenId) {
+ res.status(400);
+ throw new Error('Canteen ID is required');
+ }
+
+ const feedbacks = await Feedback.find({ canteenId });
+
+ res.status(200).json(feedbacks);
+});
+
+
const submitFeedback = asyncHandler(async (req, res) => {
// Validate request inputs
const errors = validationResult(req);
@@ -23,4 +31,7 @@ const submitFeedback = asyncHandler(async (req, res) => {
res.status(500).json({ error: 'Server error, could not submit feedback' });
}
});
-module.exports = { submitFeedback, validateFeedback };
+
+
+module.exports = { submitFeedback ,getFeedbacksByCanteen };
+
diff --git a/server/routes/student.js b/server/routes/student.js
index bd70acc..0bf0a7b 100644
--- a/server/routes/student.js
+++ b/server/routes/student.js
@@ -2,11 +2,8 @@ const express = require("express");
const { auth, studentAuth, isCanteen } = require("../middlewares/auth");
const router = express.Router();
const authController = require("../controllers/Auth");
-<<<<<<< HEAD
const { getCanteenData } = require("../controllers/canteenController");
-=======
const feedbackController = require("../controllers/feedbackController");
->>>>>>> 56cd98b40c82e9849270fe2c43ef735b8fe058bc
router.post("/studentSignup", authController.studentSignup);
router.post("/studentLogin", authController.studentLogin);
@@ -17,12 +14,10 @@ router.get("/resetPassword/:id/:token", authController.verifyLink);
router.post("/newPassword/:id/:token", authController.resetPassword);
router.get("/studentLogout", studentAuth, authController.studentLogout);
router.get("/canteenLogout", auth, authController.canteenLogout);
-<<<<<<< HEAD
router.get("/canteen/:id", getCanteenData);
-=======
router.post('/submitFeedback', feedbackController.submitFeedback);
+router.get('/feedbacks/:canteenId', feedbackController.getFeedbacksByCanteen);
->>>>>>> 56cd98b40c82e9849270fe2c43ef735b8fe058bc
router.post(
"/changeStudentPassword",
studentAuth,
diff --git a/src/pages/FeedbackList.jsx b/src/pages/FeedbackList.jsx
new file mode 100644
index 0000000..e75811e
--- /dev/null
+++ b/src/pages/FeedbackList.jsx
@@ -0,0 +1,48 @@
+import React, { useState, useEffect, useContext } from "react";
+import { useParams } from "react-router-dom";
+import axios from "axios";
+import Loader from "../components/Loader/Loader";
+import { ThemeContext } from "../themeContext";
+
+const FeedbackList = () => {
+ const { _id } = useParams();
+ const { theme } = useContext(ThemeContext);
+ const [feedbacks, setFeedbacks] = useState([]);
+ const [loading, setLoading] = useState(false);
+
+ useEffect(() => {
+ const fetchFeedbacks = async () => {
+ setLoading(true);
+ try {
+ const response = await axios.get(`${process.env.REACT_APP_BASE_URL}/feedbacks/${_id}`);
+ setFeedbacks(response.data);
+ } catch (error) {
+ console.error("Error fetching feedbacks:", error);
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ fetchFeedbacks();
+ }, [_id]);
+
+ if (loading) return
{feedback.message}
+User ID: {feedback.userId}
+No feedback available.
+ )} +