From 75d4f4d2a9cd0651a98eb479fe950c3ed20b5e16 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Thu, 27 Mar 2025 20:30:27 +0100 Subject: [PATCH] Update code in endpoints/books.delete.py --- endpoints/books.delete.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 endpoints/books.delete.py diff --git a/endpoints/books.delete.py b/endpoints/books.delete.py new file mode 100644 index 0000000..5c3b10e --- /dev/null +++ b/endpoints/books.delete.py @@ -0,0 +1,19 @@ +# Entity: Book + +from fastapi import APIRouter, Depends, HTTPException, status +from sqlalchemy.orm import Session +from core.database import get_db +from models.book import Book +from schemas.book import BookSchema +from helpers.book_helpers import delete_book_by_id + +router = APIRouter() + +@router.delete("/books/{book_id}", status_code=status.HTTP_204_NO_CONTENT) +async def delete_book( + book_id: int, + db: Session = Depends(get_db) +): + if not delete_book_by_id(db, book_id): + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Book not found") + return \ No newline at end of file