Skip to content

[JITERA] Add PATCH /books/:id route to bookRoutes

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

Created by: chi-jitera

Overview

This pull request introduces a new PATCH route for updating book records partially in the /routes/bookRoutes.js file. The new route is mapped to the existing patchBook controller function, which handles the logic for partial updates and validation.

Changes

  • Added PATCH /books/:id route:
    • This route allows clients to send partial updates to a book's information. It is mapped to the bookController.patchBook function, ensuring that the existing RESTful structure is maintained.

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); // New PATCH route added
router.delete('/books/:id', bookController.deleteBook); 

module.exports = router;

This addition aligns with the existing API structure and leverages the already implemented service logic for handling partial updates and validation.

Merge request reports