Skip to content

[JITERA] Implement "Get all books" functionality

chi le requested to merge feat/get-all-books-1762163639 into main

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

  1. Controller (bookController.js):

    • Added the getAllBooks method 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);
    };
  2. Service (bookService.js):

    • Implemented the getAllBooks function that interacts with the database to fetch all book entries using Book.find().
    exports.getAllBooks = async () => {
        return await Book.find();
    };
  3. Routes (bookRoutes.js):

    • Configured the route /books to map to the getAllBooks controller method, allowing clients to access the list of books.
    router.get('/books', bookController.getAllBooks);

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.

Merge request reports