Skip to content

Commit

Permalink
feat: add new endpoints, update schemas
Browse files Browse the repository at this point in the history
Add liked actor endpoints, update user schema
  • Loading branch information
yevheniiairapetian committed Jun 10, 2024
1 parent 795b9ef commit e3de7dd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@ app.get('/movies/:movieTitle', passport.authenticate('jwt', { session: false }),
// });
// });

app.post("/users/:id/liked/:actors/:ActorID", passport.authenticate('jwt', { session: false }), async (req, res) => {
await Users.findOneAndUpdate({ Username: req.params.id }, {
$push: { LikedActors: req.params.ActorID },

},
{ new: true }) // This line makes sure that the updated document is returned
.then((updatedUser) => {
res.status(201).json(updatedUser);
})
.catch((err) => {
console.error(err);
res.status(500).send('Error: ' + err);
});
//adds a favorite movies to the list of favorites
});




app.post("/users/:id/watched/:movies/:MovieID", passport.authenticate('jwt', { session: false }), async (req, res) => {
await Users.findOneAndUpdate({ Username: req.params.id }, {
Expand Down Expand Up @@ -681,6 +699,21 @@ app.delete("/users/:id/watched/:movies/:MovieID", passport.authenticate('jwt', {
});
});

app.delete("/users/:id/liked/:actors/:ActorID", passport.authenticate('jwt', { session: false }), async (req, res) => {
await Users.findOneAndUpdate({ Username: req.params.id }, {
$pull: { LikedActors: req.params.ActorID },

},
{ new: true }) // This line makes sure that the updated document is returned
.then((updatedUser) => {
res.status(201).json(updatedUser);
})
.catch((err) => {
console.error(err);
res.status(500).send('Error: ' + err);
});
});

/**
* API call to delete "/users/:id/:animes/:AnimeID" returning user json object with a deleted movie data (anime gets deleted from the FavoriteMovies)
* @param {string} /users/:id/:animes/:AnimeID
Expand Down
2 changes: 2 additions & 0 deletions models.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ let userSchema = mongoose.Schema({
}],
FavoriteMovies: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Movie',
ref: 'TVseries', ref: 'Anime'
}],
LikedActors: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Actor',
}]
});

Expand Down

0 comments on commit e3de7dd

Please sign in to comment.