fix: Add missing GET /api/prompts/{id} endpoint
Critical Backend Bug:
- Frontend calls api.getPrompt(id) → GET /api/prompts/{uuid}
- Backend had NO endpoint for single prompt retrieval by ID
- Result: 405 Method Not Allowed
Backend Endpoints Before:
✓ GET /api/prompts - List all
✓ POST /api/prompts - Create
✓ PUT /api/prompts/{id} - Update
✗ GET /api/prompts/{id} - MISSING!
Backend Endpoints After:
✓ GET /api/prompts - List all
✓ GET /api/prompts/{id} - Get single (NEW)
✓ POST /api/prompts - Create
✓ PUT /api/prompts/{id} - Update
Implementation:
- Added get_prompt(prompt_id: str) function
- Returns single prompt by UUID
- 404 if not found
- Requires auth (admin or user)
This fixes:
- Workflow loading after save (loadWorkflow calls getPrompt)
- Workflow editing from admin list (Edit button calls getPrompt)
- All 405 Method Not Allowed errors
Root Cause: Backend was incomplete, missing basic CRUD read-by-id endpoint
This commit is contained in:
parent
84c1fa3c1d
commit
d9bcaaaac6
|
|
@ -53,6 +53,20 @@ def list_prompts(session: dict=Depends(require_auth)):
|
||||||
return [r2d(r) for r in cur.fetchall()]
|
return [r2d(r) for r in cur.fetchall()]
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/{prompt_id}")
|
||||||
|
def get_prompt(prompt_id: str, session: dict=Depends(require_auth)):
|
||||||
|
"""Get single AI prompt by ID (UUID)."""
|
||||||
|
with get_db() as conn:
|
||||||
|
cur = get_cursor(conn)
|
||||||
|
cur.execute("SELECT * FROM ai_prompts WHERE id=%s", (prompt_id,))
|
||||||
|
row = cur.fetchone()
|
||||||
|
|
||||||
|
if not row:
|
||||||
|
raise HTTPException(status_code=404, detail="Prompt not found")
|
||||||
|
|
||||||
|
return r2d(row)
|
||||||
|
|
||||||
|
|
||||||
@router.post("")
|
@router.post("")
|
||||||
def create_prompt(p: PromptCreate, session: dict=Depends(require_admin)):
|
def create_prompt(p: PromptCreate, session: dict=Depends(require_admin)):
|
||||||
"""Create new AI prompt (admin only)."""
|
"""Create new AI prompt (admin only)."""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user