from __future__ import annotations from fastapi import APIRouter, Depends, HTTPException from ..auth import verify_ingest_token from ..config import ( ACCOUNTS_PATH, ADMIN_TASKS_PATH, CLASSNOTES_PATH, COURSE_SUMMARIES_ROOT, COURSE_SUMMARY_STATE_PATH, OPERATION_LOGS_PATH, write_lock, ) from ..data import ingest_course_summaries from ..schemas import CourseSummaryIngestPayload router = APIRouter() @router.post("/api/ingest/course-summaries") def ingest_course_summary_batch(payload: CourseSummaryIngestPayload, _user: str = Depends(verify_ingest_token)): try: with write_lock: result = ingest_course_summaries( classnotes_path=CLASSNOTES_PATH, accounts_path=ACCOUNTS_PATH, tasks_path=ADMIN_TASKS_PATH, summaries_root=COURSE_SUMMARIES_ROOT, state_path=COURSE_SUMMARY_STATE_PATH, operation_logs_path=OPERATION_LOGS_PATH, batch_id=payload.batch_id, window=payload.window, students=payload.students, summaries=[item.dict() for item in payload.summaries], ) except ValueError as exc: raise HTTPException(status_code=400, detail=str(exc)) from exc return {"ok": True, **result}