Skip to content

Commit

Permalink
[SAMBAD-256] 쿼리 가독성 강화
Browse files Browse the repository at this point in the history
  • Loading branch information
kkjsw17 committed Aug 16, 2024
1 parent 87076df commit 83b8f4e
Showing 1 changed file with 5 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.JPQLQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -157,32 +156,19 @@ public List<MeetingMember> findMeetingMembersByMeetingQuestionId(Long meetingQue
.fetch();
}

/*
* 각 모임 별로, 가장 최근 만료된 질문이 비활성화 상태인 경우만 조회
*
* SELECT *
* FROM meeting_question mq
* WHERE mq.question_id IS NULL
* AND mq.status = 'INACTIVE'
* AND mq.expired_at= (
* SELECT MAX(mq2.expired_at)
* FROM meeting_question mq2
* WHERE mq2.meeting_id = mq.meeting_id
* );
*/
public List<MeetingQuestion> findAllInactiveAndQuestionNotRegistered() {
QMeetingQuestion mq1 = new QMeetingQuestion("mq1");
QMeetingQuestion mq2 = new QMeetingQuestion("mq2");

JPQLQuery<LocalDateTime> maxExpiredAtSubQuery = select(mq2.expiredAt.max())
.from(mq2)
.where(mq2.meeting.id.eq(mq1.meeting.id));

return queryFactory.selectFrom(mq1)
.where(
mq1.question.isNull(),
mq1.status.eq(INACTIVE),
mq1.expiredAt.eq(maxExpiredAtSubQuery)
mq1.expiredAt.eq(
select(mq2.expiredAt.max())
.from(mq2)
.where(mq2.meeting.id.eq(mq1.meeting.id))
)
)
.fetch();
}
Expand Down

0 comments on commit 83b8f4e

Please sign in to comment.