Skip to content

Commit

Permalink
Merge branch 'AlfiyaSiddique:master' into profile_page
Browse files Browse the repository at this point in the history
  • Loading branch information
IkkiOcean authored Nov 8, 2024
2 parents 69cac0d + 878849a commit 666606f
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 18 deletions.
103 changes: 101 additions & 2 deletions backend/Controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import User from "../models/User.js";
import jwt from "jsonwebtoken";
import dotenv from "dotenv";
import Feedback from "../models/feedback.js";

import Recipe from "../models/Recipe.js";
import Comment from "../models/Comment.js";
dotenv.config();


Expand Down Expand Up @@ -256,18 +257,116 @@ const getAllFeedback = async (req, res) => {
});
}
}
const getFeedbackByUserId = async (req, res) => {
const { userId } = req.params; // Extract userId from params

try {
// Find all feedback entries by userId and populate user details
const feedbackEntries = await Feedback.find({ 'userId._id': userId }).populate('userId', 'firstName lastName profile');

// Check if feedback entries were found
if (!feedbackEntries.length) {
return res.status(404).json({
success: false,
message: "No feedback found for this user",
});
}

return res.status(200).json({
success: true,
message: "Feedback retrieved successfully!",
data: feedbackEntries,
});
} catch (error) {
console.error("Error retrieving feedback by userId:", error);
return res.status(500).json({
success: false,
message: "Error retrieving feedback",
});
}
};
// Feedback deletion controller
const deleteFeedbackById = async (req, res) => {
const { id } = req.body;

try {
// Find and delete the feedback by ID
const deletedFeedback = await Feedback.findByIdAndDelete(id);

// Check if feedback was found and deleted
if (!deletedFeedback) {
return res.status(404).json({
success: false,
message: "Feedback not found",
});
}

return res.status(200).json({
success: true,
message: "Feedback deleted successfully!",
});
} catch (error) {
console.error("Error deleting feedback:", error);
return res.status(500).json({
success: false,
message: "Error deleting feedback",
});
}
};




const deleteUserById = async (req, res) => {
const { id } = req.params;

try {
// Find the user by ID and delete
const deletedUser = await User.findByIdAndDelete(id);

// Check if the user was found and deleted
if (!deletedUser) {
return res.status(404).json({
success: false,
message: "User not found",
});
}


await Recipe.deleteMany({ user: id });
await Comment.deleteMany({ user: id });
await Feedback.deleteMany({ userId: id });


return res.status(200).json({
success: true,
message: "User deleted successfully!",
data: deletedUser,
});
} catch (error) {
console.error("Error deleting user:", error);
return res.status(500).json({
success: false,
message: "Error deleting user",
});
}
};


const UserController = {
Signup,
Login,
getAllUserName,
deleteUserById,
verifyUserByToken,
forgotPassword,
resetPassword,
UpdateImage,
FetchUser,
submitFeedback,
getAllFeedback
getAllFeedback,
getFeedbackByUserId,
deleteFeedbackById
};


Expand Down
5 changes: 4 additions & 1 deletion backend/routes/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ router.get("/recipe/getcomments/:recipeId", RecipeController.getComments);
router.post("/signup", UserController.Signup);
router.post("/login", UserController.Login);
router.post("/submitFeedback", UserController.submitFeedback);
router.get('/getFeedback', UserController.getAllFeedback);
router.get('/feedback', UserController.getAllFeedback);
router.get('/feedback/:id', UserController.getFeedbackByUserId);
router.post("/feedback/delete", UserController.deleteFeedbackById);
router.post("/user/imageUpdate", UserController.UpdateImage);
router.post("/user/fetch", UserController.FetchUser);
router.delete("/user/:id", UserController.deleteUserById);
router.post("/recipe/add", authenticateToken, RecipeController.addRecipe);
router.post("/recipe/update", authenticateToken, RecipeController.updateRecipe);
router.post(
Expand Down
4 changes: 4 additions & 0 deletions frontend/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
User-agent: *
Disallow: /private
Allow: /
Sitemap: https://delightful-daifuku-a9f6ea.netlify.app/sitemap.xml
14 changes: 14 additions & 0 deletions frontend/public/sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">

<url>
<loc>https://delightful-daifuku-a9f6ea.netlify.app/</loc>
<lastmod>2024-11-07T12:19:42+00:00</lastmod>
</url>


</urlset>
Loading

0 comments on commit 666606f

Please sign in to comment.