From 60af03f0d68e09453bdfaf8e6fe6b92197c02af1 Mon Sep 17 00:00:00 2001 From: Diego Villanueva Date: Mon, 29 Apr 2024 00:52:26 +0200 Subject: [PATCH] Fix: Repeated questions problem --- api/src/main/java/lab/en2b/quizapi/game/GameService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/lab/en2b/quizapi/game/GameService.java b/api/src/main/java/lab/en2b/quizapi/game/GameService.java index 36e10efd..5491fb04 100644 --- a/api/src/main/java/lab/en2b/quizapi/game/GameService.java +++ b/api/src/main/java/lab/en2b/quizapi/game/GameService.java @@ -71,7 +71,11 @@ public GameResponseDto startRound(Long id, Authentication authentication) { private Question generateQuestionForGame(Game game){ Optional 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);