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 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
}