Submit an answer for one question in a practice session
POST/sessions/:session_id/answers
Records the user's answer to a single question. The backend
determines correctness server-side -- the client does NOT
send is_correct. Per-type validation:
multiple-choice-- exact string match betweenuser_answerand the text of the option whoseis_correctflag is true.verified: true.true-false--user_answerMUST be the lowercase string"true"or"false". The backend parses it and compares against the canonical answer derived from the "True" option'sis_correctflag.verified: true.freeform-- case-insensitive trimmed string compare againstquiz_questions.reference_answer. The response carriesverified: falsebecause string-match is not semantic validation.
On a correct answer, the parent session's
correct_answers counter is incremented by 1 in the
same transaction as the insert.
Authorization: the session must belong to the authenticated user (403 otherwise). Sessions that have already been completed reject submissions with 409 (the SELECT FOR UPDATE on the session row serializes against a concurrent complete-session call).
Duplicate submission protection: the
uq_practice_answers_session_question unique constraint
catches the case where a question is answered twice in
the same session. The service surfaces the unique
violation as a typed 400 with details
{"question_id": "already answered"}.
No auto-completion: even when this answer is the last
unanswered question in the snapshot, the session stays
in-progress until the client explicitly calls
POST /api/sessions/{session_id}/complete (ASK-140,
future).
Request
Responses
- 201
- 400
- 401
- 403
- 404
- 409
- 500
Answer recorded with backend-determined correctness.
Bad request
Unauthorized
Forbidden
Not found
Conflict with current resource state
Internal server error