Update code in endpoints/books.get.py
This commit is contained in:
parent
91d7edf02d
commit
3c3ff065bb
@ -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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user