fers web
This commit is contained in:
@@ -95,3 +95,15 @@ def get_response(response_id: str):
|
||||
if not r:
|
||||
raise HTTPException(status_code=404, detail="Response not found")
|
||||
return {"id": str(r.id), "poll_id": str(r.poll_id), "user_id": str(r.user_id) if r.user_id else None, "submitted_at": r.submitted_at.isoformat(), "answers": [{"id": str(a.id), "question_id": str(a.question_id), "choice_id": str(a.choice_id) if a.choice_id else None, "text": a.text} for a in r.answers]}
|
||||
|
||||
|
||||
@router.get("/users/{user_id}/responses")
|
||||
def list_responses_by_user(user_id: str):
|
||||
Session = get_session()
|
||||
try:
|
||||
uid = uuid.UUID(user_id)
|
||||
except Exception:
|
||||
raise HTTPException(status_code=400, detail="Invalid user UUID")
|
||||
with Session() as session:
|
||||
rows = session.query(Response).filter(Response.user_id == uid).all()
|
||||
return [{"id": str(r.id), "poll_id": str(r.poll_id), "submitted_at": r.submitted_at.isoformat()} for r in rows]
|
||||
|
||||
Reference in New Issue
Block a user