Skip to content

Commit

Permalink
fix: back now uses string
Browse files Browse the repository at this point in the history
  • Loading branch information
Toto-hitori committed Apr 9, 2024
1 parent ea70784 commit 3c3ef53
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
8 changes: 5 additions & 3 deletions api/src/main/java/lab/en2b/quizapi/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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(){
Expand Down Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.time.OffsetDateTime;

@AllArgsConstructor
@Data
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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));
}

Expand Down

0 comments on commit 3c3ef53

Please sign in to comment.