Skip to content

Commit

Permalink
Fix: Repeated questions problem
Browse files Browse the repository at this point in the history
  • Loading branch information
UO283615 committed Apr 28, 2024
1 parent 536ef1c commit 60af03f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion api/src/main/java/lab/en2b/quizapi/game/GameService.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ public GameResponseDto startRound(Long id, Authentication authentication) {
private Question generateQuestionForGame(Game game){
Optional<Question> question = questionService.findRandomQuestion(game.getLanguage(),game.getQuestionCategoriesForGamemode());
if(question.isPresent()){
return question.get();
Question q = question.get();
if (game.getQuestions().contains(q)){
return generateQuestionForGame(game);
}
return q;
} else {
game.setGameOver(true);
gameRepository.save(game);
Expand Down

0 comments on commit 60af03f

Please sign in to comment.