Update code in endpoints/api/v1/endpoint.get.py

This commit is contained in:
Backend IM Bot 2025-03-18 09:38:59 +00:00
parent 9e9663a7cd
commit 004a5dfb10

View File

@ -1,39 +1,35 @@
from fastapi import APIRouter, Depends, HTTPException
from core.database import fake_users_db
from typing import Dict
router = APIRouter()
@router.get("/books")
async def get_books(
limit: int = 10,
offset: int = 0
):
"""Get list of books"""
# Demo books data
books = [
{
"id": "1",
"title": "Sample Book 1",
"author": "Author 1",
"year": 2023
},
{
"id": "2",
"title": "Sample Book 2",
"author": "Author 2",
"year": 2022
}
]
paginated_books = books[offset:offset + limit]
fake_books_db: Dict = {
"1": {
"id": "1",
"title": "Sample Book",
"author": "John Doe",
"year": 2023,
"available": True
}
}
@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 {
"message": "Books retrieved successfully",
"data": paginated_books,
"message": "Book found",
"data": book,
"metadata": {
"total_count": len(books),
"limit": limit,
"offset": offset,
"returned_count": len(paginated_books)
"source": "demo_db",
"result_count": 1,
"features": {
"details_available": True,
"can_download": False
}
}
}