Skip to content

Commit

Permalink
test: test movie rating endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniiairapetian committed Jun 1, 2024
1 parent 161747e commit 682ddb8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
60 changes: 45 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
});



/**
Expand Down
1 change: 1 addition & 0 deletions log.txt
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions models.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let movieSchema = mongoose.Schema({
ImagePath: String,
Featured: Boolean,
Actors: [String],
R3playRating: [String],
InterestingFacts: [String],
Rating: String,
ReleaseDate: Date,
Expand Down

0 comments on commit 682ddb8

Please sign in to comment.