Skip to content

Commit

Permalink
Fix : 모임 인원수 오류 수정
Browse files Browse the repository at this point in the history
자기자신을 인원에 포함하지 않는 문제
여러명의 인원을 1명으로 인식하는 문제
  • Loading branch information
Astin01 committed Sep 22, 2024
1 parent 5958e52 commit 81c13c2
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.querydsl.core.types.dsl.CaseBuilder;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.NumberExpression;
import com.querydsl.core.types.dsl.NumberPath;
import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.JPQLQuery;
Expand Down Expand Up @@ -240,7 +241,7 @@ public Page<GatheringApplicantResponse> retrieveGatheringApplicant(Pageable page
NumberExpression<Integer> likeCount = countGreatGatheringByGatheringById();
BooleanExpression isBookMark = isGatheringBookmark(userId);
StringExpression gatheringStatus = getGatheringStatus();
NumberExpression<Integer> gatheringApplicantCount = countGatheringApplicant(userId);
NumberExpression<Integer> gatheringApplicantCount = countGatheringApplicant(gathering.id);

JPQLQuery<Gathering> query = from(gathering)
.leftJoin(zoneCategoryParent)
Expand Down Expand Up @@ -273,7 +274,8 @@ public Page<GatheringApplicantResponse> retrieveGatheringApplicant(Pageable page
gathering.startAge,
gathering.endAge,
gathering.personCount,
gatheringApplicantCount, isUserGreatGathering(userId),
gatheringApplicantCount,
isUserGreatGathering(userId),
gatheringStatus,
gathering.isFinish
))
Expand All @@ -285,18 +287,17 @@ gatheringApplicantCount, isUserGreatGathering(userId),
return new PageImpl<>(list, pageable, total);
}

private NumberExpression<Integer> countGatheringApplicant(Long userId) {
private NumberExpression<Integer> countGatheringApplicant(NumberPath<Long> gatheringId) {
QGatheringApplicants gatheringApplicants = QGatheringApplicants.gatheringApplicants;

JPQLQuery<Long> countApplicant = JPAExpressions
.select(gatheringApplicants.count())
JPQLQuery<Integer> countApplicant = JPAExpressions
.select(gatheringApplicants.count().intValue())
.from(gatheringApplicants)
.where(gatheringApplicants.user.id.eq(userId)
.where(gatheringApplicants.gathering.id.eq(gatheringId)
.and(gatheringApplicants.gatheringStatus.eq(GatheringStatus.CONSENT)));

return Expressions.numberTemplate(Long.class, "{0}", countApplicant)
.coalesce(0L)
.intValue();
return Expressions.numberTemplate(Integer.class, "{0}", countApplicant)
.coalesce(0);
}

@Override
Expand Down

0 comments on commit 81c13c2

Please sign in to comment.