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 3fcc8bfd..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) { @@ -77,6 +85,7 @@ public MostInactiveMeetingQuestionListResponse findMostInactiveList(Long meeting .leftJoin(meetingQuestion.memberAnswers, meetingAnswer).fetchJoin() .where( meetingQuestion.meeting.id.eq(meetingId), + meetingQuestion.question.isNotNull(), inactiveCond() ) .orderBy(orderDescByMeetingAnswerCount(), meetingQuestion.startTime.desc()) @@ -103,6 +112,7 @@ public FullInactiveMeetingQuestionListResponse findFullInactiveList(Long meeting .leftJoin(meetingQuestion.question.questionImageFile, questionImageFile).fetchJoin() .where( meetingQuestion.meeting.id.eq(meetingId), + meetingQuestion.question.isNotNull(), inactiveCond() ) .orderBy(orderDescByMeetingAnswerCount(), meetingQuestion.startTime.desc()) @@ -113,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() @@ -129,15 +139,15 @@ private OrderSpecifier orderDescByMeetingAnswerCount() { return new OrderSpecifier<>(Order.DESC, meetingQuestion.memberAnswers.size()); } - private Answer getBestAnswer(MeetingQuestion meetingQuestion) { - return queryFactory + private Optional getBestAnswer(MeetingQuestion meetingQuestion) { + return Optional.ofNullable(queryFactory .select(meetingAnswer.answer) .from(meetingAnswer) .where(meetingAnswer.meetingQuestion.eq(meetingQuestion)) .groupBy(meetingAnswer.answer) .orderBy(meetingAnswer.count().desc()) .limit(1) - .fetchOne(); + .fetchOne()); } private Boolean isAnswered(Long meetingQuestionId, Long meetingMemberId) { @@ -150,13 +160,18 @@ 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()); } + private BooleanExpression activeCond() { + return registeredCond() + .and(meetingQuestion.question.isNotNull()); + } + private BooleanExpression inactiveCond() { LocalDateTime now = LocalDateTime.now(); return meetingQuestion.startTime.lt(now.minusHours(RESPONSE_TIME_LIMIT_HOURS)) diff --git a/src/main/java/org/depromeet/sambad/moring/meeting/question/presentation/response/MostInactiveMeetingQuestionListResponseDetail.java b/src/main/java/org/depromeet/sambad/moring/meeting/question/presentation/response/MostInactiveMeetingQuestionListResponseDetail.java index a23b2cb6..90c923ce 100644 --- a/src/main/java/org/depromeet/sambad/moring/meeting/question/presentation/response/MostInactiveMeetingQuestionListResponseDetail.java +++ b/src/main/java/org/depromeet/sambad/moring/meeting/question/presentation/response/MostInactiveMeetingQuestionListResponseDetail.java @@ -1,6 +1,8 @@ package org.depromeet.sambad.moring.meeting.question.presentation.response; -import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.*; + +import java.util.Optional; import org.depromeet.sambad.moring.answer.domain.Answer; import org.depromeet.sambad.moring.meeting.meeting.domain.Meeting; @@ -17,7 +19,7 @@ public record MostInactiveMeetingQuestionListResponseDetail( @Schema(example = "갖고 싶은 초능력은?", description = "모임 질문 TITLE", requiredMode = REQUIRED) String title, - @Schema(example = "순간이동", description = "가장 많이 선택한 답변", requiredMode = REQUIRED) + @Schema(example = "순간이동", description = "가장 많이 선택한 답변", requiredMode = NOT_REQUIRED) String content, @Schema(example = "70", description = "참여율, 소수점 첫째 자리에서 반올림하여 반환합니다.", requiredMode = REQUIRED) @@ -27,13 +29,14 @@ public record MostInactiveMeetingQuestionListResponseDetail( Long startTime ) { - public static MostInactiveMeetingQuestionListResponseDetail of(MeetingQuestion meetingQuestion, Answer bestAnswer) { + public static MostInactiveMeetingQuestionListResponseDetail of(MeetingQuestion meetingQuestion, + Optional bestAnswer) { Meeting meeting = meetingQuestion.getMeeting(); return MostInactiveMeetingQuestionListResponseDetail.builder() .meetingQuestionId(meetingQuestion.getId()) .title(meetingQuestion.getQuestion().getTitle()) - .content(bestAnswer.getContent()) + .content(bestAnswer.isPresent() ? bestAnswer.get().getContent() : null) .engagementRate(meeting.calculateEngagementRate(meetingQuestion)) .startTime(meetingQuestion.getEpochMilliStartTime()) .build();