diff --git a/src/api/v1/upload_jobs.py b/src/api/v1/upload_jobs.py index cda5e8f..b7c1f3a 100644 --- a/src/api/v1/upload_jobs.py +++ b/src/api/v1/upload_jobs.py @@ -38,7 +38,7 @@ async def create(project_id: str, body: CreateUploadJobIn, @router.get("/{job_id}") async def get(project_id: str, job_id: str, db: AsyncSession = Depends(get_session)): - data = await svc.get_job(job_id, db) + data = await svc.get_job_detail(job_id, db) if data["projectId"] != project_id: from fastapi import HTTPException raise HTTPException(404, "upload job not found") diff --git a/src/services/upload_jobs.py b/src/services/upload_jobs.py index c9c0214..b8e6b50 100644 --- a/src/services/upload_jobs.py +++ b/src/services/upload_jobs.py @@ -58,6 +58,17 @@ async def get_job(job_id: str, db: AsyncSession) -> dict: return _job_dict(job) +async def get_job_detail(job_id: str, db: AsyncSession) -> dict: + job = await db.get(UploadJob, job_id) + if job is None: + raise HTTPException(404, "upload job not found") + rows = (await db.execute(select(UploadItem).where( + UploadItem.job_id == job_id).order_by(UploadItem.created_at, UploadItem.id))).scalars().all() + items = [_item_dict(item, r2.presign_put(item.r2_key, item.content_type) + if item.status == "pending" else None) for item in rows] + return {**_job_dict(job), "items": items} + + async def complete_item(job_id: str, item_id: str, width: int, height: int, db: AsyncSession) -> dict: item = await db.get(UploadItem, item_id)