Skip to content

feat: validate quiz CSV uploads#242

Merged
smitdodiya merged 1 commit into
mainfrom
feat/csv-validation
Jun 15, 2026
Merged

feat: validate quiz CSV uploads#242
smitdodiya merged 1 commit into
mainfrom
feat/csv-validation

Conversation

@smitdodiya

Copy link
Copy Markdown
Member

Problem:
Uploading a CSV with invalid data (e.g. an unrecognized question type) was silently accepted, showed a "Questions imported successfully" toast, and stored garbage. The bad data then crashed the quiz view with [GET] /api/v1/quizzes/{id}/questions: 500 Internal Server Error, because an invalid question type was silently coerced to 0, which no downstream lookup could resolve.

validation added:

  • Question Type : Must be single answer or survey (now uses the shared CheckQuestionType helper instead of a silent map lookup). This is the fix for the 500.
  • Question Text : Required (non-empty after trim).
  • Options : At least 2 non-empty options required.
  • Correct Answer : Required; each value must be numeric (now strconv.Atoi, no silent Sscanf); each must reference an option that actually exists (catches "answer = 7 but only 4 options").
  • Correct Answer count : single answer → exactly one correct answer; survey → at least one.
  • Points : Optional; if present must be a positive integer (rejects abc, 0, -5). Defaults to 1 when blank.
  • Question Media / Options Media : Must be text, image, or code. Empty defaults to text (matching manual question creation). Values are trimmed + lowercased, so Image/CODE are accepted and stored normalized so the frontend renders them correctly.

@smitdodiya smitdodiya merged commit 08e015d into main Jun 15, 2026
2 checks passed
@smitdodiya smitdodiya deleted the feat/csv-validation branch June 15, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant