Skip to content

Commit

Permalink
fix: 종료된 질문 응답 시, 답변이 없을 경우 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
nahyeon99 committed Aug 4, 2024
1 parent d44e561 commit 66b76c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ private OrderSpecifier<Integer> orderDescByMeetingAnswerCount() {
return new OrderSpecifier<>(Order.DESC, meetingQuestion.memberAnswers.size());
}

private Answer getBestAnswer(MeetingQuestion meetingQuestion) {
return queryFactory
private Optional<Answer> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand All @@ -27,13 +29,14 @@ public record MostInactiveMeetingQuestionListResponseDetail(
Long startTime
) {

public static MostInactiveMeetingQuestionListResponseDetail of(MeetingQuestion meetingQuestion, Answer bestAnswer) {
public static MostInactiveMeetingQuestionListResponseDetail of(MeetingQuestion meetingQuestion,
Optional<Answer> 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();
Expand Down

0 comments on commit 66b76c3

Please sign in to comment.