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 ; + + return ( +
+

Feedbacks

+ {feedbacks.length > 0 ? ( + feedbacks.map((feedback) => ( +
+

{feedback.message}

+

User ID: {feedback.userId}

+
+ )) + ) : ( +

No feedback available.

+ )} +
+ ); +}; + +export default FeedbackList; diff --git a/src/pages/SectionPage.jsx b/src/pages/SectionPage.jsx index a54d249..d5930f3 100644 --- a/src/pages/SectionPage.jsx +++ b/src/pages/SectionPage.jsx @@ -1,30 +1,25 @@ import React, { useState, useEffect, useContext } from "react"; import { useParams, useNavigate } from "react-router-dom"; -import Modal from "../components/Modal"; import Navbar from "../components/Navbar"; import Loader from "../components/Loader/Loader"; import Footer from "../components/Footer"; import AddFoodItem from "./AddFoodItem"; -import EditProfile from "./EditProfile"; import Foodlist from "./Foodlist"; +import FeedbackList from "./FeedbackList"; // Import the new component import { ThemeContext } from "../themeContext"; import { FaRegEdit } from "react-icons/fa"; import { CiBoxList } from "react-icons/ci"; import { IoMdAdd } from "react-icons/io"; +import { FaComments } from "react-icons/fa"; // Import an icon for feedback + const SectionPage = () => { const { _id } = useParams(); const navigate = useNavigate(); const { theme } = useContext(ThemeContext); - const [showModal, setShowModal] = useState(false); - const [selectedSection, setSelectedSection] = useState(""); - const [formData, setFormData] = useState(null); - const [selectedBreakfastRecipes, setSelectedBreakfastRecipes] = useState([]); - const [selectedLunchRecipes, setSelectedLunchRecipes] = useState([]); - const [selectedDinnerRecipes, setSelectedDinnerRecipes] = useState([]); const [loading, setLoading] = useState(false); const [canteenData, setCanteenData] = useState(); const [view, setView] = useState("add"); - + const getCanteenData = async () => { try { setLoading(true); @@ -50,23 +45,6 @@ const SectionPage = () => { getCanteenData(); }, [_id]); - const handleSectionClick = (sectionName) => { - setSelectedSection(sectionName); - setShowModal(true); - }; - - const handleFormSubmit = (data) => { - if (selectedSection === "Breakfast") { - setSelectedBreakfastRecipes([...selectedBreakfastRecipes, data]); - } else if (selectedSection === "Lunch") { - setSelectedLunchRecipes([...selectedLunchRecipes, data]); - } else if (selectedSection === "Dinner") { - setSelectedDinnerRecipes([...selectedDinnerRecipes, data]); - } - setFormData(data); - setShowModal(false); - }; - return (
{
- {loading ? ( ) : ( @@ -114,9 +91,21 @@ const SectionPage = () => { > Product List +
-
- {view === "add" ? : } +
+ {view === "add" && } + {view === "list" && } + {view === "feedback" && } {/* Render FeedbackList */}
)}