From 3d58a2db8e26d48d3aef2bc2e150614c73e8bfff Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 18 Mar 2026 15:26:57 +0100 Subject: [PATCH] fix: add missing /api/insights endpoints - Add GET /api/insights (returns all insights for profile) - Add DELETE /api/insights/{id} (delete by ID, not scope) - Frontend Analysis.jsx needs these endpoints to load/delete insights Fixes 404 error preventing prompts from displaying. Co-Authored-By: Claude Opus 4.6 --- backend/main.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/backend/main.py b/backend/main.py index bc2a169..a097e54 100644 --- a/backend/main.py +++ b/backend/main.py @@ -644,6 +644,16 @@ def get_stats(x_profile_id: Optional[str]=Header(default=None), session: dict=De # ── AI Insights ─────────────────────────────────────────────────────────────── import httpx, json +@app.get("/api/insights") +def get_all_insights(x_profile_id: Optional[str]=Header(default=None), session: dict=Depends(require_auth)): + """Get all AI insights for profile.""" + pid = get_pid(x_profile_id) + with get_db() as conn: + cur = get_cursor(conn) + cur.execute("SELECT * FROM ai_insights WHERE profile_id=%s ORDER BY created DESC", (pid,)) + rows = cur.fetchall() + return [r2d(r) for r in rows] + @app.get("/api/insights/latest") def get_latest_insights(x_profile_id: Optional[str]=Header(default=None), session: dict=Depends(require_auth)): """Get latest AI insights across all scopes.""" @@ -664,6 +674,15 @@ def get_ai_insight(scope: str, x_profile_id: Optional[str]=Header(default=None), if not row: return None return r2d(row) +@app.delete("/api/insights/{insight_id}") +def delete_insight_by_id(insight_id: str, x_profile_id: Optional[str]=Header(default=None), session: dict=Depends(require_auth)): + """Delete a specific insight by ID.""" + pid = get_pid(x_profile_id) + with get_db() as conn: + cur = get_cursor(conn) + cur.execute("DELETE FROM ai_insights WHERE id=%s AND profile_id=%s", (insight_id, pid)) + return {"ok":True} + @app.delete("/api/ai/insights/{scope}") def delete_ai_insight(scope: str, x_profile_id: Optional[str]=Header(default=None), session: dict=Depends(require_auth)): pid = get_pid(x_profile_id)