Skip to content

Commit

Permalink
Merge branch 'develop_back_core' of https://github.com/tukcomCD2024/D…
Browse files Browse the repository at this point in the history
…roidBlossom into develop_back_core
  • Loading branch information
GaBaljaintheroom committed Jun 19, 2024
2 parents 5cee5e3 + 277bbbb commit d56cdeb
Showing 1 changed file with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,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 @@ -43,7 +44,15 @@ public List<NearbyARCapsuleSummaryDto> findARCapsuleSummaryDtosByCurrentLocation
final Polygon mbr,
final CapsuleType capsuleType
) {
JPAQuery<NearbyARCapsuleSummaryDto> dynamicQuery = jpaQueryFactory
List<Long> groupIds = jpaQueryFactory
.select(
memberGroup.group.id
)
.from(memberGroup)
.where(memberGroup.member.id.eq(memberId))
.fetch();

return jpaQueryFactory
.select(
Projections.constructor(
NearbyARCapsuleSummaryDto.class,
Expand All @@ -59,20 +68,16 @@ public List<NearbyARCapsuleSummaryDto> findARCapsuleSummaryDtosByCurrentLocation
)
.from(capsule)
.join(capsule.capsuleSkin, capsuleSkin)
.join(capsule.member, member);

joinMemberGroupForGroupCapsule(memberId, capsuleType, dynamicQuery);

return dynamicQuery
.where(ST_Contains(mbr, capsule.point).and(capsuleFilter(capsuleType, memberId)))
.join(capsule.member, member)
.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);
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 @@ -91,7 +96,15 @@ public List<NearbyCapsuleSummaryDto> findCapsuleSummaryDtosByCurrentLocationAndC
final Polygon mbr,
final CapsuleType capsuleType
) {
JPAQuery<NearbyCapsuleSummaryDto> dynamicQuery = jpaQueryFactory
List<Long> groupIds = jpaQueryFactory
.select(
memberGroup.group.id
)
.from(memberGroup)
.where(memberGroup.member.id.eq(memberId))
.fetch();

return jpaQueryFactory
.select(
Projections.constructor(
NearbyCapsuleSummaryDto.class,
Expand All @@ -102,25 +115,11 @@ public List<NearbyCapsuleSummaryDto> findCapsuleSummaryDtosByCurrentLocationAndC
)
.from(capsule)
.join(capsule.capsuleSkin, capsuleSkin)
.join(capsule.member, member);

joinMemberGroupForGroupCapsule(memberId, capsuleType, dynamicQuery);

return dynamicQuery
.where(ST_Contains(mbr, capsule.point).and(capsuleFilter(capsuleType, memberId)))
.join(capsule.member, member)
.where(ST_Contains(mbr, capsule.point).and(capsuleFilter(capsuleType, memberId, groupIds)))
.fetch();
}

private void joinMemberGroupForGroupCapsule(Long memberId, CapsuleType capsuleType,
JPAQuery<?> dynamicQuery) {
if (capsuleType.equals(CapsuleType.GROUP)) {
dynamicQuery
.join(memberGroup).on(memberGroup.member.id.eq(capsule.member.id)
.and(memberGroup.member.id.eq(memberId))
);
}
}

/**
* 지도에서 사용자의 친구들의 캡슐을 찾기 위해 현재 위치에서 범위 내의 사용자의 친구가 만든 캡슐을 조회한다.
*
Expand Down

0 comments on commit d56cdeb

Please sign in to comment.