From 682ddb883c668e53eb6ae9b1525b1710a34edfdf Mon Sep 17 00:00:00 2001 From: Yevhenii Airapetian Date: Sat, 1 Jun 2024 21:04:03 +0200 Subject: [PATCH] test: test movie rating endpoint --- index.js | 60 +++++++++++++++++++++++++++++++++++++++++-------------- log.txt | 1 + models.js | 1 + 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 3818110..8eda9d0 100644 --- a/index.js +++ b/index.js @@ -138,6 +138,37 @@ app.get('/movies/:movieTitle', passport.authenticate('jwt', { session: false }), }); }); +app.post('/movies/:movieTitle/R3playRating', passport.authenticate('jwt', { session: false }), async (req, res) => { + await Movies.findOneAndUpdate({ Title: req.params.movieTitle}, { + $push: { R3playRating: req.params.R3playRating }, +}, +{ new: true }) // This line makes sure that the updated document is returned + .then((updatedMovie) => { + res.status(201).json(updatedMovie); + }) + .catch((err) => { + console.error(err); + res.status(500).send('Error: ' + err); + }); +}); + + +app.post("/users/:id/watched/: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 get "/animes/:animeTitle" returning json object with an anime * @param {string} /movies/:movieTitle @@ -373,6 +404,19 @@ app.post("/users/:id/favorites/:movies/:MovieID", passport.authenticate('jwt', { }); + + + + + + + + + + + + + /** * 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 @@ -505,21 +549,7 @@ app.delete("/users/:id/favorites/:tvseries/:tvID", passport.authenticate('jwt', -app.post("/users/:id/watched/: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 -}); + /** diff --git a/log.txt b/log.txt index b2a91c7..7e5b624 100644 --- a/log.txt +++ b/log.txt @@ -1 +1,2 @@ 127.0.0.1 - - [31/May/2024:21:52:47 +0000] "GET /favicon.ico HTTP/1.1" 404 150 "http://localhost:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0" +127.0.0.1 - - [01/Jun/2024:12:10:18 +0000] "GET /favicon.ico HTTP/1.1" 404 150 "http://localhost:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0" diff --git a/models.js b/models.js index f4282c7..cd20dbe 100644 --- a/models.js +++ b/models.js @@ -21,6 +21,7 @@ let movieSchema = mongoose.Schema({ ImagePath: String, Featured: Boolean, Actors: [String], + R3playRating: [String], InterestingFacts: [String], Rating: String, ReleaseDate: Date,