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

This commit is contained in:
Backend IM Bot 2025-03-18 09:37:34 +00:00
parent 567df984b5
commit 2f76b2e534

View File

@ -0,0 +1,39 @@
from fastapi import APIRouter, Depends, HTTPException
from core.database import fake_users_db
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]
return {
"message": "Books retrieved successfully",
"data": paginated_books,
"metadata": {
"total_count": len(books),
"limit": limit,
"offset": offset,
"returned_count": len(paginated_books)
}
}