From 004a5dfb1057a89dfd99a5759ddb786a65610a0a Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 18 Mar 2025 09:38:59 +0000 Subject: [PATCH] Update code in endpoints/api/v1/endpoint.get.py --- endpoints/api/v1/endpoint.get.py | 54 +++++++++++++++----------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/endpoints/api/v1/endpoint.get.py b/endpoints/api/v1/endpoint.get.py index 1dc2909..07ded6a 100644 --- a/endpoints/api/v1/endpoint.get.py +++ b/endpoints/api/v1/endpoint.get.py @@ -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 + } } } \ No newline at end of file