Skip to content

Commit

Permalink
test: test add watched
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniiairapetian committed May 31, 2024
1 parent c71f65b commit 75c3d36
Showing 1 changed file with 165 additions and 6 deletions.
171 changes: 165 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ app.post("/users", [

app.post("/users/:id/:movies/:MovieID", passport.authenticate('jwt', { session: false }), async (req, res) => {
await Users.findOneAndUpdate({ Username: req.params.id }, {
$push: { FavoriteMovies: req.params.MovieID, WatchedMovies: req.params.MovieID },
$push: { FavoriteMovies: req.params.MovieID },

},
{ new: true }) // This line makes sure that the updated document is returned
Expand All @@ -384,7 +384,7 @@ app.post("/users/:id/:movies/:MovieID", passport.authenticate('jwt', { session:

app.post("/users/:id/:animes/:AnimeID", passport.authenticate('jwt', { session: false }), async (req, res) => {
await Users.findOneAndUpdate({ Username: req.params.id }, {
$push: { FavoriteMovies: req.params.AnimeID, WatchedMovies: req.params.AnimeID },
$push: { FavoriteMovies: req.params.AnimeID },

},
{ new: true }) // This line makes sure that the updated document is returned
Expand All @@ -408,7 +408,7 @@ app.post("/users/:id/:animes/:AnimeID", passport.authenticate('jwt', { session:

app.post("/users/:id/:tvseries/:tvID", passport.authenticate('jwt', { session: false }), async (req, res) => {
await Users.findOneAndUpdate({ Username: req.params.id }, {
$push: { FavoriteMovies: req.params.tvID, WatchedMovies: req.params.tvID },
$push: { FavoriteMovies: req.params.tvID },

},
{ new: true }) // This line makes sure that the updated document is returned
Expand All @@ -433,7 +433,7 @@ app.post("/users/:id/:tvseries/:tvID", passport.authenticate('jwt', { session: f

app.delete("/users/:id/:movies/:MovieID", passport.authenticate('jwt', { session: false }), async (req, res) => {
await Users.findOneAndUpdate({ Username: req.params.id }, {
$pull: { FavoriteMovies: req.params.MovieID, WatchedMovies: req.params.MovieID },
$pull: { FavoriteMovies: req.params.MovieID },

},
{ new: true }) // This line makes sure that the updated document is returned
Expand All @@ -457,7 +457,7 @@ app.delete("/users/:id/:movies/:MovieID", passport.authenticate('jwt', { session

app.delete("/users/:id/:animes/:AnimeID", passport.authenticate('jwt', { session: false }), async (req, res) => {
await Users.findOneAndUpdate({ Username: req.params.id }, {
$pull: { FavoriteMovies: req.params.AnimeID, WatchedMovies: req.params.AnimeID },
$pull: { FavoriteMovies: req.params.AnimeID },


},
Expand All @@ -482,7 +482,7 @@ app.delete("/users/:id/:animes/:AnimeID", passport.authenticate('jwt', { session

app.delete("/users/:id/:tvseries/:tvID", passport.authenticate('jwt', { session: false }), async (req, res) => {
await Users.findOneAndUpdate({ Username: req.params.id }, {
$pull: { FavoriteMovies: req.params.tvID, WatchedMovies: req.params.tvID },
$pull: { FavoriteMovies: req.params.tvID },


},
Expand All @@ -497,6 +497,165 @@ app.delete("/users/:id/:tvseries/:tvID", passport.authenticate('jwt', { session:
});


















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

},
{ 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
});


/**
* API call to post "/users/:id/:animes/:AnimeID" returning user json object with a favorite anime data (anime gets pushed to favoriteMovies)
* @param {string} /users/:id/:animes/:AnimeID
* @param {} returning user json object with a favorite anime data (anime gets pushed to favoriteMovies)
* @name postAnime
* @async
*/


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

},
{ 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 post "/users/:id/:tvseries/:tvID" returning user json object with a favorite movie data (tv series gets pushed to favoriteMovies)
* @param {string} /users/:id/:tvseries/:tvID
* @param {} returning user json object with a favorite movie data (tv series gets pushed to favoriteMovies)
* @name postTV
* @async
*/

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

},
{ 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 tv series to the list of favorites
});


/**
* API call to delete "/users/:id/:movies/:MovieID" returning user json object with a deleted movie data
* @param {string} /users/:id/:movies/:MovieID
* @param {} returning user json object with a deleted movie data
* @name deleteMovie
* @async
*/

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

},
{ 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);
});
//deletes a movies from the favorites list
});

/**
* 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
* @param {} returning user json object with a deleted movie data (anime gets deleted from the FavoriteMovies)
* @name deleteAnime
* @async
*/

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


},
{ 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/:tvseries/:tvID" returning user json object with a deleted movie data (tv series gets deleted from the FavoriteMovies)
* @param {string} /users/:id/:tvseries/:tvID
* @param {} returning user json object with a deleted movie data (tv series gets deleted from the FavoriteMovies)
* @name deleteTV
* @async
*/

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


},
{ 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 put "/users/:id" returning user json object with an updated user data
* @param {object} {Username: string,
Expand Down

0 comments on commit 75c3d36

Please sign in to comment.