Update code in endpoints/books.delete.py
This commit is contained in:
parent
dbd5e6e7be
commit
75d4f4d2a9
19
endpoints/books.delete.py
Normal file
19
endpoints/books.delete.py
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user