diff --git a/api/src/main/java/lab/en2b/quizapi/game/Game.java b/api/src/main/java/lab/en2b/quizapi/game/Game.java index 579f0346..76e03aeb 100644 --- a/api/src/main/java/lab/en2b/quizapi/game/Game.java +++ b/api/src/main/java/lab/en2b/quizapi/game/Game.java @@ -7,7 +7,9 @@ import lab.en2b.quizapi.questions.question.Question; import lombok.*; +import java.time.Instant; import java.time.LocalDateTime; +import java.time.OffsetDateTime; import java.util.List; @Entity @@ -29,7 +31,7 @@ public class Game { private Long correctlyAnsweredQuestions = 0L; private String language; - private LocalDateTime roundStartTime; + private String roundStartTime; @NonNull private Integer roundDuration; private boolean currentQuestionAnswered; @@ -62,7 +64,7 @@ public void newRound(Question question){ setCurrentQuestionAnswered(false); getQuestions().add(question); increaseRound(); - setRoundStartTime(LocalDateTime.now()); + setRoundStartTime(Instant.now().toString()); } private void increaseRound(){ @@ -90,7 +92,7 @@ private boolean currentRoundIsOver(){ } private boolean roundTimeHasExpired(){ - return getRoundStartTime()!= null && LocalDateTime.now().isAfter(getRoundStartTime().plusSeconds(getRoundDuration())); + return getRoundStartTime()!= null && Instant.now().isAfter(Instant.parse(getRoundStartTime()).plusSeconds(getRoundDuration())); } public boolean answerQuestion(Long answerId){ diff --git a/api/src/main/java/lab/en2b/quizapi/game/dtos/GameResponseDto.java b/api/src/main/java/lab/en2b/quizapi/game/dtos/GameResponseDto.java index 991ec4a3..ffb37336 100644 --- a/api/src/main/java/lab/en2b/quizapi/game/dtos/GameResponseDto.java +++ b/api/src/main/java/lab/en2b/quizapi/game/dtos/GameResponseDto.java @@ -9,6 +9,7 @@ import lombok.EqualsAndHashCode; import java.time.LocalDateTime; +import java.time.OffsetDateTime; @AllArgsConstructor @Data @@ -34,7 +35,7 @@ public class GameResponseDto { @Schema(description = "Moment when the timer has started", example = "LocalDateTime.now()") @JsonProperty("round_start_time") - private LocalDateTime roundStartTime; + private String roundStartTime; @Schema(description = "Number of seconds for the player to answer the question", example = "20") @JsonProperty("round_duration") diff --git a/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java b/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java index 16ca722d..ab02dc2d 100644 --- a/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java +++ b/api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java @@ -220,7 +220,7 @@ public void getCurrentQuestionRoundFinished() { when(questionService.findRandomQuestion(any())).thenReturn(defaultQuestion); when(userService.getUserByAuthentication(authentication)).thenReturn(defaultUser); gameService.startRound(1L,authentication); - defaultGame.setRoundStartTime(LocalDateTime.now().minusSeconds(100)); + defaultGame.setRoundStartTime(Instant.now().minusSeconds(100).toString()); assertThrows(IllegalStateException.class, () -> gameService.getCurrentQuestion(1L,authentication)); } @@ -285,7 +285,7 @@ public void answerQuestionWhenRoundHasFinished(){ when(questionService.findRandomQuestion(any())).thenReturn(defaultQuestion); gameService.newGame(authentication); gameService.startRound(1L, authentication); - defaultGame.setRoundStartTime(LocalDateTime.now().minusSeconds(100)); + defaultGame.setRoundStartTime(Instant.now().minusSeconds(100).toString()); assertThrows(IllegalStateException.class, () -> gameService.answerQuestion(1L, new GameAnswerDto(1L), authentication)); }