Skip to content

Commit

Permalink
refactor: postgreSQL group by
Browse files Browse the repository at this point in the history
  • Loading branch information
alstn113 committed Dec 11, 2024
1 parent 7786e21 commit 736d1b4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ExamSummaryDto {
private String description;
private ExamStatus status;
private AuthorDto author;
private int questionCount;
private Long questionCount;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;

Expand All @@ -27,7 +27,7 @@ public ExamSummaryDto(
String description,
ExamStatus status,
AuthorDto author,
int questionCount,
Long questionCount,
LocalDateTime createdAt,
LocalDateTime updatedAt
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.fluffy.auth.domain.QMember.member;
import static com.fluffy.exam.domain.QExam.exam;
import static com.fluffy.exam.domain.QQuestion.question;
import static com.querydsl.core.types.ExpressionUtils.count;

import com.fluffy.exam.domain.ExamRepositoryCustom;
import com.fluffy.exam.domain.ExamStatus;
Expand Down Expand Up @@ -37,14 +38,25 @@ public List<ExamSummaryDto> findPublishedSummaries() {
exam.description.value,
exam.status,
AUTHOR_PROJECTION,
exam.questionGroup.questions.size(), // postgreSQL group by 이슈로 인함.
question.count(),
exam.createdAt,
exam.updatedAt
))
.from(exam)
.leftJoin(member).on(exam.memberId.eq(member.id))
.leftJoin(exam.questionGroup.questions, question)
.where(exam.status.eq(ExamStatus.PUBLISHED))
.groupBy(
exam.id,
exam.title,
exam.description,
exam.status,
member.id,
member.name,
member.avatarUrl,
exam.createdAt,
exam.updatedAt
)
.orderBy(exam.updatedAt.desc())
.fetch();
}
Expand All @@ -58,14 +70,25 @@ public List<ExamSummaryDto> findMySummaries(ExamStatus status, Long memberId) {
exam.description.value,
exam.status,
AUTHOR_PROJECTION,
exam.questionGroup.questions.size(),
question.count(),
exam.createdAt,
exam.updatedAt
))
.from(exam)
.leftJoin(member).on(exam.memberId.eq(member.id))
.leftJoin(exam.questionGroup.questions, question)
.where(exam.memberId.eq(memberId), exam.status.eq(status))
.groupBy(
exam.id,
exam.title,
exam.description,
exam.status,
member.id,
member.name,
member.avatarUrl,
exam.createdAt,
exam.updatedAt
)
.orderBy(exam.updatedAt.desc())
.fetch();
}
Expand Down

0 comments on commit 736d1b4

Please sign in to comment.