fix(fastapi): remove duplicate confirm/reject routes
- api_confirm and api_reject were defined twice on same paths - FastAPI only registers first definition, causing silent 404s - Kept api_confirm_engram and api_reject_engram (use _update_correctness) - Removed duplicate direct DB implementations - Fixes dashboard confirm/reject buttons not working
This commit is contained in:
@@ -690,72 +690,6 @@ def api_refresh_engram(engram_id: str):
|
|||||||
return JSONResponse({"error": str(e)}, status_code=404)
|
return JSONResponse({"error": str(e)}, status_code=404)
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/engrams/{engram_id}/confirm")
|
|
||||||
def api_confirm(engram_id: str, reason: str = Form("")):
|
|
||||||
conn = get_db()
|
|
||||||
c = conn.cursor()
|
|
||||||
row = c.execute(
|
|
||||||
"SELECT correctness_json FROM engrams WHERE id = ?", (engram_id,)
|
|
||||||
).fetchone()
|
|
||||||
if not row:
|
|
||||||
conn.close()
|
|
||||||
return JSONResponse({"error": "Not found"}, status_code=404)
|
|
||||||
|
|
||||||
correctness = json.loads(row["correctness_json"] or "{}")
|
|
||||||
correctness["confirmed"] = True
|
|
||||||
correctness["confirmations"] = correctness.get("confirmations", 0) + 1
|
|
||||||
correctness["last_reviewed"] = datetime.now(timezone.utc).isoformat()
|
|
||||||
review_history = correctness.get("review_history", [])
|
|
||||||
review_history.append({
|
|
||||||
"by": "web",
|
|
||||||
"action": "confirm",
|
|
||||||
"at": datetime.now(timezone.utc).isoformat(),
|
|
||||||
"note": reason or "confirmed via dashboard",
|
|
||||||
})
|
|
||||||
correctness["review_history"] = review_history
|
|
||||||
|
|
||||||
c.execute(
|
|
||||||
"UPDATE engrams SET correctness_json = ?, modified_at = ? WHERE id = ?",
|
|
||||||
(json.dumps(correctness), datetime.now(timezone.utc).isoformat(), engram_id),
|
|
||||||
)
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
return {"success": True, "engram_id": engram_id}
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/engrams/{engram_id}/reject")
|
|
||||||
def api_reject(engram_id: str, reason: str = Form("")):
|
|
||||||
conn = get_db()
|
|
||||||
c = conn.cursor()
|
|
||||||
row = c.execute(
|
|
||||||
"SELECT correctness_json FROM engrams WHERE id = ?", (engram_id,)
|
|
||||||
).fetchone()
|
|
||||||
if not row:
|
|
||||||
conn.close()
|
|
||||||
return JSONResponse({"error": "Not found"}, status_code=404)
|
|
||||||
|
|
||||||
correctness = json.loads(row["correctness_json"] or "{}")
|
|
||||||
correctness["confirmed"] = False
|
|
||||||
correctness["rejections"] = correctness.get("rejections", 0) + 1
|
|
||||||
correctness["last_reviewed"] = datetime.now(timezone.utc).isoformat()
|
|
||||||
review_history = correctness.get("review_history", [])
|
|
||||||
review_history.append({
|
|
||||||
"by": "web",
|
|
||||||
"action": "reject",
|
|
||||||
"at": datetime.now(timezone.utc).isoformat(),
|
|
||||||
"note": reason or "rejected via dashboard",
|
|
||||||
})
|
|
||||||
correctness["review_history"] = review_history
|
|
||||||
|
|
||||||
c.execute(
|
|
||||||
"UPDATE engrams SET correctness_json = ?, modified_at = ? WHERE id = ?",
|
|
||||||
(json.dumps(correctness), datetime.now(timezone.utc).isoformat(), engram_id),
|
|
||||||
)
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
return {"success": True, "engram_id": engram_id}
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/engrams/{engram_id}/refresh")
|
@app.post("/api/engrams/{engram_id}/refresh")
|
||||||
def api_refresh(engram_id: str):
|
def api_refresh(engram_id: str):
|
||||||
conn = get_db()
|
conn = get_db()
|
||||||
|
|||||||
Reference in New Issue
Block a user