Skip to content

Commit

Permalink
[FIX] 새로고침 버튼 표시 관련 필드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ddongseop committed Apr 5, 2024
1 parent e7e0eec commit 8bc6f1f
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import sopt.org.umbba.domain.domain.qna.Question;
import sopt.org.umbba.domain.domain.user.User;

import java.time.Duration;
import java.time.LocalDateTime;

@Getter
@Builder
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
Expand All @@ -29,6 +32,8 @@ public class TodayQnAResponseDto {
private String opponentUsername;
private String myUsername;

private Boolean isRerollTime;


public static TodayQnAResponseDto of(User myUser, User opponentUser, int count, QnA todayQnA, Question todayQuestion) {
String opponentQuestion;
Expand All @@ -38,6 +43,20 @@ public static TodayQnAResponseDto of(User myUser, User opponentUser, int count,
boolean isOpponentAnswer;
boolean isMyAnswer;

boolean isRerollAvailable = true;

// 하루에 한번만 질문 새로고침 가능
LocalDateTime lastRerollChange = myUser.getLastRerollChange();
LocalDateTime now = LocalDateTime.now();
if (lastRerollChange != null) {
Duration duration = Duration.between(lastRerollChange, now);
long hoursPassed = duration.toHours();

if (hoursPassed < 24) {
isRerollAvailable = false;
}
}

if (myUser.isMeChild()) {
opponentQuestion = todayQuestion.getParentQuestion();
myQuestion = todayQuestion.getChildQuestion();
Expand Down Expand Up @@ -68,6 +87,7 @@ public static TodayQnAResponseDto of(User myUser, User opponentUser, int count,
.isMyAnswer(isMyAnswer)
.opponentUsername(opponentUser.getUsername())
.myUsername(myUser.getUsername())
.isRerollTime(isRerollAvailable)
.build();
} else {
return TodayQnAResponseDto.builder()
Expand All @@ -83,6 +103,7 @@ public static TodayQnAResponseDto of(User myUser, User opponentUser, int count,
.isMyAnswer(isMyAnswer)
.opponentUsername("상대방")
.myUsername(myUser.getUsername())
.isRerollTime(isRerollAvailable)
.build();
}
}
Expand Down

0 comments on commit 8bc6f1f

Please sign in to comment.