Add autocomplete suggestions for Author, Chapter, and Reviewer fields

Adds a GET /api/jobs/suggestions endpoint that returns distinct values for
author, chapter, and reviewer_name from the database, and wires them into
HTML datalist elements on the New Job, result view, and Browse Jobs pages.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Aaron Roberts
2026-06-09 18:24:49 +01:00
parent 1d15b5f0c1
commit 5ea18d76d6
5 changed files with 88 additions and 12 deletions

View File

@@ -754,6 +754,31 @@ async def list_jobs(
return JSONResponse({"total": total, "limit": limit, "offset": offset, "jobs": rows})
@app.get("/api/jobs/suggestions")
async def job_suggestions():
"""Return distinct values for author, chapter, and reviewer_name to power autocomplete."""
try:
with get_db() as conn:
with conn.cursor() as cur:
cur.execute("""
SELECT
array_remove(array_agg(DISTINCT author ORDER BY author), NULL) AS authors,
array_remove(array_agg(DISTINCT chapter ORDER BY chapter), NULL) AS chapters,
array_remove(array_agg(DISTINCT reviewer_name ORDER BY reviewer_name), NULL) AS reviewers
FROM ocr_jobs
""")
row = cur.fetchone()
except Exception as exc:
print(f"suggestions DB error: {exc}")
raise HTTPException(status_code=500, detail="Database error.")
return JSONResponse({
"authors": row["authors"] or [],
"chapters": row["chapters"] or [],
"reviewers": row["reviewers"] or [],
})
@app.get("/api/jobs/{job_id}")
async def get_job(job_id: str):
"""Retrieve full job record including OCR text."""