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

refact : 캡슐 공통 dto, response 통일 #480

Closed
wants to merge 6 commits into from
Closed
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
@@ -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,
Expand All @@ -15,9 +15,9 @@ public record MyGroupCapsuleDto(
CapsuleType capsuleType
) {

public MyGroupCapsuleResponse toResponse(
public CapsuleBasicInfoResponse toResponse(
final Function<String, String> singlePreSignUrlFunction) {
return MyGroupCapsuleResponse.builder()
return CapsuleBasicInfoResponse.builder()
.capsuleId(capsuleId)
.skinUrl(singlePreSignUrlFunction.apply(skinUrl))
.dueDate(dueDate)
Expand All @@ -27,4 +27,4 @@ public MyGroupCapsuleResponse toResponse(
.capsuleType(capsuleType)
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand All @@ -32,7 +32,7 @@ public record MyGroupCapsuleResponse(
CapsuleType capsuleType
) {

public MyGroupCapsuleResponse {
public CapsuleBasicInfoResponse {
if (dueDate != null) {
dueDate = dueDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}
Expand All @@ -41,4 +41,4 @@ public record MyGroupCapsuleResponse(
createdAt = createdAt.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,7 @@ public Slice<MyGroupCapsuleDto> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
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;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.request.CapsuleCreateRequest;
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;
Expand Down Expand Up @@ -137,7 +137,7 @@ public ResponseEntity<ApiSpec<MyPublicCapsuleSliceResponse>> getMyPublicCapsules
@RequestParam(defaultValue = "20", value = "size") final int size,
@RequestParam(value = "created_at") final ZonedDateTime createdAt
) {
final Slice<MyPublicCapsuleDto> publicCapsules = publicCapsuleService.findMyPublicCapsuleSlice(
final Slice<CapsuleBasicInfoDto> publicCapsules = publicCapsuleService.findMyPublicCapsuleSlice(
memberId, size, createdAt);

return ResponseEntity.ok(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<MyPublicCapsuleResponse> publicCapsules,
List<CapsuleBasicInfoResponse> publicCapsules,

@Schema(description = "다음 페이지 유무")
Boolean hasNext
) {

public static MyPublicCapsuleSliceResponse createOf(
final List<MyPublicCapsuleDto> publicCapsules,
final List<CapsuleBasicInfoDto> publicCapsules,
final boolean hasNext,
final Function<String, String> singlePreSignUrlFunction
) {
List<MyPublicCapsuleResponse> publicCapsuleResponses = publicCapsules.stream()
List<CapsuleBasicInfoResponse> publicCapsuleResponses = publicCapsules.stream()
.map(capsule -> capsule.toResponse(singlePreSignUrlFunction))
.toList();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -158,28 +159,22 @@ public Slice<PublicCapsuleDetailDto> 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<MyPublicCapsuleDto> findMyPublicCapsuleSlice(
public Slice<CapsuleBasicInfoDto> findMyPublicCapsuleSlice(
final Long memberId,
final int size,
final ZonedDateTime createdAt
) {
final List<MyPublicCapsuleDto> publicCapsules = jpaQueryFactory
final List<CapsuleBasicInfoDto> publicCapsules = jpaQueryFactory
.select(
Projections.constructor(
MyPublicCapsuleDto.class,
CapsuleBasicInfoDto.class,
capsule.id,
capsuleSkin.imageUrl,
capsule.dueDate,
Expand All @@ -199,11 +194,6 @@ public Slice<MyPublicCapsuleDto> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -70,7 +70,7 @@ public Slice<PublicCapsuleDetailDto> findPublicCapsulesMadeByFriend(
* @param createdAt 조회를 시작할 캡슐의 생성 시간, 첫 조회라면 현재 시간, 이후 조회라면 맨 마지막 데이터의 시간
* @return 사용자가 생성한 공개 캡슐 목록
*/
public Slice<MyPublicCapsuleDto> findMyPublicCapsuleSlice(
public Slice<CapsuleBasicInfoDto> findMyPublicCapsuleSlice(
final Long memberId,
final int size,
final ZonedDateTime createdAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
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;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.request.CapsuleCreateRequest;
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;
Expand Down Expand Up @@ -64,7 +64,7 @@ public ResponseEntity<ApiSpec<MySecretCapsuleSliceResponse>> getMySecretCapsules
@RequestParam(defaultValue = "20", value = "size") final int size,
@RequestParam(defaultValue = "0", value = "created_at") final ZonedDateTime createdAt
) {
final Slice<MySecreteCapsuleDto> dtos = secretCapsuleService.findSecretCapsuleSliceByMemberId(
final Slice<CapsuleBasicInfoDto> dtos = secretCapsuleService.findSecretCapsuleSliceByMemberId(
memberId, size, createdAt);

return ResponseEntity.ok(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<MySecreteCapsuleResponse> capsules,
List<CapsuleBasicInfoResponse> capsules,

@Schema(description = "다음 페이지 유무")
Boolean hasNext
) {

public static MySecretCapsuleSliceResponse createOf(
final Slice<MySecreteCapsuleDto> dtos,
final Slice<CapsuleBasicInfoDto> dtos,
final Function<String, String> preSignUrlFunction
) {
final List<MySecreteCapsuleResponse> capsules = dtos.getContent().
final List<CapsuleBasicInfoResponse> capsules = dtos.getContent().
stream()
.map(dto -> dto.toResponse(preSignUrlFunction))
.toList();
Expand Down
Loading
Loading