feat: add open questions with a pending grading state
- migration: open question type, rubric, max_length, quiz grader and the grading and review columns of attempt answers - open answers are checked, stored as pending and never scored on answer; a changed text resets the grading state - student JSON gains text, grading_status, grader_feedback, review_comment, max_length, needs_review and open_answers; the rubric is never serialized
This commit is contained in:
@@ -41,6 +41,7 @@ var (
|
||||
{Field: "answer_ids", Rules: lagoon.ParseRules("nullable|array")},
|
||||
{Field: "answer_ids.*", Rules: lagoon.ParseRules("integer|min:1")},
|
||||
{Field: "known", Rules: lagoon.ParseRules("nullable|boolean")},
|
||||
{Field: "text", Rules: lagoon.ParseRules("nullable|string")},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -116,7 +117,8 @@ func (h *Handlers) StartAttempt(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Answer answers POST /attempts/{id}/answers with
|
||||
// {"question_id": 1, "answer_ids": [2], "known": true}.
|
||||
// {"question_id": 1, "answer_ids": [2], "known": true}; an open question
|
||||
// takes {"question_id": 1, "text": "..."}.
|
||||
func (h *Handlers) Answer(w http.ResponseWriter, r *http.Request) {
|
||||
userID, ok := h.user(w, r)
|
||||
if !ok {
|
||||
@@ -147,6 +149,10 @@ func (h *Handlers) Answer(w http.ResponseWriter, r *http.Request) {
|
||||
known := toBool(raw)
|
||||
in.Known = &known
|
||||
}
|
||||
if raw, present := input["text"]; present && raw != nil {
|
||||
text, _ := raw.(string) // the string rule already refused anything else
|
||||
in.Text = &text
|
||||
}
|
||||
fb, err := svc.Answer(r.Context(), userID, attemptID, in)
|
||||
if err != nil {
|
||||
h.writeError(w, r, err)
|
||||
@@ -331,6 +337,8 @@ var apiMessages = map[string]string{
|
||||
"answer_not_in_question": "The chosen answers do not belong to this question.",
|
||||
"single_one_answer": "Choose exactly one answer for this question.",
|
||||
"known_required": "The known field is required for this question.",
|
||||
"text_required": "Write an answer to this question.",
|
||||
"text_too_long": "The answer is longer than this question allows.",
|
||||
"unknown_category": "The quiz has no questions in this category.",
|
||||
"validation_failed": "The given data was invalid.",
|
||||
"attempt_limit_reached": "All attempts at this test have been used.",
|
||||
|
||||
Reference in New Issue
Block a user