Skip to content

[JITERA] Implement PATCH endpoint for updating a book by ID

Klebson Leite requested to merge feat/patch-update-book-1744814533 into main

Created by: kstayner

Overview

This pull request modifies the existing updateBook method in the BookController to support PATCH requests, allowing for partial updates of book information. This change aligns with RESTful API practices, where PATCH is used for updating only specific fields of a resource.

Changes Made

  1. Updated updateBook Method:

    • The updateBook method in backend/src/controllers/bookController.js has been modified to handle PATCH requests.
    • The method now accepts a request body that can contain only the fields that need to be updated, rather than requiring the entire book object.
  2. Service Layer Adaptation:

    • Ensured that the BookService.updateBook method is capable of processing partial updates. This involves checking which fields are present in the request and updating only those fields in the database.
  3. Testing:

    • Added unit tests to verify that the PATCH endpoint correctly updates only the specified fields of a book.
    • Ensured that the existing PUT functionality remains intact and unaffected by this change.

This implementation enhances the flexibility of the API, allowing clients to update only the necessary fields without needing to send the entire book object.

Merge request reports