From 513cc811dcbb0128ef008039bc82701c984d6562 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 18 Mar 2025 18:00:45 +0000 Subject: [PATCH] feat: Update endpoint loading --- endpoints/loading.get.py | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/endpoints/loading.get.py b/endpoints/loading.get.py index e69de29..f278fd2 100644 --- a/endpoints/loading.get.py +++ b/endpoints/loading.get.py @@ -0,0 +1,57 @@ +from fastapi import APIRouter, Depends, HTTPException +from core.database import fake_users_db +from typing import List, Optional + +router = APIRouter() + +# Demo items database +fake_items_db = [ + {"id": "1", "name": "Item 1", "description": "First item"}, + {"id": "2", "name": "Item 2", "description": "Second item"}, + {"id": "3", "name": "Item 3", "description": "Third item"} +] + +@router.post("/items") +async def get_items( + ids: Optional[List[str]] = None, + skip: int = 0, + limit: int = 10 +): + """Get items from array with optional filtering""" + if ids: + items = [item for item in fake_items_db if item["id"] in ids] + if not items: + raise HTTPException(status_code=404, detail="No items found with provided IDs") + else: + items = fake_items_db[skip:skip + limit] + + return { + "message": "Items retrieved successfully", + "data": { + "items": items, + "total": len(items) + }, + "metadata": { + "skip": skip, + "limit": limit, + "filtered": bool(ids) + } + } + +@router.post("/items/{item_id}") +async def get_item_by_id( + item_id: str +): + """Get single item by ID""" + item = next((item for item in fake_items_db if item["id"] == item_id), None) + if not item: + raise HTTPException(status_code=404, detail="Item not found") + + return { + "message": "Item retrieved successfully", + "data": item, + "metadata": { + "source": "demo_items_db", + "result_count": 1 + } + } \ No newline at end of file