Skip to content

[JITERA] Implement PATCH /books/:id Endpoint for Partial Book Updates

chi le requested to merge feat/patch-book-endpoint-1764583594 into main

Created by: chi-jitera

Overview

This pull request implements the PATCH /books/:id endpoint to allow partial updates to book resources. The service and controller logic are already in place, and this update focuses on registering the new route in the application.

Changes

  • Updated routes/bookRoutes.js:

    • Added the PATCH route for /books/:id that calls bookController.patchBook to handle partial updates for book resources.
    const express = require('express');
    const bookController = require('../controllers/bookController');
    const router = express.Router();
    
    router.post('/books', bookController.createBook);
    router.get('/books', bookController.getAllBooks);
    router.get('/books/search', bookController.searchBooks);
    router.get('/books/:id', bookController.getBookById);
    router.put('/books/:id', bookController.updateBook); // PATCH endpoint for partial update
    router.patch('/books/:id', bookController.patchBook); // New PATCH route added
    router.delete('/books/:id', bookController.deleteBook);
    
    module.exports = router;

Summary of Implementation

  • The new PATCH endpoint allows clients to update only the fields they provide, adhering to the existing validation and error handling defined in the technical documentation.
  • No changes were necessary for the controller or service, as they already conform to the required logic and guidelines.
  • This implementation maintains the coding style and structure of the project, ensuring consistency across the codebase.

Merge request reports