Add delete job functionality with confirmation step

Adds DELETE /api/jobs/{id} endpoint (removes DB record and image file),
and a two-step Delete / Confirm button on the review page that returns
to the job list on success.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Aaron Roberts
2026-06-09 18:33:46 +01:00
parent dc5a1a4ff5
commit 02e3099388
2 changed files with 87 additions and 2 deletions

View File

@@ -877,6 +877,39 @@ async def review_job(job_id: str, body: ReviewRequest):
return JSONResponse(_job_row_to_dict(row))
@app.delete("/api/jobs/{job_id}")
async def delete_job(job_id: str):
"""Delete a job record and its stored image."""
try:
uuid.UUID(job_id)
except ValueError:
raise HTTPException(status_code=400, detail="Invalid job ID.")
try:
with get_db() as conn:
with conn.cursor() as cur:
cur.execute(
"DELETE FROM ocr_jobs WHERE id = %s RETURNING image_path",
(job_id,),
)
row = cur.fetchone()
except Exception as exc:
print(f"delete_job DB error: {exc}")
raise HTTPException(status_code=500, detail="Database error.")
if not row:
raise HTTPException(status_code=404, detail="Job not found.")
# Best-effort removal of the stored image file
try:
if row["image_path"] and os.path.isfile(row["image_path"]):
os.remove(row["image_path"])
except Exception:
pass
return JSONResponse({"deleted": job_id})
if __name__ == "__main__":
host = env_config("API_HOST", default="0.0.0.0")
port = env_config("API_PORT", default=8000, cast=int)