From 541a45864682a8f4da696c32959c4bc8f95421ba Mon Sep 17 00:00:00 2001 From: hong seokho Date: Tue, 21 May 2024 08:04:19 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat=20:=20=EC=BA=A1=EC=8A=90=20=EB=B3=B4?= =?UTF-8?q?=EB=AC=BC=20=ED=83=80=EC=9E=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/capsule/entity/CapsuleType.java | 1 + .../repository/CapsuleQueryRepository.java | 18 ++++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) 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 505e9371e..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(); } From 7d62a1fbba06f55002560810002fb2910aa39372 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Tue, 21 May 2024 08:04:45 +0900 Subject: [PATCH 2/3] =?UTF-8?q?test=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CapsuleQueryRepositoryTest.java | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) 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 From e7b7a1a281abb1fe2958eefee31a241e908faf72 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sat, 25 May 2024 19:30:42 +0900 Subject: [PATCH 3/3] =?UTF-8?q?chore=20:=20.gitignore=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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