Skip to content

Commit

Permalink
Merge branch 'hoxfix/#205-bug-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
violet-mj committed Aug 25, 2024
2 parents 1559688 + 93e86b4 commit 434699c
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,30 @@ public EventUser preview(PreviewRequest previewRequest, Model model) {
throw new DrawingEventNotParticipantException();
}

double scoreGame1 = Double.parseDouble((String) eventUser.getScores().get("1_game_score"));
double scoreGame1 = getGameScore(eventUser.getScores().get("1_game_score"));
model.addAttribute("score", String.format("%.1f", scoreGame1));

return eventUser;
}

private double getGameScore(Object rawGameScore) {
double scoreGame1;
if (rawGameScore != null) {
if (rawGameScore instanceof String) {
try {
scoreGame1 = Double.parseDouble((String) rawGameScore);
} catch (NumberFormatException e) {
scoreGame1 = 0.0;
}
} else if (rawGameScore instanceof Number) {
scoreGame1 = ((Number) rawGameScore).doubleValue();
} else {
scoreGame1 = 0.0;
}
} else {
scoreGame1 = 0.0;
}

return scoreGame1;
}
}

0 comments on commit 434699c

Please sign in to comment.