Skip to content

Commit

Permalink
fix: crash on judge when no user answer found
Browse files Browse the repository at this point in the history
  • Loading branch information
zrll12 committed Dec 9, 2024
1 parent beaa123 commit d090afc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/service/score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,22 @@ impl score::Model {
};
let all = correct_answer.all_points.unwrap_or(0);
let sub = correct_answer.sub_points.unwrap_or(0);
let Some(user_answer) = answer.get(question.id.to_string()) else {
scores.insert(question.id, 0);
all_score += all;
continue;
};
let user_answer = user_answer.as_str().unwrap();

let score = match question.r#type {
QuestionType::Text | QuestionType::SingleChoice => {
let user_answer = answer.get(question.id.to_string()).unwrap().as_str().unwrap();
if user_answer == correct_answer.answer {
all
} else {
0
}
}
QuestionType::MultipleChoice => {
let user_answer = answer.get(question.id.to_string()).unwrap()
.as_str().unwrap();
let user_answer: Vec<String> = serde_json::from_str(user_answer).unwrap();
let correct_answer: Vec<String> = serde_json::from_str(&correct_answer.answer).unwrap();

Expand Down

0 comments on commit d090afc

Please sign in to comment.