Skip to content

[JITERA] Add PATCH /books/:id route to enable partial updates

chi le requested to merge feat/add-patch-route-1762859488 into main

Created by: chi-jitera

Overview

This pull request introduces a new PATCH route for updating book records partially by their ID. The logic for handling the PATCH request is already implemented in the service and controller, and this update integrates the route into the application.

Changes

  • Updated /routes/bookRoutes.js:
    • Added the PATCH route for /books/:id which maps to the bookController.patchBook method. This allows clients to perform partial updates on book records.

Code Changes

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);
router.patch('/books/:id', bookController.patchBook); // <-- Added PATCH
router.delete('/books/:id', bookController.deleteBook); 

module.exports = router;

This addition enables clients to send PATCH requests to update specific fields of a book without needing to send the entire book object.

Merge request reports