diff --git a/backend/main.py b/backend/main.py index 38aa512..9dfbb3a 100644 --- a/backend/main.py +++ b/backend/main.py @@ -563,6 +563,50 @@ async def assign_shift( assignments[employee] = shift return RedirectResponse(url="/") + +# ============ List Records (from Excel) ============ +@app.get("/api/{section}") +async def list_records( + section: str, + page: int = Query(1, ge=1), + page_size: int = Query(50, ge=1, le=1000), + current_user: User = Depends(get_current_user) +): + """List records from stored Excel file""" + if section not in ["attendance", "accident"]: + raise HTTPException(status_code=400, detail="Invalid section") + + headers, rows = read_excel_file(section) + if headers is None: + return {"total": 0, "page": page, "page_size": page_size, "data": []} + + start = (page - 1) * page_size + end = start + page_size + page_rows = rows[start:end] + + data = [] + for idx, row in enumerate(page_rows, start=start + 1): + record = {"_row": idx} + for i, header in enumerate(headers): + if header: + record[str(header)] = row[i] if i < len(row) else None + data.append(record) + + return {"total": len(rows), "page": page, "page_size": page_size, "data": data} + +@app.get("/api/{section}/info") +async def get_section_info(section: str): + """Get info about stored Excel file""" + if section not in ["attendance", "accident"]: + raise HTTPException(status_code=400, detail="Invalid section") + + headers, rows = read_excel_file(section) + if headers is None: + return {"uploaded": False, "rows": 0, "columns": 0, "headers": []} + + return {"uploaded": True, "rows": len(rows), "columns": len(headers), "headers": headers} + +# ============ Dashboard Summary (combined) ============ @app.get("/api/dashboard/summary") async def dashboard_summary(current_user: User = Depends(get_current_user)): """Combined dashboard data for frontend Dashboard page."""