diff --git a/src/main/java/org/depromeet/sambad/moring/meeting/question/infrastructure/MeetingQuestionQueryRepository.java b/src/main/java/org/depromeet/sambad/moring/meeting/question/infrastructure/MeetingQuestionQueryRepository.java index f1ab4816..30873f3b 100644 --- a/src/main/java/org/depromeet/sambad/moring/meeting/question/infrastructure/MeetingQuestionQueryRepository.java +++ b/src/main/java/org/depromeet/sambad/moring/meeting/question/infrastructure/MeetingQuestionQueryRepository.java @@ -53,7 +53,7 @@ public Optional findNextQuestion(Long meetingId) { } public ActiveMeetingQuestionResponse findActiveOneByMeeting(Long meetingId, Long loginMeetingMemberId) { - Optional activeMeetingQuestion = findActiveQuestion(meetingId); + Optional activeMeetingQuestion = findRegisteredMeetingQuestion(meetingId); if (activeMeetingQuestion.isEmpty()) { return null; @@ -66,7 +66,15 @@ public ActiveMeetingQuestionResponse findActiveOneByMeeting(Long meetingId, Long } public Optional findActiveOneByMeeting(Long meetingId) { - return findActiveQuestion(meetingId); + return Optional.ofNullable( + queryFactory + .selectFrom(meetingQuestion) + .where(meetingQuestion.meeting.id.eq(meetingId), + activeCond()) + .orderBy(meetingQuestion.startTime.asc()) + .limit(1) + .fetchOne() + ); } public MostInactiveMeetingQuestionListResponse findMostInactiveList(Long meetingId) { @@ -115,12 +123,12 @@ public FullInactiveMeetingQuestionListResponse findFullInactiveList(Long meeting return FullInactiveMeetingQuestionListResponse.of(inactiveMeetingQuestions, pageable); } - private Optional findActiveQuestion(Long meetingId) { + private Optional findRegisteredMeetingQuestion(Long meetingId) { return Optional.ofNullable( queryFactory .selectFrom(meetingQuestion) .where(meetingQuestion.meeting.id.eq(meetingId), - activeCond()) + registeredCond()) .orderBy(meetingQuestion.startTime.asc()) .limit(1) .fetchOne() @@ -152,11 +160,15 @@ private Boolean isAnswered(Long meetingQuestionId, Long meetingMemberId) { return fetchOne != null; } - private BooleanExpression activeCond() { + private BooleanExpression registeredCond() { LocalDateTime now = LocalDateTime.now(); return meetingQuestion.startTime.loe(now) .and(meetingQuestion.startTime.goe(now.minusHours(RESPONSE_TIME_LIMIT_HOURS))) - .and(isAnsweredByAllCond().not()) + .and(isAnsweredByAllCond().not()); + } + + private BooleanExpression activeCond() { + return registeredCond() .and(meetingQuestion.question.isNotNull()); }