Skip to content

[JITERA] Implement Delete Book API Endpoint

chi le requested to merge feat/delete-book-api-1748506271 into main

Created by: chi-jitera

Overview

This pull request implements the API endpoint for deleting a book from the database. The functionality is added to the existing book management system, allowing users to remove a book by its ID.

Changes Made

  1. Controller Update:

    • Added the deleteBook function in bookController.js to handle the deletion logic. This function retrieves the book ID from the request parameters and calls the deleteBook service method. It returns a success message upon successful deletion or an error message if the book is not found.
    exports.deleteBook = async (req, res) => {
        try {
            const message = await bookService.deleteBook(req.params.id);
            res.json(message);
        } catch (error) {
            res.status(404).json({ error: error.message });
        }
    };
  2. Route Definition:

    • Updated bookRoutes.js to include a DELETE route for the /books/:id endpoint. This route maps to the deleteBook function in the controller, allowing clients to send DELETE requests to remove a book.
    router.delete('/books/:id', bookController.deleteBook);

This implementation ensures that users can effectively manage their book collection by removing books that are no longer needed.

Merge request reports