From 66b76c30be2103e02b5c90439c7d2b3732207817 Mon Sep 17 00:00:00 2001 From: nahyeon99 Date: Sun, 4 Aug 2024 20:26:19 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=A2=85=EB=A3=8C=EB=90=9C=20=EC=A7=88?= =?UTF-8?q?=EB=AC=B8=20=EC=9D=91=EB=8B=B5=20=EC=8B=9C,=20=EB=8B=B5?= =?UTF-8?q?=EB=B3=80=EC=9D=B4=20=EC=97=86=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MeetingQuestionQueryRepository.java | 6 +++--- ...MostInactiveMeetingQuestionListResponseDetail.java | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) 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 f0b6e17a..f1ab4816 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 @@ -131,15 +131,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) { 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();