39 lines
898 B
Python
39 lines
898 B
Python
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)
|
|
}
|
|
} |