diff --git a/.gitignore b/.gitignore index 723ef36f4..91cd78597 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -.idea \ No newline at end of file +.idea + +data \ No newline at end of file diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/entity/CapsuleType.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/entity/CapsuleType.java index e3b8b14be..0f6dc063a 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/entity/CapsuleType.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/entity/CapsuleType.java @@ -4,5 +4,6 @@ public enum CapsuleType { SECRET, PUBLIC, GROUP, + TREASURE, ALL } diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/generic_capsule/repository/CapsuleQueryRepository.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/generic_capsule/repository/CapsuleQueryRepository.java index 889c02f6d..700a7d637 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/generic_capsule/repository/CapsuleQueryRepository.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/generic_capsule/repository/CapsuleQueryRepository.java @@ -55,17 +55,16 @@ public List 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)); + }; } /** @@ -93,8 +92,7 @@ public List 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(); } diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/generic_capsule/repository/CapsuleQueryRepositoryTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/generic_capsule/repository/CapsuleQueryRepositoryTest.java index f3d6a84fd..f4fa3bec4 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/generic_capsule/repository/CapsuleQueryRepositoryTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/generic_capsule/repository/CapsuleQueryRepositoryTest.java @@ -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; @@ -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())); }); } @@ -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())); }); } @@ -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())); }); } @@ -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())); }); } @@ -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())); }); } @@ -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())); }); } @@ -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())); }); } @@ -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())); }); } } \ No newline at end of file