extend /getdata endpoint with list view

This commit is contained in:
Oli
2024-05-21 12:08:18 +00:00
parent 1dc204e4ba
commit bc909c0799

23
main.py
View File

@@ -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/") @app.post("/uploadfile/")
async def create_upload_files(file: UploadFile = File(...)): async def create_upload_files(file: UploadFile = File(...)):
content = await file.read() content = await file.read()