Update code in endpoints/api/v1/endpoint.get.py
This commit is contained in:
parent
9e9663a7cd
commit
004a5dfb10
@ -1,39 +1,35 @@
|
|||||||
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
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.get("/books")
|
fake_books_db: Dict = {
|
||||||
async def get_books(
|
"1": {
|
||||||
limit: int = 10,
|
|
||||||
offset: int = 0
|
|
||||||
):
|
|
||||||
"""Get list of books"""
|
|
||||||
# Demo books data
|
|
||||||
books = [
|
|
||||||
{
|
|
||||||
"id": "1",
|
"id": "1",
|
||||||
"title": "Sample Book 1",
|
"title": "Sample Book",
|
||||||
"author": "Author 1",
|
"author": "John Doe",
|
||||||
"year": 2023
|
"year": 2023,
|
||||||
},
|
"available": True
|
||||||
{
|
}
|
||||||
"id": "2",
|
|
||||||
"title": "Sample Book 2",
|
|
||||||
"author": "Author 2",
|
|
||||||
"year": 2022
|
|
||||||
}
|
}
|
||||||
]
|
|
||||||
|
|
||||||
paginated_books = books[offset:offset + limit]
|
@router.get("/books/{book_id}")
|
||||||
|
async def get_book(book_id: str):
|
||||||
|
"""Get book by ID"""
|
||||||
|
book = fake_books_db.get(book_id)
|
||||||
|
if not book:
|
||||||
|
raise HTTPException(status_code=404, detail="Book not found")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"message": "Books retrieved successfully",
|
"message": "Book found",
|
||||||
"data": paginated_books,
|
"data": book,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"total_count": len(books),
|
"source": "demo_db",
|
||||||
"limit": limit,
|
"result_count": 1,
|
||||||
"offset": offset,
|
"features": {
|
||||||
"returned_count": len(paginated_books)
|
"details_available": True,
|
||||||
|
"can_download": False
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user