From 32e4428a673d4e2bc25ee9691c26587416642058 Mon Sep 17 00:00:00 2001
From: Nishant Kaushal <101548649+nishant0708@users.noreply.github.com>
Date: Sun, 28 Jul 2024 20:39:55 +0530
Subject: [PATCH] Added Feedback system
---
server/controllers/feedbackController.js | 15 +++++++-
server/routes/student.js | 7 +---
src/pages/FeedbackList.jsx | 48 ++++++++++++++++++++++++
src/pages/SectionPage.jsx | 47 +++++++++--------------
4 files changed, 81 insertions(+), 36 deletions(-)
create mode 100644 src/pages/FeedbackList.jsx
diff --git a/server/controllers/feedbackController.js b/server/controllers/feedbackController.js
index 89f12f1..dd30542 100644
--- a/server/controllers/feedbackController.js
+++ b/server/controllers/feedbackController.js
@@ -1,6 +1,19 @@
const asyncHandler = require('express-async-handler');
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) => {
const { message, canteenId ,userId} = req.body;
@@ -15,4 +28,4 @@ const submitFeedback = asyncHandler(async (req, res) => {
res.status(201).json({ message: 'Feedback submitted successfully' });
});
-module.exports = { submitFeedback };
\ No newline at end of file
+module.exports = { submitFeedback ,getFeedbacksByCanteen };
\ No newline at end of file
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.
+ )} +