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

fix : 그룹 캡슐 개봉 로직 수정 #483 #486

Merged
merged 3 commits into from
Jun 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -120,26 +119,24 @@ 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) {
if (groupCapsuleOpens.isEmpty()) {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
Original file line number Diff line number Diff line change
@@ -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
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

Expand All @@ -257,6 +258,7 @@ class GroupCapsuleServiceTest {
softly.assertThat(groupCapsule.get().getIsOpened()).isTrue();
softly.assertThat(groupCapsuleOpenStateDto.capsuleOpenStatus())
.isEqualTo(CapsuleOpenStatus.OPEN);
softly.assertThat(groupCapsuleOpenStateDto.isIndividuallyOpened()).isTrue();
});
}

Expand All @@ -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();
});
}

Expand All @@ -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();
});
}

Expand Down Expand Up @@ -341,6 +345,7 @@ class GroupCapsuleServiceTest {
softly.assertThat(groupCapsule.get().getIsOpened()).isTrue();
softly.assertThat(groupCapsuleOpenStateDto.capsuleOpenStatus()).isEqualTo(
CapsuleOpenStatus.OPEN);
softly.assertThat(groupCapsuleOpenStateDto.isIndividuallyOpened()).isTrue();
});
}

Expand All @@ -364,6 +369,7 @@ class GroupCapsuleServiceTest {
softly.assertThat(groupCapsule.get().getIsOpened()).isTrue();
softly.assertThat(groupCapsuleOpenStateDto.capsuleOpenStatus()).isEqualTo(
CapsuleOpenStatus.OPEN);
softly.assertThat(groupCapsuleOpenStateDto.isIndividuallyOpened()).isTrue();
});
}

Expand Down
Loading