From bc909c0799c116697e56170aabe6669e792ef139 Mon Sep 17 00:00:00 2001 From: Oli Date: Tue, 21 May 2024 12:08:18 +0000 Subject: [PATCH] extend /getdata endpoint with list view --- main.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/main.py b/main.py index 718c251..5e1d599 100644 --- a/main.py +++ b/main.py @@ -32,6 +32,29 @@ async def read_item(date: str, index: str = "DAX", show_all_indices: Optional[bo +@app.get("/getdata") +async def get_indices_paginated(page: int = 1, page_size: int = 30): + all_dates = list(fake_items_db.keys()) + total_pages = (len(all_dates) + page_size - 1) // page_size + + start_index = (page - 1) * page_size + end_index = start_index + page_size + + current_page_dates = all_dates[start_index:end_index] + + indices_data = [] + for date in current_page_dates: + indices_data.append(fake_items_db[date]) + + return { + "page": page, + "total_pages": total_pages, + "page_size": page_size, + "data": indices_data + } + + + @app.post("/uploadfile/") async def create_upload_files(file: UploadFile = File(...)): content = await file.read()