[JITERA] Implement Review functionality for Books
Created by: chi-jitera
Overview
This pull request introduces a new Review feature to the existing Book resources. It includes the creation of a Review model, service, controller, and the necessary route to fetch reviews for a specific book.
Changes
-
models/Review.js:
- Created a Review model with the following fields:
-
book: ObjectId referencing the Book model (required) -
reviewer: String to store the reviewer's name (required) -
rating: Number to store the rating given by the reviewer (required) -
comment: String for additional comments by the reviewer.
-
- Created a Review model with the following fields:
-
services/reviewService.js:
- Added a service to fetch reviews based on the book ID. This service interacts with the Review model to retrieve the relevant reviews.
-
controllers/reviewController.js:
- Implemented a controller that handles the request to fetch reviews for a specific book. It utilizes the review service to get the data and returns it in JSON format.
-
routes/bookRoutes.js:
- Updated the book routes to include a new endpoint
GET /books/:id/reviewsthat maps to thegetBookReviewsmethod in the review controller.
- Updated the book routes to include a new endpoint
This implementation provides a solid foundation for managing reviews associated with books and can be further customized as needed.