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 4988f6b01..8ec2d1635 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 @@ -111,18 +111,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(); 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 4d9721f51..ab6a2e991 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 @@ -236,6 +236,7 @@ class GroupCapsuleServiceTest { softly.assertThat(groupCapsule.get().getIsOpened()).isFalse(); softly.assertThat(groupCapsuleOpenStateDto.capsuleOpenStatus()) .isEqualTo(CapsuleOpenStatus.NOT_OPEN); + softly.assertThat(groupCapsuleOpenStateDto.isIndividuallyOpened()).isFalse(); }); } @@ -257,6 +258,7 @@ class GroupCapsuleServiceTest { softly.assertThat(groupCapsule.get().getIsOpened()).isTrue(); softly.assertThat(groupCapsuleOpenStateDto.capsuleOpenStatus()) .isEqualTo(CapsuleOpenStatus.OPEN); + softly.assertThat(groupCapsuleOpenStateDto.isIndividuallyOpened()).isTrue(); }); } @@ -280,6 +282,7 @@ class GroupCapsuleServiceTest { softly.assertThat(groupCapsule.get().getIsOpened()).isFalse(); softly.assertThat(groupCapsuleOpenStateDto.capsuleOpenStatus()).isEqualTo( CapsuleOpenStatus.NOT_OPEN); + softly.assertThat(groupCapsuleOpenStateDto.isIndividuallyOpened()).isTrue(); }); } @@ -303,6 +306,7 @@ class GroupCapsuleServiceTest { softly.assertThat(groupCapsule.get().getIsOpened()).isFalse(); softly.assertThat(groupCapsuleOpenStateDto.capsuleOpenStatus()).isEqualTo( CapsuleOpenStatus.NOT_OPEN); + softly.assertThat(groupCapsuleOpenStateDto.isIndividuallyOpened()).isTrue(); }); } @@ -341,6 +345,7 @@ class GroupCapsuleServiceTest { softly.assertThat(groupCapsule.get().getIsOpened()).isTrue(); softly.assertThat(groupCapsuleOpenStateDto.capsuleOpenStatus()).isEqualTo( CapsuleOpenStatus.OPEN); + softly.assertThat(groupCapsuleOpenStateDto.isIndividuallyOpened()).isTrue(); }); } @@ -364,6 +369,7 @@ class GroupCapsuleServiceTest { softly.assertThat(groupCapsule.get().getIsOpened()).isTrue(); softly.assertThat(groupCapsuleOpenStateDto.capsuleOpenStatus()).isEqualTo( CapsuleOpenStatus.OPEN); + softly.assertThat(groupCapsuleOpenStateDto.isIndividuallyOpened()).isTrue(); }); }