From c92e9527d8bba217cf479e21693ffb7afbab7b3d Mon Sep 17 00:00:00 2001 From: hong seokho Date: Thu, 20 Jun 2024 00:22:09 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20=EA=B7=B8=EB=A3=B9=20=EC=BA=A1?= =?UTF-8?q?=EC=8A=90=20=EC=A1=B0=ED=9A=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 사용자가 속한 그룹 캡슐도 나오도록 수정 --- .../capsule/CapsuleQueryRepositoryImpl.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/generic_capsule/repository/capsule/CapsuleQueryRepositoryImpl.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/generic_capsule/repository/capsule/CapsuleQueryRepositoryImpl.java index 2e4301ecb..99bf56000 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/generic_capsule/repository/capsule/CapsuleQueryRepositoryImpl.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/generic_capsule/repository/capsule/CapsuleQueryRepositoryImpl.java @@ -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; @@ -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 @@ -41,6 +44,14 @@ public List findARCapsuleSummaryDtosByCurrentLocation final Polygon mbr, final CapsuleType capsuleType ) { + List groupIds = jpaQueryFactory + .select( + memberGroup.group.id + ) + .from(memberGroup) + .where(memberGroup.member.id.eq(memberId)) + .fetch(); + return jpaQueryFactory .select( Projections.constructor( @@ -58,14 +69,15 @@ public List 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 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)); }; } @@ -84,6 +96,14 @@ public List findCapsuleSummaryDtosByCurrentLocationAndC final Polygon mbr, final CapsuleType capsuleType ) { + List groupIds = jpaQueryFactory + .select( + memberGroup.group.id + ) + .from(memberGroup) + .where(memberGroup.member.id.eq(memberId)) + .fetch(); + return jpaQueryFactory .select( Projections.constructor( @@ -96,7 +116,7 @@ public List 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(); }