[JITERA] Add PATCH route for updating books
Created by: chi-jitera
Overview
This pull request introduces a new PATCH route for updating book records in the application. The existing functionality for partial updates is already implemented at the service and controller levels, but the corresponding route was missing in the bookRoutes.js file.
Changes
-
Added PATCH /books/:id route:
- This route allows for partial updates of book records using the existing
updateBookcontroller logic. - The route is defined in
routes/bookRoutes.jsand conforms to REST conventions for updating resources.
- This route allows for partial updates of book records using the existing
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.updateBook); // New PATCH route added
router.delete('/books/:id', bookController.deleteBook);
module.exports = router;
This addition allows clients to send PATCH requests to update only specific fields of a book, enhancing the flexibility and efficiency of the API.