Skip to content

Commit

Permalink
Fix : 마이페이지 모임 조회 오류 수정 (#207)
Browse files Browse the repository at this point in the history
* Fix : 삭제된 모임 조회되지 않도록 수정

* Fix : 모임 인원수 오류 수정

자기자신을 인원에 포함하지 않는 문제
여러명의 인원을 1명으로 인식하는 문제
  • Loading branch information
Astin01 authored Sep 23, 2024
1 parent 6d80eb6 commit b820b58
Showing 1 changed file with 13 additions and 12 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 @@ -149,7 +150,7 @@ public Page<GatheringMypageResponse> retrieveGatheringHost(Pageable pageable, Lo
.on(gatheringApplicants.gathering.id.eq(gathering.id)
.and(gatheringApplicants.gatheringStatus.eq(GatheringStatus.CONSENT)))
.orderBy(gathering.createdAt.desc())
.where(gathering.user.id.eq(userId));
.where(gathering.user.id.eq(userId).and(gathering.isDeleted.eq(false)));

List<GatheringMypageResponse> list = query
.groupBy(gathering.id, zoneCategoryParent.id, zoneCategoryChild.id,
Expand Down Expand Up @@ -200,7 +201,7 @@ public Page<GatheringMypageResponse> retrieveGatheringBookmark(Pageable pageable
.leftJoin(bookMarkGathering)
.on(bookMarkGathering.gathering.id.eq(gathering.id))
.orderBy(gathering.createdAt.desc())
.where(bookMarkGathering.user.id.eq(userId));
.where(bookMarkGathering.user.id.eq(userId).and(gathering.isDeleted.eq(false)));

List<GatheringMypageResponse> list = query
.groupBy(gathering.id, zoneCategoryParent.id, zoneCategoryChild.id,
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 All @@ -250,7 +251,7 @@ public Page<GatheringApplicantResponse> retrieveGatheringApplicant(Pageable page
.leftJoin(gatheringApplicants)
.on(gatheringApplicants.gathering.id.eq(gathering.id))
.orderBy(gathering.createdAt.desc())
.where(gatheringApplicants.user.id.eq(userId).and(gathering.user.id.eq(userId).not()));
.where(gatheringApplicants.user.id.eq(userId).and(gathering.user.id.eq(userId).not()).and(gathering.isDeleted.eq(false)));

List<GatheringApplicantResponse> list = query
.groupBy(gathering.id, zoneCategoryParent.id, zoneCategoryChild.id,
Expand All @@ -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 b820b58

Please sign in to comment.