Skip to content

Commit

Permalink
db updates recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadil-K committed Oct 30, 2023
1 parent e2d6985 commit 50aecb9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
38 changes: 38 additions & 0 deletions backend/controllers/appController.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,42 @@ export async function resetPassword(req,res){
}
}

/** PUT: http://localhost:5001/api/updateRecommendation */
export async function updateRecommendation(req, res) {
const { username, recommendations } = req.body;

try {
const user = await UserModel.findOne({ username });

if (!user) {
return res.status(404).send({ error: "User not found" });
}

user.recommendations = recommendations;

await user.save();

return res.status(200).send({ message: "Recommendations updated successfully" });
} catch (error) {
return res.status(500).send({ error: "Failed to update recommendations" });
}
}

/** GET: http://localhost:5001/api/recommendation/:username */
export async function getRecommendation(req, res) {
const { username } = req.params;

try {
const user = await UserModel.findOne({ username });

if (!user) {
return res.status(404).send({ error: "User not found" });
}

const recommendations = user.recommendations;

return res.status(200).send({ recommendations });
} catch (error) {
return res.status(500).send({ error: "Failed to retrieve recommendations" });
}
}
3 changes: 2 additions & 1 deletion backend/models/User.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export const UserSchema = new mongoose.Schema({
lastName: { type: String},
mobile : { type : Number},
address: { type: String},
profile: { type: String}
profile: { type: String},
recommendation: { type: String},
});

export default mongoose.model.Users || mongoose.model('User', UserSchema );
2 changes: 2 additions & 0 deletions backend/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ router.route("/verifyOTP").get(controller.verifyOTP);
router.route("/createResetSession").get(controller.createResetSession);
// router.route("/youtube_videos").get(ml_controller.video_predict);
router.route("/spotify_recommend").get(ml_controller.spotify_recommend);
router.route("/getRecommendation").get(Auth, controller.getRecommendation);

/** PUT Methods */
router.route("/updateuser").put(Auth, controller.updateUser);
router.route("/resetPassword").put(controller.verifyUser, controller.resetPassword);
router.route("/updateRecommendation").put(Auth, controller.updateRecommendation);

export default router;
13 changes: 13 additions & 0 deletions frontend/src/pages/AI_Assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ const AI_Assistant = () => {
.catch((error) => console.error(error));
}, [emotion]);

useEffect(() => {
if (recommendations) {
axios.post('http://localhost:5001/api/update_recommendations', { recommendations })
.then((response) => {
console.log('Recommendations updated in the database:', response.data);
})
.catch((error) => {
console.error('Error updating recommendations in the database:', error);
});
}
}, [recommendations]);


const startRecording = async () => {
if (recording) {
if (mediaRecorderRef.current) {
Expand Down

0 comments on commit 50aecb9

Please sign in to comment.