Update code in endpoints\library.get.py
This commit is contained in:
parent
5346f3e1a8
commit
ef6bae8843
27
endpoints/library.get.py
Normal file
27
endpoints/library.get.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
from core.database import fake_users_db
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.get("/library")
|
||||||
|
async def get_book_handler(
|
||||||
|
book_id: str,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
token: str = Depends(oauth2_scheme)
|
||||||
|
):
|
||||||
|
"""Get a book from the library"""
|
||||||
|
user = get_current_user_dummy(token)
|
||||||
|
book = db.query(Book).filter(Book.id == book_id).first()
|
||||||
|
|
||||||
|
if not book:
|
||||||
|
raise HTTPException(status_code=404, detail="Book not found")
|
||||||
|
|
||||||
|
return {
|
||||||
|
"message": "Book retrieved successfully",
|
||||||
|
"data": book,
|
||||||
|
"metadata": {
|
||||||
|
"user": user.username,
|
||||||
|
"source": "library_db"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user