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 b5f94b6 + 8d23835 commit df94416
Showing 1 changed file with 25 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 Down Expand Up @@ -41,7 +43,7 @@ public List<NearbyARCapsuleSummaryDto> findARCapsuleSummaryDtosByCurrentLocation
final Polygon mbr,
final CapsuleType capsuleType
) {
return jpaQueryFactory
JPAQuery<NearbyARCapsuleSummaryDto> dynamicQuery = jpaQueryFactory
.select(
Projections.constructor(
NearbyARCapsuleSummaryDto.class,
Expand All @@ -57,7 +59,11 @@ public List<NearbyARCapsuleSummaryDto> findARCapsuleSummaryDtosByCurrentLocation
)
.from(capsule)
.join(capsule.capsuleSkin, capsuleSkin)
.join(capsule.member, member)
.join(capsule.member, member);

joinMemberGroupForGroupCapsule(memberId, capsuleType, dynamicQuery);

return dynamicQuery
.where(ST_Contains(mbr, capsule.point).and(capsuleFilter(capsuleType, memberId)))
.fetch();
}
Expand All @@ -66,6 +72,7 @@ private BooleanExpression capsuleFilter(CapsuleType capsuleType, Long memberId)
return switch (capsuleType) {
case ALL -> capsule.member.id.eq(memberId);
case TREASURE -> capsule.type.eq(capsuleType);
case GROUP -> capsule.type.eq(CapsuleType.GROUP);
default -> capsule.type.eq(capsuleType).and(capsule.member.id.eq(memberId));
};
}
Expand All @@ -84,7 +91,7 @@ public List<NearbyCapsuleSummaryDto> findCapsuleSummaryDtosByCurrentLocationAndC
final Polygon mbr,
final CapsuleType capsuleType
) {
return jpaQueryFactory
JPAQuery<NearbyCapsuleSummaryDto> dynamicQuery = jpaQueryFactory
.select(
Projections.constructor(
NearbyCapsuleSummaryDto.class,
Expand All @@ -95,11 +102,25 @@ public List<NearbyCapsuleSummaryDto> findCapsuleSummaryDtosByCurrentLocationAndC
)
.from(capsule)
.join(capsule.capsuleSkin, capsuleSkin)
.join(capsule.member, member)
.join(capsule.member, member);

joinMemberGroupForGroupCapsule(memberId, capsuleType, dynamicQuery);

return dynamicQuery
.where(ST_Contains(mbr, capsule.point).and(capsuleFilter(capsuleType, memberId)))
.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 df94416

Please sign in to comment.