diff --git a/endpoints/books.get.py b/endpoints/books.get.py index 89a6d09..2982935 100644 --- a/endpoints/books.get.py +++ b/endpoints/books.get.py @@ -1,13 +1,28 @@ from fastapi import APIRouter, Depends, HTTPException from core.database import fake_users_db +import uuid router = APIRouter() -@router.get("/books") -async def books_handler(): - """Get all books""" - books = list(fake_users_db.values()) +@router.put("/books/{book_id}") +async def update_book( + book_id: str, + title: str = None, + author: str = None, + db: Session = Depends(get_db), + token: str = Depends(oauth2_scheme) +): + """Update a book by ID""" + if book_id not in fake_users_db: + raise HTTPException(status_code=404, detail="Book not found") + + book = fake_users_db[book_id] + if title: + book["title"] = title + if author: + book["author"] = author + return { - "message": "Books retrieved successfully", - "data": books + "message": "Book updated successfully", + "data": book } \ No newline at end of file