[JITERA] Implement Delete Book API Endpoint
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
-
Controller Update:
- Added the
deleteBookfunction inbookController.jsto handle the deletion logic. This function retrieves the book ID from the request parameters and calls thedeleteBookservice 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 }); } }; - Added the
-
Route Definition:
- Updated
bookRoutes.jsto include a DELETE route for the/books/:idendpoint. This route maps to thedeleteBookfunction in the controller, allowing clients to send DELETE requests to remove a book.
router.delete('/books/:id', bookController.deleteBook); - Updated
This implementation ensures that users can effectively manage their book collection by removing books that are no longer needed.