Add /api/attendance/records and /api/accident/records endpoints for frontend

This commit is contained in:
IT狗
2026-07-21 00:15:29 +08:00
parent 766817b9be
commit 02b4a49e8c
+54
View File
@@ -606,6 +606,60 @@ async def get_section_info(section: str):
return {"uploaded": True, "rows": len(rows), "columns": len(headers), "headers": headers} return {"uploaded": True, "rows": len(rows), "columns": len(headers), "headers": headers}
# ============ Attendance Records (for frontend) ============
@app.get("/api/attendance/records")
async def attendance_records(
page: int = Query(1, ge=1),
per_page: int = Query(50, ge=1, le=1000),
sort_by: Optional[str] = None,
sort_order: Optional[str] = None,
current_user: User = Depends(get_current_user)
):
"""List attendance records for frontend - mirrors /api/attendance with different param names."""
headers, rows = read_excel_file("attendance")
if headers is None:
return {"total": 0, "page": page, "per_page": per_page, "data": []}
start = (page - 1) * per_page
end = start + per_page
page_rows = rows[start:end]
data = []
for idx, row in enumerate(page_rows, start=start + 1):
record = {"_row": idx}
for i, h in enumerate(headers):
if h:
record[str(h)] = row[i] if i < len(row) else None
data.append(record)
return {"total": len(rows), "page": page, "per_page": per_page, "data": data}
# ============ Accident Records (for frontend) ============
@app.get("/api/accident/records")
async def accident_records(
page: int = Query(1, ge=1),
per_page: int = Query(50, ge=1, le=1000),
current_user: User = Depends(get_current_user)
):
"""List accident records for frontend."""
headers, rows = read_excel_file("accident")
if headers is None:
return {"total": 0, "page": page, "per_page": per_page, "data": []}
start = (page - 1) * per_page
end = start + per_page
page_rows = rows[start:end]
data = []
for idx, row in enumerate(page_rows, start=start + 1):
record = {"_row": idx}
for i, h in enumerate(headers):
if h:
record[str(h)] = row[i] if i < len(row) else None
data.append(record)
return {"total": len(rows), "page": page, "per_page": per_page, "data": data}
# ============ Dashboard Summary (combined) ============ # ============ Dashboard Summary (combined) ============
@app.get("/api/dashboard/summary") @app.get("/api/dashboard/summary")
async def dashboard_summary(current_user: User = Depends(get_current_user)): async def dashboard_summary(current_user: User = Depends(get_current_user)):