diff --git a/backend/app.js b/backend/app.js index d82646af..38a34d4d 100644 --- a/backend/app.js +++ b/backend/app.js @@ -3,6 +3,7 @@ import dotenv from "dotenv"; import connectDB from "./utils/db.js"; import blogRoutes from "./routes/blogRoutes.js"; import userRoutes from "./routes/userRoutes.js"; +import feedbackRoutes from "./routes/feebackroute.js"; import cors from "cors"; dotenv.config(); @@ -16,6 +17,7 @@ app.use(cors()); app.use("/api/users", userRoutes); app.use("/api/blogs", blogRoutes); +app.use("/api/feedback", feedbackRoutes); const PORT = process.env.PORT || 5000; app.listen(PORT, () => { diff --git a/backend/controllers/feedbackcontroller.js b/backend/controllers/feedbackcontroller.js new file mode 100644 index 00000000..335652f2 --- /dev/null +++ b/backend/controllers/feedbackcontroller.js @@ -0,0 +1,24 @@ +import feedback from "../models/feedback.js"; + +export async function saveFeedback(req, resp) { + try { + const { name, userfeedback, email, rating } = req.body; + + if (!name || !userfeedback || !email || typeof rating !== "number") { + return resp.status(400).json({ message: "All fields are required." }); + } + + const newfeedback = new feedback({ name, userfeedback, email, rating }); + + // Save feedback to the database + await newfeedback.save(); + + // Respond with success message + resp + .status(201) + .json({ message: "Feedback saved successfully!", newfeedback }); + } catch (error) { + console.error("Error saving feedback:", error); + resp.status(500).json({ message: "Failed to save feedback.", error }); + } +} diff --git a/backend/models/feedback.js b/backend/models/feedback.js new file mode 100644 index 00000000..08064d10 --- /dev/null +++ b/backend/models/feedback.js @@ -0,0 +1,29 @@ +import { mongoose } from "mongoose"; + +const feedbackSchema = new mongoose.Schema( + { + name: { + type: String, + required: true, + trim: true, + }, + userfeedback: { + type: String, + required: true, + trim: true, + }, + email: { + type: String, + required: true, + }, + rating: { + type: Number, + required: true, + }, + }, + { timestamps: true } +); + +const feedback = mongoose.model(" feedback", feedbackSchema); + +export default feedback; diff --git a/backend/routes/feebackroute.js b/backend/routes/feebackroute.js new file mode 100644 index 00000000..51a5ed41 --- /dev/null +++ b/backend/routes/feebackroute.js @@ -0,0 +1,7 @@ +import express from "express"; +const router = express.Router(); +import { saveFeedback } from "../controllers/feedbackcontroller.js"; + +router.post("/savefeedback", saveFeedback); + +export default router; diff --git a/give_feedback.html b/give_feedback.html index c4d93471..f238ae1c 100644 --- a/give_feedback.html +++ b/give_feedback.html @@ -532,11 +532,62 @@

- - + + + + +