diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/MyGroupCapsuleDto.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/data/dto/CapsuleBasicInfoDto.java similarity index 68% rename from backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/MyGroupCapsuleDto.java rename to backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/data/dto/CapsuleBasicInfoDto.java index e2adb4825..fffbe3fe2 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/MyGroupCapsuleDto.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/data/dto/CapsuleBasicInfoDto.java @@ -1,11 +1,11 @@ -package site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto; +package site.timecapsulearchive.core.domain.capsule.data.dto; import java.time.ZonedDateTime; import java.util.function.Function; +import site.timecapsulearchive.core.domain.capsule.data.response.CapsuleBasicInfoResponse; import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType; -import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.MyGroupCapsuleResponse; -public record MyGroupCapsuleDto( +public record CapsuleBasicInfoDto( Long capsuleId, String skinUrl, ZonedDateTime dueDate, @@ -15,9 +15,9 @@ public record MyGroupCapsuleDto( CapsuleType capsuleType ) { - public MyGroupCapsuleResponse toResponse( + public CapsuleBasicInfoResponse toResponse( final Function singlePreSignUrlFunction) { - return MyGroupCapsuleResponse.builder() + return CapsuleBasicInfoResponse.builder() .capsuleId(capsuleId) .skinUrl(singlePreSignUrlFunction.apply(skinUrl)) .dueDate(dueDate) @@ -27,4 +27,4 @@ public MyGroupCapsuleResponse toResponse( .capsuleType(capsuleType) .build(); } -} +} \ No newline at end of file diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/response/MyGroupCapsuleResponse.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/data/response/CapsuleBasicInfoResponse.java similarity index 82% rename from backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/response/MyGroupCapsuleResponse.java rename to backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/data/response/CapsuleBasicInfoResponse.java index 256d80354..883e1c4e9 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/response/MyGroupCapsuleResponse.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/data/response/CapsuleBasicInfoResponse.java @@ -1,4 +1,4 @@ -package site.timecapsulearchive.core.domain.capsule.group_capsule.data.response; +package site.timecapsulearchive.core.domain.capsule.data.response; import io.swagger.v3.oas.annotations.media.Schema; import java.time.ZonedDateTime; @@ -7,8 +7,8 @@ import site.timecapsulearchive.core.global.common.response.ResponseMappingConstant; @Builder -@Schema(description = "사용자가 만든 그룹 캡슐") -public record MyGroupCapsuleResponse( +@Schema(description = "캡슐 기본 정보") +public record CapsuleBasicInfoResponse( @Schema(description = "캡슐 아이디") Long capsuleId, @@ -32,7 +32,7 @@ public record MyGroupCapsuleResponse( CapsuleType capsuleType ) { - public MyGroupCapsuleResponse { + public CapsuleBasicInfoResponse { if (dueDate != null) { dueDate = dueDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID); } @@ -41,4 +41,4 @@ public record MyGroupCapsuleResponse( createdAt = createdAt.withZoneSameInstant(ResponseMappingConstant.ZONE_ID); } } -} +} \ No newline at end of file diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/api/GroupCapsuleApiController.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/api/GroupCapsuleApiController.java index 43476dd14..f63841be1 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/api/GroupCapsuleApiController.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/api/GroupCapsuleApiController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleOpenStateDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleSummaryDto; @@ -124,7 +125,7 @@ public ResponseEntity> getMyGroupCapsules( @RequestParam(defaultValue = "20", value = "size") final int size, @RequestParam(value = "created_at") final ZonedDateTime createdAt ) { - final Slice groupCapsules = groupCapsuleService.findMyGroupCapsuleSlice( + final Slice groupCapsules = groupCapsuleService.findMyGroupCapsuleSlice( memberId, size, createdAt diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/response/MyGroupCapsuleSliceResponse.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/response/MyGroupCapsuleSliceResponse.java index dba16b276..41aefd50d 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/response/MyGroupCapsuleSliceResponse.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/response/MyGroupCapsuleSliceResponse.java @@ -2,19 +2,20 @@ import java.util.List; import java.util.function.Function; -import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.MyGroupCapsuleDto; +import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto; +import site.timecapsulearchive.core.domain.capsule.data.response.CapsuleBasicInfoResponse; public record MyGroupCapsuleSliceResponse( - List groupCapsules, + List groupCapsules, Boolean hasNext ) { public static MyGroupCapsuleSliceResponse createOf( - final List groupCapsules, + final List groupCapsules, final boolean hasNext, final Function singlePreSignUrlFunction ) { - List groupCapsuleResponses = groupCapsules.stream() + List groupCapsuleResponses = groupCapsules.stream() .map(capsule -> capsule.toResponse(singlePreSignUrlFunction)) .toList(); diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepository.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepository.java index 3efe95754..90c01c9d7 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepository.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepository.java @@ -17,18 +17,17 @@ import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; -import org.springframework.data.domain.SliceImpl; import org.springframework.stereotype.Repository; +import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto; import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleSummaryDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleSummaryDto; -import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.MyGroupCapsuleDto; import site.timecapsulearchive.core.domain.group.data.dto.GroupMemberSummaryDto; import site.timecapsulearchive.core.domain.member.entity.QMember; +import site.timecapsulearchive.core.global.util.SliceUtil; @Repository @RequiredArgsConstructor @@ -131,15 +130,15 @@ public Optional findGroupCapsuleSummaryDtoByCapsuleId( ).get(capsuleId)); } - public Slice findMyGroupCapsuleSlice( + public Slice findMyGroupCapsuleSlice( final Long memberId, final int size, final ZonedDateTime createdAt ) { - final List groupCapsules = jpaQueryFactory + final List groupCapsules = jpaQueryFactory .select( Projections.constructor( - MyGroupCapsuleDto.class, + CapsuleBasicInfoDto.class, capsule.id, capsuleSkin.imageUrl, capsule.dueDate, @@ -159,12 +158,7 @@ public Slice findMyGroupCapsuleSlice( .limit(size + 1) .fetch(); - final boolean hasNext = groupCapsules.size() > size; - if (hasNext) { - groupCapsules.remove(size); - } - - return new SliceImpl<>(groupCapsules, Pageable.ofSize(size), hasNext); + return SliceUtil.makeSlice(size, groupCapsules); } public boolean findGroupCapsuleExistByGroupId(Long groupId) { 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 6f6659f7f..4988f6b01 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 @@ -8,6 +8,7 @@ import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto; import site.timecapsulearchive.core.domain.capsule.entity.Capsule; import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType; import site.timecapsulearchive.core.domain.capsule.exception.CapsuleNotFondException; @@ -89,7 +90,7 @@ public GroupCapsuleSummaryDto findGroupCapsuleSummaryByGroupIDAndCapsuleId( * @param createdAt 조회를 시작할 캡슐의 생성 시간, 첫 조회라면 현재 시간, 이후 조회라면 맨 마지막 데이터의 시간 * @return 사용자가 생성한 그룹 캡슐 목록 */ - public Slice findMyGroupCapsuleSlice( + public Slice findMyGroupCapsuleSlice( final Long memberId, final int size, final ZonedDateTime createdAt diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApiController.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApiController.java index 7b3e7665e..97cd4d050 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApiController.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApiController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto; import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleSummaryDto; @@ -21,7 +22,6 @@ import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.response.CapsuleDetailResponse; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.response.CapsuleSummaryResponse; import site.timecapsulearchive.core.domain.capsule.generic_capsule.facade.CapsuleFacade; -import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.MyPublicCapsuleDto; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.MyPublicCapsuleSliceResponse; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.PublicCapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.reqeust.PublicCapsuleUpdateRequest; @@ -137,7 +137,7 @@ public ResponseEntity> getMyPublicCapsules @RequestParam(defaultValue = "20", value = "size") final int size, @RequestParam(value = "created_at") final ZonedDateTime createdAt ) { - final Slice publicCapsules = publicCapsuleService.findMyPublicCapsuleSlice( + final Slice publicCapsules = publicCapsuleService.findMyPublicCapsuleSlice( memberId, size, createdAt); return ResponseEntity.ok( diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/dto/MyPublicCapsuleDto.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/dto/MyPublicCapsuleDto.java deleted file mode 100644 index 8fe22bbc9..000000000 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/dto/MyPublicCapsuleDto.java +++ /dev/null @@ -1,30 +0,0 @@ -package site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto; - -import java.time.ZonedDateTime; -import java.util.function.Function; -import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType; -import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.MyPublicCapsuleResponse; - -public record MyPublicCapsuleDto( - Long capsuleId, - String skinUrl, - ZonedDateTime dueDate, - ZonedDateTime createdAt, - String title, - Boolean isOpened, - CapsuleType capsuleType -) { - - public MyPublicCapsuleResponse toResponse( - final Function singlePreSignUrlFunction) { - return MyPublicCapsuleResponse.builder() - .capsuleId(capsuleId) - .skinUrl(singlePreSignUrlFunction.apply(skinUrl)) - .dueDate(dueDate) - .createdAt(createdAt) - .title(title) - .isOpened(isOpened) - .capsuleType(capsuleType) - .build(); - } -} diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/dto/MyPublicCapsuleSliceResponse.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/dto/MyPublicCapsuleSliceResponse.java index a74bd4939..a05510495 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/dto/MyPublicCapsuleSliceResponse.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/dto/MyPublicCapsuleSliceResponse.java @@ -3,24 +3,25 @@ import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; import java.util.function.Function; -import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.MyPublicCapsuleResponse; +import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto; +import site.timecapsulearchive.core.domain.capsule.data.response.CapsuleBasicInfoResponse; @Schema(description = "사용자가 만든 공개 캡슐 슬라이싱") public record MyPublicCapsuleSliceResponse( @Schema(description = "사용자가 만든 공개 캡슐 정보") - List publicCapsules, + List publicCapsules, @Schema(description = "다음 페이지 유무") Boolean hasNext ) { public static MyPublicCapsuleSliceResponse createOf( - final List publicCapsules, + final List publicCapsules, final boolean hasNext, final Function singlePreSignUrlFunction ) { - List publicCapsuleResponses = publicCapsules.stream() + List publicCapsuleResponses = publicCapsules.stream() .map(capsule -> capsule.toResponse(singlePreSignUrlFunction)) .toList(); diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/response/MyPublicCapsuleResponse.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/response/MyPublicCapsuleResponse.java deleted file mode 100644 index 3dea37611..000000000 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/response/MyPublicCapsuleResponse.java +++ /dev/null @@ -1,44 +0,0 @@ -package site.timecapsulearchive.core.domain.capsule.public_capsule.data.response; - -import io.swagger.v3.oas.annotations.media.Schema; -import java.time.ZonedDateTime; -import lombok.Builder; -import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType; -import site.timecapsulearchive.core.global.common.response.ResponseMappingConstant; - -@Builder -@Schema(description = "사용자가 만든 공개 캡슐") -public record MyPublicCapsuleResponse( - - @Schema(description = "캡슐 아이디") - Long capsuleId, - - @Schema(description = "스킨 url") - String skinUrl, - - @Schema(description = "개봉일") - ZonedDateTime dueDate, - - @Schema(description = "생성일") - ZonedDateTime createdAt, - - @Schema(description = "제목") - String title, - - @Schema(description = "캡슐 개봉 여부") - Boolean isOpened, - - @Schema(description = "캡슐 타입") - CapsuleType capsuleType -) { - - public MyPublicCapsuleResponse { - if (dueDate != null) { - dueDate = dueDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID); - } - - if (createdAt != null) { - createdAt = createdAt.withZoneSameInstant(ResponseMappingConstant.ZONE_ID); - } - } -} diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java index 980a5caac..b9aa3f28b 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java @@ -19,11 +19,12 @@ import org.springframework.data.domain.Slice; import org.springframework.data.domain.SliceImpl; import org.springframework.stereotype.Repository; +import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto; import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleSummaryDto; -import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.MyPublicCapsuleDto; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.PublicCapsuleDetailDto; +import site.timecapsulearchive.core.global.util.SliceUtil; @Repository @RequiredArgsConstructor @@ -158,28 +159,22 @@ public Slice findPublicCapsulesDtoMadeByFriend( .limit(size + 1) .fetch(); - final boolean hasNext = canMoreRead(size, publicCapsuleDetailDtos.size()); - if (hasNext) { - publicCapsuleDetailDtos.remove(size); - } - - return new SliceImpl<>(publicCapsuleDetailDtos, Pageable.ofSize(size), hasNext); - + return SliceUtil.makeSlice(size, publicCapsuleDetailDtos); } private boolean canMoreRead(final int size, final int capsuleSize) { return capsuleSize > size; } - public Slice findMyPublicCapsuleSlice( + public Slice findMyPublicCapsuleSlice( final Long memberId, final int size, final ZonedDateTime createdAt ) { - final List publicCapsules = jpaQueryFactory + final List publicCapsules = jpaQueryFactory .select( Projections.constructor( - MyPublicCapsuleDto.class, + CapsuleBasicInfoDto.class, capsule.id, capsuleSkin.imageUrl, capsule.dueDate, @@ -199,11 +194,6 @@ public Slice findMyPublicCapsuleSlice( .limit(size + 1) .fetch(); - final boolean hasNext = publicCapsules.size() > size; - if (hasNext) { - publicCapsules.remove(size); - } - - return new SliceImpl<>(publicCapsules, Pageable.ofSize(size), hasNext); + return SliceUtil.makeSlice(size, publicCapsules); } } diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleService.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleService.java index e58b91da6..75293a823 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleService.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleService.java @@ -6,10 +6,10 @@ import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto; import site.timecapsulearchive.core.domain.capsule.exception.CapsuleNotFondException; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleSummaryDto; -import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.MyPublicCapsuleDto; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.PublicCapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.public_capsule.repository.PublicCapsuleQueryRepository; @@ -70,7 +70,7 @@ public Slice findPublicCapsulesMadeByFriend( * @param createdAt 조회를 시작할 캡슐의 생성 시간, 첫 조회라면 현재 시간, 이후 조회라면 맨 마지막 데이터의 시간 * @return 사용자가 생성한 공개 캡슐 목록 */ - public Slice findMyPublicCapsuleSlice( + public Slice findMyPublicCapsuleSlice( final Long memberId, final int size, final ZonedDateTime createdAt diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/api/SecretCapsuleApiController.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/api/SecretCapsuleApiController.java index 15458cde6..5ea1bddb2 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/api/SecretCapsuleApiController.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/api/SecretCapsuleApiController.java @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto; import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleSummaryDto; @@ -22,7 +23,6 @@ import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.response.CapsuleDetailResponse; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.response.CapsuleSummaryResponse; import site.timecapsulearchive.core.domain.capsule.generic_capsule.facade.CapsuleFacade; -import site.timecapsulearchive.core.domain.capsule.secret_capsule.data.dto.MySecreteCapsuleDto; import site.timecapsulearchive.core.domain.capsule.secret_capsule.data.reqeust.SecretCapsuleUpdateRequest; import site.timecapsulearchive.core.domain.capsule.secret_capsule.data.response.MySecretCapsuleSliceResponse; import site.timecapsulearchive.core.domain.capsule.secret_capsule.service.SecretCapsuleService; @@ -64,7 +64,7 @@ public ResponseEntity> getMySecretCapsules @RequestParam(defaultValue = "20", value = "size") final int size, @RequestParam(defaultValue = "0", value = "created_at") final ZonedDateTime createdAt ) { - final Slice dtos = secretCapsuleService.findSecretCapsuleSliceByMemberId( + final Slice dtos = secretCapsuleService.findSecretCapsuleSliceByMemberId( memberId, size, createdAt); return ResponseEntity.ok( diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/data/dto/MySecreteCapsuleDto.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/data/dto/MySecreteCapsuleDto.java deleted file mode 100644 index 19d661802..000000000 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/data/dto/MySecreteCapsuleDto.java +++ /dev/null @@ -1,32 +0,0 @@ -package site.timecapsulearchive.core.domain.capsule.secret_capsule.data.dto; - -import java.time.ZonedDateTime; -import java.util.function.Function; -import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType; -import site.timecapsulearchive.core.domain.capsule.secret_capsule.data.response.MySecreteCapsuleResponse; - -public record MySecreteCapsuleDto( - Long capsuleId, - String skinUrl, - ZonedDateTime dueDate, - ZonedDateTime createdAt, - String title, - Boolean isOpened, - CapsuleType type -) { - - public MySecreteCapsuleResponse toResponse( - final Function preSignUrlFunction - ) { - return MySecreteCapsuleResponse.builder() - .capsuleId(capsuleId) - .SkinUrl(preSignUrlFunction.apply(skinUrl)) - .dueDate(dueDate) - .createdAt(createdAt) - .title(title) - .isOpened(isOpened) - .type(type) - .build(); - } - -} diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/data/response/MySecretCapsuleSliceResponse.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/data/response/MySecretCapsuleSliceResponse.java index f2ecc413d..15e626d9d 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/data/response/MySecretCapsuleSliceResponse.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/data/response/MySecretCapsuleSliceResponse.java @@ -4,23 +4,24 @@ import java.util.List; import java.util.function.Function; import org.springframework.data.domain.Slice; -import site.timecapsulearchive.core.domain.capsule.secret_capsule.data.dto.MySecreteCapsuleDto; +import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto; +import site.timecapsulearchive.core.domain.capsule.data.response.CapsuleBasicInfoResponse; @Schema(description = "내가 생성한 비밀 캡슐 목록 응답") public record MySecretCapsuleSliceResponse( @Schema(description = "내 비밀 캡슐 리스트") - List capsules, + List capsules, @Schema(description = "다음 페이지 유무") Boolean hasNext ) { public static MySecretCapsuleSliceResponse createOf( - final Slice dtos, + final Slice dtos, final Function preSignUrlFunction ) { - final List capsules = dtos.getContent(). + final List capsules = dtos.getContent(). stream() .map(dto -> dto.toResponse(preSignUrlFunction)) .toList(); diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/data/response/MySecreteCapsuleResponse.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/data/response/MySecreteCapsuleResponse.java deleted file mode 100644 index 15314fed7..000000000 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/data/response/MySecreteCapsuleResponse.java +++ /dev/null @@ -1,43 +0,0 @@ -package site.timecapsulearchive.core.domain.capsule.secret_capsule.data.response; - -import io.swagger.v3.oas.annotations.media.Schema; -import java.time.ZonedDateTime; -import lombok.Builder; -import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType; -import site.timecapsulearchive.core.global.common.response.ResponseMappingConstant; - -@Builder -@Schema(description = "내 비밀 캡슐 응답") -public record MySecreteCapsuleResponse( - @Schema(description = "비밀 캡슐 아이디") - Long capsuleId, - - @Schema(description = "캡슐 스킨 url") - String SkinUrl, - - @Schema(description = "내 비밀 캡슐 만료일") - ZonedDateTime dueDate, - - @Schema(description = "내 비밀 캡슐 생성일") - ZonedDateTime createdAt, - - @Schema(description = "내 비밀 캡슐 제목") - String title, - - @Schema(description = "내 비밀 캡슐 오픈 여부") - Boolean isOpened, - - @Schema(description = "내 비밀 캡슐 타입") - CapsuleType type -) { - - public MySecreteCapsuleResponse { - if (dueDate != null) { - dueDate = dueDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID); - } - - if (createdAt != null) { - createdAt = createdAt.withZoneSameInstant(ResponseMappingConstant.ZONE_ID); - } - } -} diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/repository/SecretCapsuleQueryRepository.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/repository/SecretCapsuleQueryRepository.java index 99490a193..fff856330 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/repository/SecretCapsuleQueryRepository.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/repository/SecretCapsuleQueryRepository.java @@ -14,14 +14,13 @@ import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; -import org.springframework.data.domain.SliceImpl; import org.springframework.stereotype.Repository; +import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto; import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleSummaryDto; -import site.timecapsulearchive.core.domain.capsule.secret_capsule.data.dto.MySecreteCapsuleDto; +import site.timecapsulearchive.core.global.util.SliceUtil; @Repository @RequiredArgsConstructor @@ -104,32 +103,15 @@ private StringExpression groupConcatDistinct(final StringExpression expression) return Expressions.stringTemplate("GROUP_CONCAT(DISTINCT {0})", expression); } - public Slice findSecretCapsuleSliceByMemberIdAndCreatedAt( + public Slice findSecretCapsuleSliceByMemberIdAndCreatedAt( final Long memberId, final int size, final ZonedDateTime createdAt ) { - final List mySecretCapsules = findMySecretCapsuleDtosByMemberIdAndCreatedAt( - memberId, size, createdAt - ); - - final boolean hasNext = canMoreRead(size, mySecretCapsules.size()); - if (hasNext) { - mySecretCapsules.remove(size); - } - - return new SliceImpl<>(mySecretCapsules, Pageable.ofSize(size), hasNext); - } - - private List findMySecretCapsuleDtosByMemberIdAndCreatedAt( - final Long memberId, - final int size, - final ZonedDateTime createdAt - ) { - return jpaQueryFactory + final List mySecretCapsules = jpaQueryFactory .select( Projections.constructor( - MySecreteCapsuleDto.class, + CapsuleBasicInfoDto.class, capsule.id, capsuleSkin.imageUrl, capsule.dueDate, @@ -149,9 +131,7 @@ private List findMySecretCapsuleDtosByMemberIdAndCreatedAt( .orderBy(capsule.id.desc()) .limit(size + 1) .fetch(); - } - private boolean canMoreRead(final int size, final int capsuleSize) { - return capsuleSize > size; + return SliceUtil.makeSlice(size, mySecretCapsules); } } \ No newline at end of file diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/service/SecretCapsuleService.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/service/SecretCapsuleService.java index 87182171f..62e5acd51 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/service/SecretCapsuleService.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/secret_capsule/service/SecretCapsuleService.java @@ -6,10 +6,10 @@ import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto; import site.timecapsulearchive.core.domain.capsule.exception.CapsuleNotFondException; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleSummaryDto; -import site.timecapsulearchive.core.domain.capsule.secret_capsule.data.dto.MySecreteCapsuleDto; import site.timecapsulearchive.core.domain.capsule.secret_capsule.repository.SecretCapsuleQueryRepository; @Service @@ -27,7 +27,7 @@ public class SecretCapsuleService { * @param createdAt 마지막 캡슐 생성 날짜 * @return 내 페이지에서 비밀 캡슐을 조회한다. */ - public Slice findSecretCapsuleSliceByMemberId( + public Slice findSecretCapsuleSliceByMemberId( final Long memberId, final int size, final ZonedDateTime createdAt diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java index 0ed08cdf1..0e1aab206 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java @@ -22,6 +22,7 @@ import site.timecapsulearchive.core.common.fixture.domain.GroupFixture; import site.timecapsulearchive.core.common.fixture.domain.MemberFixture; import site.timecapsulearchive.core.common.fixture.domain.MemberGroupFixture; +import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto; import site.timecapsulearchive.core.domain.capsule.entity.Capsule; import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType; import site.timecapsulearchive.core.domain.capsule.entity.GroupCapsuleOpen; @@ -29,7 +30,6 @@ import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleSummaryDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleSummaryDto; -import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.MyGroupCapsuleDto; import site.timecapsulearchive.core.domain.capsuleskin.entity.CapsuleSkin; import site.timecapsulearchive.core.domain.group.data.dto.GroupMemberSummaryDto; import site.timecapsulearchive.core.domain.group.entity.Group; @@ -187,15 +187,14 @@ void setup(@Autowired EntityManager entityManager) { ZonedDateTime now = ZonedDateTime.now().plusDays(1); //when - Slice groupCapsules = groupCapsuleQueryRepository.findMyGroupCapsuleSlice( + Slice groupCapsules = groupCapsuleQueryRepository.findMyGroupCapsuleSlice( groupLeaderId, size, now); //then SoftAssertions.assertSoftly(softly -> { assertThat(groupCapsules.hasContent()).isTrue(); - assertThat(groupCapsules).allMatch( - capsule -> capsule.capsuleType().equals(CapsuleType.GROUP)); - assertThat(groupCapsules).allMatch(capsule -> capsule.createdAt().isBefore(now)); + assertThat(groupCapsules).allMatch(c-> c.capsuleType().equals(CapsuleType.GROUP)); + assertThat(groupCapsules).allMatch(c -> c.createdAt().isBefore(now)); }); } } \ No newline at end of file diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepositoryTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepositoryTest.java index 3181f65e8..bdab3a023 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepositoryTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepositoryTest.java @@ -19,11 +19,11 @@ import site.timecapsulearchive.core.common.fixture.domain.CapsuleSkinFixture; import site.timecapsulearchive.core.common.fixture.domain.MemberFixture; import site.timecapsulearchive.core.common.fixture.domain.MemberFriendFixture; +import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto; import site.timecapsulearchive.core.domain.capsule.entity.Capsule; import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleSummaryDto; -import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.MyPublicCapsuleDto; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.PublicCapsuleDetailDto; import site.timecapsulearchive.core.domain.capsuleskin.entity.CapsuleSkin; import site.timecapsulearchive.core.domain.friend.entity.MemberFriend; @@ -193,7 +193,7 @@ void setup(@Autowired EntityManager entityManager) { ZonedDateTime now = ZonedDateTime.now().plusDays(1); //when - Slice publicCapsules = publicCapsuleQueryRepository.findMyPublicCapsuleSlice( + Slice publicCapsules = publicCapsuleQueryRepository.findMyPublicCapsuleSlice( memberId, size, now); //then