26 lines
685 B
Python
26 lines
685 B
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
from uuid import UUID
|
|
|
|
from core.database import get_db
|
|
from helpers.book_helpers import delete_book
|
|
|
|
router = APIRouter()
|
|
|
|
@router.delete("/books", status_code=status.HTTP_200_OK)
|
|
async def delete_book_endpoint(
|
|
book_id: UUID,
|
|
db: Session = Depends(get_db)
|
|
):
|
|
"""
|
|
Delete a book from the database by its ID
|
|
"""
|
|
success = delete_book(db=db, book_id=book_id)
|
|
|
|
if not success:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="Book not found"
|
|
)
|
|
|
|
return {"message": "Book successfully deleted"} |