Skip to content

Commit

Permalink
Revert "refact : 캡슐 공통 dto, response 통일 #479"
Browse files Browse the repository at this point in the history
  • Loading branch information
seokho-1116 authored Jun 10, 2024
1 parent 889f189 commit e8118e7
Show file tree
Hide file tree
Showing 20 changed files with 246 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
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;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.MyGroupCapsuleDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.reqeust.GroupCapsuleCreateRequest;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.reqeust.GroupCapsuleUpdateRequest;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleDetailResponse;
Expand Down Expand Up @@ -121,7 +121,7 @@ public ResponseEntity<ApiSpec<MyGroupCapsuleSliceResponse>> getMyGroupCapsules(
@RequestParam(defaultValue = "20", value = "size") final int size,
@RequestParam(value = "created_at") final ZonedDateTime createdAt
) {
final Slice<CapsuleBasicInfoDto> groupCapsules = groupCapsuleService.findMyGroupCapsuleSlice(
final Slice<MyGroupCapsuleDto> groupCapsules = groupCapsuleService.findMyGroupCapsuleSlice(
memberId,
size,
createdAt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package site.timecapsulearchive.core.domain.capsule.data.dto;
package site.timecapsulearchive.core.domain.capsule.group_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 CapsuleBasicInfoDto(
public record MyGroupCapsuleDto(
Long capsuleId,
String skinUrl,
ZonedDateTime dueDate,
Expand All @@ -15,9 +15,9 @@ public record CapsuleBasicInfoDto(
CapsuleType capsuleType
) {

public CapsuleBasicInfoResponse toResponse(
public MyGroupCapsuleResponse toResponse(
final Function<String, String> singlePreSignUrlFunction) {
return CapsuleBasicInfoResponse.builder()
return MyGroupCapsuleResponse.builder()
.capsuleId(capsuleId)
.skinUrl(singlePreSignUrlFunction.apply(skinUrl))
.dueDate(dueDate)
Expand All @@ -27,4 +27,4 @@ public CapsuleBasicInfoResponse toResponse(
.capsuleType(capsuleType)
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.core.domain.capsule.data.response;
package site.timecapsulearchive.core.domain.capsule.group_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 CapsuleBasicInfoResponse(
@Schema(description = "사용자가 만든 그룹 캡슐")
public record MyGroupCapsuleResponse(

@Schema(description = "캡슐 아이디")
Long capsuleId,
Expand All @@ -32,7 +32,7 @@ public record CapsuleBasicInfoResponse(
CapsuleType capsuleType
) {

public CapsuleBasicInfoResponse {
public MyGroupCapsuleResponse {
if (dueDate != null) {
dueDate = dueDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}
Expand All @@ -41,4 +41,4 @@ public record CapsuleBasicInfoResponse(
createdAt = createdAt.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

import java.util.List;
import java.util.function.Function;
import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto;
import site.timecapsulearchive.core.domain.capsule.data.response.CapsuleBasicInfoResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.MyGroupCapsuleDto;

public record MyGroupCapsuleSliceResponse(
List<CapsuleBasicInfoResponse> groupCapsules,
List<MyGroupCapsuleResponse> groupCapsules,
Boolean hasNext
) {

public static MyGroupCapsuleSliceResponse createOf(
final List<CapsuleBasicInfoDto> groupCapsules,
final List<MyGroupCapsuleDto> groupCapsules,
final boolean hasNext,
final Function<String, String> singlePreSignUrlFunction
) {
List<CapsuleBasicInfoResponse> groupCapsuleResponses = groupCapsules.stream()
List<MyGroupCapsuleResponse> groupCapsuleResponses = groupCapsules.stream()
.map(capsule -> capsule.toResponse(singlePreSignUrlFunction))
.toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
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
Expand Down Expand Up @@ -130,15 +131,15 @@ public Optional<GroupCapsuleSummaryDto> findGroupCapsuleSummaryDtoByCapsuleId(
).get(capsuleId));
}

public Slice<CapsuleBasicInfoDto> findMyGroupCapsuleSlice(
public Slice<MyGroupCapsuleDto> findMyGroupCapsuleSlice(
final Long memberId,
final int size,
final ZonedDateTime createdAt
) {
final List<CapsuleBasicInfoDto> groupCapsules = jpaQueryFactory
final List<MyGroupCapsuleDto> groupCapsules = jpaQueryFactory
.select(
Projections.constructor(
CapsuleBasicInfoDto.class,
MyGroupCapsuleDto.class,
capsule.id,
capsuleSkin.imageUrl,
capsule.dueDate,
Expand All @@ -158,7 +159,12 @@ public Slice<CapsuleBasicInfoDto> findMyGroupCapsuleSlice(
.limit(size + 1)
.fetch();

return SliceUtil.makeSlice(size, groupCapsules);
final boolean hasNext = groupCapsules.size() > size;
if (hasNext) {
groupCapsules.remove(size);
}

return new SliceImpl<>(groupCapsules, Pageable.ofSize(size), hasNext);
}

public boolean findGroupCapsuleExistByGroupId(Long groupId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
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;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.CapsuleRepository;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleCreateRequestDto;
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.capsule.group_capsule.data.dto.GroupCapsuleOpenStateDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.repository.GroupCapsuleQueryRepository;
import site.timecapsulearchive.core.domain.capsuleskin.entity.CapsuleSkin;
Expand Down Expand Up @@ -82,7 +82,7 @@ public GroupCapsuleSummaryDto findGroupCapsuleSummaryByGroupIDAndCapsuleId(
* @param createdAt 조회를 시작할 캡슐의 생성 시간, 첫 조회라면 현재 시간, 이후 조회라면 맨 마지막 데이터의 시간
* @return 사용자가 생성한 그룹 캡슐 목록
*/
public Slice<CapsuleBasicInfoDto> findMyGroupCapsuleSlice(
public Slice<MyGroupCapsuleDto> findMyGroupCapsuleSlice(
final Long memberId,
final int size,
final ZonedDateTime createdAt
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<CapsuleBasicInfoDto> publicCapsules = publicCapsuleService.findMyPublicCapsuleSlice(
final Slice<MyPublicCapsuleDto> publicCapsules = publicCapsuleService.findMyPublicCapsuleSlice(
memberId, size, createdAt);

return ResponseEntity.ok(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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<String, String> singlePreSignUrlFunction) {
return MyPublicCapsuleResponse.builder()
.capsuleId(capsuleId)
.skinUrl(singlePreSignUrlFunction.apply(skinUrl))
.dueDate(dueDate)
.createdAt(createdAt)
.title(title)
.isOpened(isOpened)
.capsuleType(capsuleType)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import java.util.function.Function;
import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto;
import site.timecapsulearchive.core.domain.capsule.data.response.CapsuleBasicInfoResponse;
import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.MyPublicCapsuleResponse;

@Schema(description = "사용자가 만든 공개 캡슐 슬라이싱")
public record MyPublicCapsuleSliceResponse(

@Schema(description = "사용자가 만든 공개 캡슐 정보")
List<CapsuleBasicInfoResponse> publicCapsules,
List<MyPublicCapsuleResponse> publicCapsules,

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
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 @@ -159,22 +158,28 @@ public Slice<PublicCapsuleDetailDto> findPublicCapsulesDtoMadeByFriend(
.limit(size + 1)
.fetch();

return SliceUtil.makeSlice(size, publicCapsuleDetailDtos);
final boolean hasNext = canMoreRead(size, publicCapsuleDetailDtos.size());
if (hasNext) {
publicCapsuleDetailDtos.remove(size);
}

return new SliceImpl<>(publicCapsuleDetailDtos, Pageable.ofSize(size), hasNext);

}

private boolean canMoreRead(final int size, final int capsuleSize) {
return capsuleSize > size;
}

public Slice<CapsuleBasicInfoDto> findMyPublicCapsuleSlice(
public Slice<MyPublicCapsuleDto> findMyPublicCapsuleSlice(
final Long memberId,
final int size,
final ZonedDateTime createdAt
) {
final List<CapsuleBasicInfoDto> publicCapsules = jpaQueryFactory
final List<MyPublicCapsuleDto> publicCapsules = jpaQueryFactory
.select(
Projections.constructor(
CapsuleBasicInfoDto.class,
MyPublicCapsuleDto.class,
capsule.id,
capsuleSkin.imageUrl,
capsule.dueDate,
Expand All @@ -194,6 +199,11 @@ public Slice<CapsuleBasicInfoDto> findMyPublicCapsuleSlice(
.limit(size + 1)
.fetch();

return SliceUtil.makeSlice(size, publicCapsules);
final boolean hasNext = publicCapsules.size() > size;
if (hasNext) {
publicCapsules.remove(size);
}

return new SliceImpl<>(publicCapsules, Pageable.ofSize(size), hasNext);
}
}
Loading

0 comments on commit e8118e7

Please sign in to comment.