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 <noreply@anthropic.com>
This commit is contained in:
parent
36f334aba7
commit
3d58a2db8e
|
|
@ -644,6 +644,16 @@ def get_stats(x_profile_id: Optional[str]=Header(default=None), session: dict=De
|
||||||
# ── AI Insights ───────────────────────────────────────────────────────────────
|
# ── AI Insights ───────────────────────────────────────────────────────────────
|
||||||
import httpx, json
|
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")
|
@app.get("/api/insights/latest")
|
||||||
def get_latest_insights(x_profile_id: Optional[str]=Header(default=None), session: dict=Depends(require_auth)):
|
def get_latest_insights(x_profile_id: Optional[str]=Header(default=None), session: dict=Depends(require_auth)):
|
||||||
"""Get latest AI insights across all scopes."""
|
"""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
|
if not row: return None
|
||||||
return r2d(row)
|
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}")
|
@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)):
|
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)
|
pid = get_pid(x_profile_id)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user