Skip to content

Commit

Permalink
fix : 그룹 캡슐 조회 수정
Browse files Browse the repository at this point in the history
- 사용자가 속한 그룹 캡슐도 나오도록 수정
  • Loading branch information
seokho-1116 committed Jun 19, 2024
1 parent 05805be commit c92e952
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import static site.timecapsulearchive.core.domain.capsule.entity.QCapsule.capsule;
import static site.timecapsulearchive.core.domain.capsuleskin.entity.QCapsuleSkin.capsuleSkin;
import static site.timecapsulearchive.core.domain.member.entity.QMember.member;
import static site.timecapsulearchive.core.domain.member_group.entity.QMemberGroup.memberGroup;

import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.ComparablePath;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import java.util.Optional;
Expand All @@ -19,6 +21,7 @@
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.NearbyARCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.NearbyCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.treasure_capsule.data.dto.TreasureCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.member_group.entity.MemberGroup;

@Repository
@RequiredArgsConstructor
Expand All @@ -41,6 +44,14 @@ public List<NearbyARCapsuleSummaryDto> findARCapsuleSummaryDtosByCurrentLocation
final Polygon mbr,
final CapsuleType capsuleType
) {
List<Long> groupIds = jpaQueryFactory
.select(
memberGroup.group.id
)
.from(memberGroup)
.where(memberGroup.member.id.eq(memberId))
.fetch();

return jpaQueryFactory
.select(
Projections.constructor(
Expand All @@ -58,14 +69,15 @@ public List<NearbyARCapsuleSummaryDto> findARCapsuleSummaryDtosByCurrentLocation
.from(capsule)
.join(capsule.capsuleSkin, capsuleSkin)
.join(capsule.member, member)
.where(ST_Contains(mbr, capsule.point).and(capsuleFilter(capsuleType, memberId)))
.where(ST_Contains(mbr, capsule.point).and(capsuleFilter(capsuleType, memberId, groupIds)))
.fetch();
}

private BooleanExpression capsuleFilter(CapsuleType capsuleType, Long memberId) {
private BooleanExpression capsuleFilter(CapsuleType capsuleType, Long memberId, List<Long> groupIds) {
return switch (capsuleType) {
case ALL -> capsule.member.id.eq(memberId);
case ALL -> capsule.member.id.eq(memberId).or(capsule.group.id.in(groupIds));
case TREASURE -> capsule.type.eq(capsuleType);
case GROUP -> capsule.type.eq(CapsuleType.GROUP).and(capsule.group.id.in(groupIds));
default -> capsule.type.eq(capsuleType).and(capsule.member.id.eq(memberId));
};
}
Expand All @@ -84,6 +96,14 @@ public List<NearbyCapsuleSummaryDto> findCapsuleSummaryDtosByCurrentLocationAndC
final Polygon mbr,
final CapsuleType capsuleType
) {
List<Long> groupIds = jpaQueryFactory
.select(
memberGroup.group.id
)
.from(memberGroup)
.where(memberGroup.member.id.eq(memberId))
.fetch();

return jpaQueryFactory
.select(
Projections.constructor(
Expand All @@ -96,7 +116,7 @@ public List<NearbyCapsuleSummaryDto> findCapsuleSummaryDtosByCurrentLocationAndC
.from(capsule)
.join(capsule.capsuleSkin, capsuleSkin)
.join(capsule.member, member)
.where(ST_Contains(mbr, capsule.point).and(capsuleFilter(capsuleType, memberId)))
.where(ST_Contains(mbr, capsule.point).and(capsuleFilter(capsuleType, memberId, groupIds)))
.fetch();
}

Expand Down

0 comments on commit c92e952

Please sign in to comment.