[JITERA] Implement "Get all books" functionality
Created by: chi-jitera
Overview
This pull request implements the "Get all books" functionality in the project. The feature is already present in the codebase and adheres to the project's conventions and architecture.
Explanation of Changes
-
Controller (
bookController.js):- Added the
getAllBooksmethod that handles the HTTP request to retrieve all books. - Utilizes the service layer to fetch the data and returns it as a JSON response.
exports.getAllBooks = async (req, res) => { const books = await bookService.getAllBooks(); res.json(books); }; - Added the
-
Service (
bookService.js):- Implemented the
getAllBooksfunction that interacts with the database to fetch all book entries usingBook.find().
exports.getAllBooks = async () => { return await Book.find(); }; - Implemented the
-
Routes (
bookRoutes.js):- Configured the route
/booksto map to thegetAllBookscontroller method, allowing clients to access the list of books.
router.get('/books', bookController.getAllBooks); - Configured the route
Conclusion
The implementation follows the project's architecture pattern, utilizing a clear separation of concerns between the controller, service, and route layers. It adheres to the coding conventions established in the project, ensuring maintainability and readability.