Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : 보물 타입 추가 및 기존 API 검증 #451

Merged
merged 4 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea
.idea

data
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public enum CapsuleType {
SECRET,
PUBLIC,
GROUP,
TREASURE,
ALL
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,16 @@ public List<NearbyARCapsuleSummaryDto> findARCapsuleSummaryDtosByCurrentLocation
.from(capsule)
.join(capsule.capsuleSkin, capsuleSkin)
.join(capsule.member, member)
.where(ST_Contains(mbr, capsule.point).and(capsule.member.id.eq(memberId)
.and(eqCapsuleType(capsuleType))))
.where(ST_Contains(mbr, capsule.point).and(capsuleFilter(capsuleType, memberId)))
.fetch();
}

private BooleanExpression eqCapsuleType(CapsuleType capsuleType) {
if (capsuleType.equals(CapsuleType.ALL)) {
return null;
}

return capsule.type.eq(capsuleType);
private BooleanExpression capsuleFilter(CapsuleType capsuleType, Long memberId) {
return switch (capsuleType) {
case ALL -> capsule.member.id.eq(memberId);
case TREASURE -> capsule.type.eq(capsuleType);
default -> capsule.type.eq(capsuleType).and(capsule.member.id.eq(memberId));
};
}

/**
Expand Down Expand Up @@ -93,8 +92,7 @@ public List<NearbyCapsuleSummaryDto> findCapsuleSummaryDtosByCurrentLocationAndC
.from(capsule)
.join(capsule.capsuleSkin, capsuleSkin)
.join(capsule.member, member)
.where(ST_Contains(mbr, capsule.point).and(capsule.member.id.eq(memberId))
.and(eqCapsuleType(capsuleType)))
.where(ST_Contains(mbr, capsule.point).and(capsuleFilter(capsuleType, memberId)))
.fetch();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository;

import static org.assertj.core.api.Assertions.assertThat;

import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import java.util.ArrayList;
Expand Down Expand Up @@ -134,10 +132,10 @@ void setup(@Autowired EntityManager entityManager) {

//then
SoftAssertions.assertSoftly(softly -> {
assertThat(capsules).isNotEmpty();
assertThat(capsules).allMatch(c -> c.capsuleType().equals(capsuleType));
assertThat(capsules).allMatch(c -> myCapsuleIds.contains(c.id()));
assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
softly.assertThat(capsules).isNotEmpty();
softly.assertThat(capsules).allMatch(c -> c.capsuleType().equals(capsuleType));
softly.assertThat(capsules).allMatch(c -> myCapsuleIds.contains(c.id()));
softly.assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
});
}

Expand All @@ -154,10 +152,10 @@ void setup(@Autowired EntityManager entityManager) {

//then
SoftAssertions.assertSoftly(softly -> {
assertThat(capsules).isNotEmpty();
assertThat(capsules).allMatch(c -> c.capsuleType().equals(capsuleType));
assertThat(capsules).allMatch(c -> myCapsuleIds.contains(c.id()));
assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
softly.assertThat(capsules).isNotEmpty();
softly.assertThat(capsules).allMatch(c -> c.capsuleType().equals(capsuleType));
softly.assertThat(capsules).allMatch(c -> myCapsuleIds.contains(c.id()));
softly.assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
});
}

Expand All @@ -174,10 +172,10 @@ void setup(@Autowired EntityManager entityManager) {

//then
SoftAssertions.assertSoftly(softly -> {
assertThat(capsules).isNotEmpty();
assertThat(capsules).allMatch(c -> c.capsuleType().equals(capsuleType));
assertThat(capsules).allMatch(c -> myCapsuleIds.contains(c.id()));
assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
softly.assertThat(capsules).isNotEmpty();
softly.assertThat(capsules).allMatch(c -> c.capsuleType().equals(capsuleType));
softly.assertThat(capsules).allMatch(c -> myCapsuleIds.contains(c.id()));
softly.assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
});
}

Expand All @@ -194,10 +192,10 @@ void setup(@Autowired EntityManager entityManager) {

//then
SoftAssertions.assertSoftly(softly -> {
assertThat(capsules).isNotEmpty();
assertThat(capsules).allMatch(c -> c.capsuleType().equals(capsuleType));
assertThat(capsules).allMatch(c -> myCapsuleIds.contains(c.id()));
assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
softly.assertThat(capsules).isNotEmpty();
softly.assertThat(capsules).allMatch(c -> c.capsuleType().equals(capsuleType));
softly.assertThat(capsules).allMatch(c -> myCapsuleIds.contains(c.id()));
softly.assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
});
}

Expand All @@ -214,14 +212,14 @@ void setup(@Autowired EntityManager entityManager) {

//then
SoftAssertions.assertSoftly(softly -> {
assertThat(capsules).isNotEmpty();
assertThat(capsules).allMatch(
softly.assertThat(capsules).isNotEmpty();
softly.assertThat(capsules).allMatch(
c -> c.capsuleType().equals(CapsuleType.PUBLIC) ||
c.capsuleType().equals(CapsuleType.SECRET) ||
c.capsuleType().equals(CapsuleType.GROUP)
);
assertThat(capsules).allMatch(c -> myCapsuleIds.contains(c.id()));
assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
softly.assertThat(capsules).allMatch(c -> myCapsuleIds.contains(c.id()));
softly.assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
});
}

Expand All @@ -238,14 +236,14 @@ void setup(@Autowired EntityManager entityManager) {

//then
SoftAssertions.assertSoftly(softly -> {
assertThat(capsules).isNotEmpty();
assertThat(capsules).allMatch(
softly.assertThat(capsules).isNotEmpty();
softly.assertThat(capsules).allMatch(
c -> c.capsuleType().equals(CapsuleType.PUBLIC) ||
c.capsuleType().equals(CapsuleType.SECRET) ||
c.capsuleType().equals(CapsuleType.GROUP)
);
assertThat(capsules).allMatch(c -> myCapsuleIds.contains(c.id()));
assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
softly.assertThat(capsules).allMatch(c -> myCapsuleIds.contains(c.id()));
softly.assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
});
}

Expand All @@ -261,10 +259,10 @@ void setup(@Autowired EntityManager entityManager) {

//then
SoftAssertions.assertSoftly(softly -> {
assertThat(capsules).isNotEmpty();
assertThat(capsules).allMatch(c -> friendCapsuleIds.contains(c.id()));
assertThat(capsules).allMatch(c -> c.capsuleType().equals(CapsuleType.PUBLIC));
assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
softly.assertThat(capsules).isNotEmpty();
softly.assertThat(capsules).allMatch(c -> friendCapsuleIds.contains(c.id()));
softly.assertThat(capsules).allMatch(c -> c.capsuleType().equals(CapsuleType.PUBLIC));
softly.assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
});
}

Expand All @@ -280,10 +278,10 @@ void setup(@Autowired EntityManager entityManager) {

//then
SoftAssertions.assertSoftly(softly -> {
assertThat(capsules).isNotEmpty();
assertThat(capsules).allMatch(c -> friendCapsuleIds.contains(c.id()));
assertThat(capsules).allMatch(c -> c.capsuleType().equals(CapsuleType.PUBLIC));
assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
softly.assertThat(capsules).isNotEmpty();
softly.assertThat(capsules).allMatch(c -> friendCapsuleIds.contains(c.id()));
softly.assertThat(capsules).allMatch(c -> c.capsuleType().equals(CapsuleType.PUBLIC));
softly.assertThat(capsules).allMatch(c -> mbr.contains(c.point()));
});
}
}
Loading