Skip to content

Commit

Permalink
[SAMBAD-222] �모임 질문 조회 시 활성화, 비활성화 조건 버그 수정 (#87)
Browse files Browse the repository at this point in the history
* fix: 모임 질문 종료 조건 버그 수정

* fix: 종료된 질문 응답 시, 답변이 없을 경우 버그 수정

* fix: ACTIVE 질문 조건 버그 수정
  • Loading branch information
nahyeon99 authored Aug 5, 2024
1 parent 638b539 commit 791bdf1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Optional<MeetingQuestion> findNextQuestion(Long meetingId) {
}

public ActiveMeetingQuestionResponse findActiveOneByMeeting(Long meetingId, Long loginMeetingMemberId) {
Optional<MeetingQuestion> activeMeetingQuestion = findActiveQuestion(meetingId);
Optional<MeetingQuestion> activeMeetingQuestion = findRegisteredMeetingQuestion(meetingId);

if (activeMeetingQuestion.isEmpty()) {
return null;
Expand All @@ -66,7 +66,15 @@ public ActiveMeetingQuestionResponse findActiveOneByMeeting(Long meetingId, Long
}

public Optional<MeetingQuestion> 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) {
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -113,12 +123,12 @@ public FullInactiveMeetingQuestionListResponse findFullInactiveList(Long meeting
return FullInactiveMeetingQuestionListResponse.of(inactiveMeetingQuestions, pageable);
}

private Optional<MeetingQuestion> findActiveQuestion(Long meetingId) {
private Optional<MeetingQuestion> findRegisteredMeetingQuestion(Long meetingId) {
return Optional.ofNullable(
queryFactory
.selectFrom(meetingQuestion)
.where(meetingQuestion.meeting.id.eq(meetingId),
activeCond())
registeredCond())
.orderBy(meetingQuestion.startTime.asc())
.limit(1)
.fetchOne()
Expand All @@ -129,15 +139,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 All @@ -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))
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 791bdf1

Please sign in to comment.