From c514fc4c91d077c25384e84440c8397482776a31 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sun, 9 Jun 2024 09:03:36 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix=20:=20=EA=B7=B8=EB=A3=B9=20=EC=BA=A1?= =?UTF-8?q?=EC=8A=90=20=EA=B0=9C=EB=B4=89=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - allMatch의 단축 평가때문에 for loop으로 수정 --- .../core/domain/capsule/entity/Capsule.java | 25 ++++++++----------- .../data/dto/GroupCapsuleOpenStateDto.java | 12 +++++---- .../GroupCapsuleOpenStateResponse.java | 11 +++++++- .../service/GroupCapsuleService.java | 8 +++--- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/entity/Capsule.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/entity/Capsule.java index 833fc102e..31da14e9b 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/entity/Capsule.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/entity/Capsule.java @@ -14,7 +14,6 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; -import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; @@ -120,12 +119,8 @@ public void open() { this.isOpened = Boolean.TRUE; } - public boolean isTimeCapsule() { - return dueDate != null; - } - - public boolean canOpen() { - return dueDate == null || dueDate.isBefore(ZonedDateTimeSupplier.utc().get()); + public boolean isNotTimeCapsule() { + return dueDate == null; } public boolean isAllGroupMemberOpened(Long memberId, Long capsuleId) { @@ -133,13 +128,15 @@ public boolean isAllGroupMemberOpened(Long memberId, Long capsuleId) { throw new GroupCapsuleOpenNotFoundException(); } - return groupCapsuleOpens.stream() - .allMatch(groupCapsuleOpen -> { - if (groupCapsuleOpen.matched(capsuleId, memberId)) { - groupCapsuleOpen.open(); - } + boolean isCapsuleOpened = true; + for (GroupCapsuleOpen groupCapsuleOpen : groupCapsuleOpens) { + if (groupCapsuleOpen.matched(capsuleId, memberId)) { + groupCapsuleOpen.open(); + } + + isCapsuleOpened = isCapsuleOpened && groupCapsuleOpen.getIsOpened(); + } - return groupCapsuleOpen.getIsOpened(); - }); + return isCapsuleOpened; } } \ No newline at end of file diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/GroupCapsuleOpenStateDto.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/GroupCapsuleOpenStateDto.java index 56fd18e2a..38d57c2d0 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/GroupCapsuleOpenStateDto.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/GroupCapsuleOpenStateDto.java @@ -3,21 +3,23 @@ import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleOpenStateResponse; public record GroupCapsuleOpenStateDto( - CapsuleOpenStatus capsuleOpenStatus + CapsuleOpenStatus capsuleOpenStatus, + boolean isIndividuallyOpened ) { public static GroupCapsuleOpenStateDto opened() { - return new GroupCapsuleOpenStateDto(CapsuleOpenStatus.OPEN); + return new GroupCapsuleOpenStateDto(CapsuleOpenStatus.OPEN, true); } - public static GroupCapsuleOpenStateDto notOpened() { - return new GroupCapsuleOpenStateDto(CapsuleOpenStatus.NOT_OPEN); + public static GroupCapsuleOpenStateDto notOpened(boolean isIndividuallyOpened) { + return new GroupCapsuleOpenStateDto(CapsuleOpenStatus.NOT_OPEN, isIndividuallyOpened); } public GroupCapsuleOpenStateResponse toResponse() { return new GroupCapsuleOpenStateResponse( capsuleOpenStatus, - capsuleOpenStatus.getStatusMessage() + capsuleOpenStatus.getStatusMessage(), + isIndividuallyOpened ); } } diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/response/GroupCapsuleOpenStateResponse.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/response/GroupCapsuleOpenStateResponse.java index e77ec5c3a..cd67440eb 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/response/GroupCapsuleOpenStateResponse.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/response/GroupCapsuleOpenStateResponse.java @@ -1,10 +1,19 @@ package site.timecapsulearchive.core.domain.capsule.group_capsule.data.response; +import io.swagger.v3.oas.annotations.media.Schema; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.CapsuleOpenStatus; +@Schema(description = "그룹 캡슐 개봉 상태 응답") public record GroupCapsuleOpenStateResponse( + + @Schema(description = "캡슐 개봉 상태") CapsuleOpenStatus capsuleOpenStatus, - String statusMessage + + @Schema(description = "캡슐 개봉 상태 메시지") + String statusMessage, + + @Schema(description = "현재 요청한 사용자의 개별적인 캡슐 개봉 상태") + boolean isIndividuallyOpened ) { } diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleService.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleService.java index d7123fe1c..0638c41ab 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleService.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleService.java @@ -102,18 +102,18 @@ public GroupCapsuleOpenStateDto openGroupCapsule(final Long memberId, final Long capsuleId) .orElseThrow(CapsuleNotFondException::new); - if (!groupCapsule.canOpen()) { - return GroupCapsuleOpenStateDto.notOpened(); + if (groupCapsule.isNotCapsuleOpened()) { + return GroupCapsuleOpenStateDto.notOpened(false); } - if (!groupCapsule.isTimeCapsule()) { + if (groupCapsule.isNotTimeCapsule()) { groupCapsule.open(); return GroupCapsuleOpenStateDto.opened(); } boolean allGroupMemberOpened = groupCapsule.isAllGroupMemberOpened(memberId, capsuleId); if (!allGroupMemberOpened) { - return GroupCapsuleOpenStateDto.notOpened(); + return GroupCapsuleOpenStateDto.notOpened(true); } groupCapsule.open(); From 82bf626590d77f1183c039f2412929be4ef0b32d Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sun, 9 Jun 2024 09:04:00 +0900 Subject: [PATCH 2/2] =?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 --- .../group_capsule/service/GroupCapsuleServiceTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleServiceTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleServiceTest.java index 31e5d2ca5..24793e1e8 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleServiceTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleServiceTest.java @@ -224,6 +224,7 @@ class GroupCapsuleServiceTest { softly.assertThat(groupCapsule.get().getIsOpened()).isFalse(); softly.assertThat(groupCapsuleOpenStateDto.capsuleOpenStatus()) .isEqualTo(CapsuleOpenStatus.NOT_OPEN); + softly.assertThat(groupCapsuleOpenStateDto.isIndividuallyOpened()).isFalse(); }); } @@ -244,6 +245,7 @@ class GroupCapsuleServiceTest { softly.assertThat(groupCapsule.get().getIsOpened()).isTrue(); softly.assertThat(groupCapsuleOpenStateDto.capsuleOpenStatus()) .isEqualTo(CapsuleOpenStatus.OPEN); + softly.assertThat(groupCapsuleOpenStateDto.isIndividuallyOpened()).isTrue(); }); } @@ -266,6 +268,7 @@ class GroupCapsuleServiceTest { softly.assertThat(groupCapsule.get().getIsOpened()).isFalse(); softly.assertThat(groupCapsuleOpenStateDto.capsuleOpenStatus()).isEqualTo( CapsuleOpenStatus.NOT_OPEN); + softly.assertThat(groupCapsuleOpenStateDto.isIndividuallyOpened()).isTrue(); }); } @@ -288,6 +291,7 @@ class GroupCapsuleServiceTest { softly.assertThat(groupCapsule.get().getIsOpened()).isFalse(); softly.assertThat(groupCapsuleOpenStateDto.capsuleOpenStatus()).isEqualTo( CapsuleOpenStatus.NOT_OPEN); + softly.assertThat(groupCapsuleOpenStateDto.isIndividuallyOpened()).isTrue(); }); } @@ -324,6 +328,7 @@ class GroupCapsuleServiceTest { softly.assertThat(groupCapsule.get().getIsOpened()).isTrue(); softly.assertThat(groupCapsuleOpenStateDto.capsuleOpenStatus()).isEqualTo( CapsuleOpenStatus.OPEN); + softly.assertThat(groupCapsuleOpenStateDto.isIndividuallyOpened()).isTrue(); }); } @@ -346,6 +351,7 @@ class GroupCapsuleServiceTest { softly.assertThat(groupCapsule.get().getIsOpened()).isTrue(); softly.assertThat(groupCapsuleOpenStateDto.capsuleOpenStatus()).isEqualTo( CapsuleOpenStatus.OPEN); + softly.assertThat(groupCapsuleOpenStateDto.isIndividuallyOpened()).isTrue(); }); } }