luisa-7bdn76/endpoints/books.get.py
2025-03-16 08:16:32 -05:00

28 lines
686 B
Python

from fastapi import APIRouter, Depends, HTTPException
from core.database import fake_users_db
import uuid
router = APIRouter()
@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": "Book updated successfully",
"data": book
}