quiz resetc
This commit is contained in:
@@ -341,6 +341,20 @@ func (r *QuizRepo) QuestionStats(ctx context.Context, quizID string) ([]model.Qu
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ResetAttempt deletes one person's attempt — its answers go with it — so the
|
||||
// quiz is pending for them again and they can take it afresh.
|
||||
func (r *QuizRepo) ResetAttempt(ctx context.Context, quizID, userID string) error {
|
||||
tag, err := r.pg.Pool.Exec(ctx,
|
||||
`DELETE FROM quiz_attempts WHERE quiz_id = $1 AND user_id = $2`, quizID, userID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reset attempt: %w", err)
|
||||
}
|
||||
if tag.RowsAffected() == 0 {
|
||||
return ErrQuizNotStarted
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ── Taking a quiz ─────────────────────────────────────────────────────────
|
||||
|
||||
// PublishedForPath returns the newest live quiz on a content page, or nil.
|
||||
|
||||
Reference in New Issue
Block a user