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 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
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user