Leaving Movie Reviews
Let's learn how to add reviews using the POST, PUT, and DELETE methods.
In this lesson, we’ll learn how to leave reviews for movies.
MOVIEREVIEWS_DB_URI=mongodb+srv://admin:hello@cluster0.yjxj4.mongodb.net/sample_mflix?retryWrites=true&w=majority MOVIEREVIEWS_NS=sample_mflix PORT=5000
So let’s create the routes to post, put, and delete reviews. The post method is for creating a review, put is for editing a review, and delete is for deleting reviews. In the route file movies.route.js, let’s add the routes, as shown below:
Line 3: We import the ReviewsController, which we’ll create later.
Lines 6–11: We then add a /review route that handles post, put, and delete HTTP requests within this one route call. That is to say, if the /review route receives a post HTTP request to add a review, we call apiPostReview. If /review receives a put HTTP request to edit a review, we call apiUpdateReview. Finally, if /review receives a delete HTTP request to delete a review, we call apiDeleteReview.
Creating the review controller
Next, let’s create reviews.controller.js with the following code:
Line 1: We first import ReviewsDAO, which we’ll create later.
Lines 4–11: We get ...