Update code in endpoints/books.get.py

This commit is contained in:
Backend IM Bot 2025-03-16 08:16:32 -05:00
parent 91d7edf02d
commit 3c3ff065bb

View File

@ -1,13 +1,28 @@
from fastapi import APIRouter, Depends, HTTPException from fastapi import APIRouter, Depends, HTTPException
from core.database import fake_users_db from core.database import fake_users_db
import uuid
router = APIRouter() router = APIRouter()
@router.get("/books") @router.put("/books/{book_id}")
async def books_handler(): async def update_book(
"""Get all books""" book_id: str,
books = list(fake_users_db.values()) 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 { return {
"message": "Books retrieved successfully", "message": "Book updated successfully",
"data": books "data": book
} }