From 8bc6f1f676814edaaeeb3c76d92d68aae63d4651 Mon Sep 17 00:00:00 2001 From: ddongseop Date: Fri, 5 Apr 2024 23:49:38 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20=EC=83=88=EB=A1=9C=EA=B3=A0=EC=B9=A8=20?= =?UTF-8?q?=EB=B2=84=ED=8A=BC=20=ED=91=9C=EC=8B=9C=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qna/dto/response/TodayQnAResponseDto.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/TodayQnAResponseDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/TodayQnAResponseDto.java index 9ff27324..5790c66f 100644 --- a/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/TodayQnAResponseDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/TodayQnAResponseDto.java @@ -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) @@ -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; @@ -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(); @@ -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() @@ -83,6 +103,7 @@ public static TodayQnAResponseDto of(User myUser, User opponentUser, int count, .isMyAnswer(isMyAnswer) .opponentUsername("상대방") .myUsername(myUser.getUsername()) + .isRerollTime(isRerollAvailable) .build(); } }