Skip to content

Implement Book Management CRUD Operations

chi le requested to merge feat/book-management-crud-1765438244 into feat/-1762918120

Overview

This pull request introduces the core CRUD functionalities for Book management, including creating, retrieving, updating, patching, and deleting books. The implementation spans across controller, service, route, and model layers, ensuring a modular and maintainable codebase.


Changes by File

/controllers/bookController.js

  • Added controller methods for:
    • createBook: Handles book creation requests.
    • getAllBooks: Retrieves all books.
    • getBookById: Fetches a book by its ID.
    • updateBook: Updates a book entirely.
    • patchBook: Partially updates a book.
    • deleteBook: Deletes a book by ID.
  • Improved error handling for not found and validation errors.

/services/bookService.js

  • Implemented service logic for:
    • Validating book data (e.g., published year cannot be in the future).
    • Creating, retrieving, updating, patching, and deleting books.
    • Ensured proper error handling and data validation for each operation.

/routes/bookRoutes.js

  • Defined RESTful routes for book operations:
    • POST /books for creation.
    • GET /books for listing all books.
    • GET /books/:id for retrieving a specific book.
    • PUT /books/:id for full updates.
    • DELETE /books/:id for deletion.
  • Added route for searching books (GET /books/search).

/models/Book.js

  • Defined the Book schema with fields:
    • title, author, publishedYear, genre, and available.
  • Set up required validations and default values.

Summary

This PR establishes the foundational CRUD operations for Book management, ensuring robust validation, error handling, and a clean separation of concerns across the application layers.

Merge request reports