Skip to content

Commit

Permalink
refact: 캡슐 응답 builder 패턴 적용
Browse files Browse the repository at this point in the history
자바 구글 형식 적용
  • Loading branch information
GaBaljaintheroom committed May 5, 2024
1 parent aa927ad commit b991378
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 105 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto;

import java.time.ZonedDateTime;
import java.util.List;
import java.util.function.Function;
import org.locationtech.jts.geom.Point;
import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.response.CapsuleDetailResponse;

public record CapsuleDetailDto(
Long capsuleId,
Expand Down Expand Up @@ -41,4 +44,35 @@ public CapsuleDetailDto excludeTitleAndContentAndImagesAndVideos() {
capsuleType
);
}

public CapsuleDetailResponse toResponse(
final Function<String, String> singlePreSignUrlFunction,
final Function<String, List<String>> multiplePreSignUrlFunction,
final Function<Point, Point> changePointFunction
) {
final List<String> preSignedImageUrls = multiplePreSignUrlFunction.apply(
images);
final List<String> preSignedVideoUrls = multiplePreSignUrlFunction.apply(
videos);

final Point changePoint = changePointFunction.apply(point);

return CapsuleDetailResponse.builder()
.capsuleSkinUrl(singlePreSignUrlFunction.apply(capsuleSkinUrl))
.dueDate(dueDate)
.nickname(nickname)
.profileUrl(profileUrl)
.createdDate(createdAt)
.latitude(changePoint.getX())
.longitude(changePoint.getY())
.address(address)
.roadName(roadName)
.title(title)
.content(content)
.imageUrls(preSignedImageUrls)
.videoUrls(preSignedVideoUrls)
.isOpened(isOpened)
.capsuleType(capsuleType)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto;

import java.time.ZonedDateTime;
import java.util.function.Function;
import org.locationtech.jts.geom.Point;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.response.CapsuleSummaryResponse;

public record CapsuleSummaryDto(
String nickname,
Expand All @@ -16,4 +18,24 @@ public record CapsuleSummaryDto(
ZonedDateTime createdAt
) {

public CapsuleSummaryResponse toResponse(
final Function<String, String> preSignUrlFunction,
final Function<Point, Point> changePointFunction
) {
final Point changePoint = changePointFunction.apply(point);

return CapsuleSummaryResponse.builder()
.nickname(nickname)
.profileUrl(profileUrl)
.skinUrl(preSignUrlFunction.apply(skinUrl))
.title(title)
.dueDate(dueDate)
.latitude(changePoint.getX())
.longitude(changePoint.getY())
.address(address)
.isOpened(isOpened)
.createdAt(createdAt)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,7 @@ public static CapsuleDetailResponse createOf(
final Function<String, List<String>> multiplePreSignUrlFunction,
final Function<Point, Point> changePointFunction
) {
final List<String> preSignedImageUrls = multiplePreSignUrlFunction.apply(
detailDto.images());
final List<String> preSignedVideoUrls = multiplePreSignUrlFunction.apply(
detailDto.videos());

final Point changePoint = changePointFunction.apply(detailDto.point());

return new CapsuleDetailResponse(
singlePreSignUrlFunction.apply(detailDto.capsuleSkinUrl()),
detailDto.dueDate(),
detailDto.nickname(),
detailDto.profileUrl(),
detailDto.createdAt(),
changePoint.getX(),
changePoint.getY(),
detailDto.address(),
detailDto.roadName(),
detailDto.title(),
detailDto.content(),
preSignedImageUrls,
preSignedVideoUrls,
detailDto.isOpened(),
detailDto.capsuleType()
);
return detailDto.toResponse(singlePreSignUrlFunction, multiplePreSignUrlFunction,
changePointFunction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,6 @@ public static CapsuleSummaryResponse createOf(
final Function<String, String> preSignUrlFunction,
final Function<Point, Point> changePointFunction
) {
final Point changePoint = changePointFunction.apply(summaryDto.point());

return new CapsuleSummaryResponse(
summaryDto.nickname(),
summaryDto.profileUrl(),
preSignUrlFunction.apply(summaryDto.skinUrl()),
summaryDto.title(),
summaryDto.dueDate(),
changePoint.getX(),
changePoint.getY(),
summaryDto.address(),
summaryDto.roadName(),
summaryDto.isOpened(),
summaryDto.createdAt()
);
return summaryDto.toResponse(preSignUrlFunction, changePointFunction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class CapsuleQueryRepository {
*
* @param memberId 범위 내의 캡슙을 조회할 멤버 id
* @param mbr 캡슐을 조회할 범위(최소사각형)
* @see site.timecapsulearchive.core.global.geography.GeoTransformManager
* @param capsuleType 조회할 캡슐의 타입
* @return 범위 내에 조회된 캡슐들의 요약 정보들을 반환한다.
* @see site.timecapsulearchive.core.global.geography.GeoTransformManager
*/
public List<NearbyARCapsuleSummaryDto> findARCapsuleSummaryDtosByCurrentLocationAndCapsuleType(
final Long memberId,
Expand Down Expand Up @@ -99,11 +99,11 @@ public List<NearbyCapsuleSummaryDto> findCapsuleSummaryDtosByCurrentLocationAndC
.fetch();
}

/**
/**
* 지도에서 사용자의 친구들의 캡슐을 찾기 위해 현재 위치에서 범위 내의 사용자의 친구가 만든 캡슐을 조회한다.
*
* @param friendIds 범위 내의 조회할 사용자 목록
* @param mbr 캡슐을 조회할 범위(최소사각형), <code>GeoTransformManager</code> 참조
* @param mbr 캡슐을 조회할 범위(최소사각형), <code>GeoTransformManager</code> 참조
* @return 범위 내에 조회된 캡슐들의 요약 정보들을 반환한다.
*/
public List<NearbyCapsuleSummaryDto> findFriendsCapsuleSummaryDtosByCurrentLocationAndCapsuleType(
Expand Down Expand Up @@ -131,11 +131,11 @@ private BooleanExpression ST_Contains(Polygon mbr, ComparablePath<Point> point)
return Expressions.booleanTemplate("ST_Contains({0}, {1})", mbr, point);
}

/**
/**
* AR에서 사용자의 친구들의 캡슐을 찾기 위해 현재 위치에서 범위 내의 사용자의 친구가 만든 캡슐을 조회한다.
*
* @param friendIds 범위 내의 조회할 사용자 목록
* @param mbr 캡슐을 조회할 범위(최소사각형), <code>GeoTransformManager</code> 참조
* @param mbr 캡슐을 조회할 범위(최소사각형), <code>GeoTransformManager</code> 참조
* @return 범위 내에 조회된 캡슐들의 요약 정보들을 반환한다.
*/
public List<NearbyARCapsuleSummaryDto> findFriendsARCapsulesByCurrentLocation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ public Capsule saveCapsule(

/**
* 지도에서 캡슐을 찾기 위해 사용자의 현재 위치에서 특정 반경에서 친구들의 캡슐들을 요약 조회한다
*
* @param memberId 사용자 아이디
* @param dto 현재 위치와 반경
* @param dto 현재 위치와 반경
* @return 지도용 캡슐 요약 조회들
*/
@Transactional(readOnly = true)
Expand All @@ -119,8 +120,9 @@ public List<NearbyCapsuleSummaryDto> findFriendsCapsulesByCurrentLocation(

/**
* AR로 캡슐을 찾기 위해 사용자의 현재 위치에서 특정 반경에서 친구들의 캡슐들을 요약 조회한다
*
* @param memberId 사용자 아이디
* @param dto 현재 위치와 반경
* @param dto 현재 위치와 반경
* @return AR용 캡슐 요약 조회들
*/
public List<NearbyARCapsuleSummaryDto> findFriendsARCapsulesByCurrentLocation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.reqeust.GroupCapsuleUpdateRequest;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleDetailResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsulePageResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.MyGroupCapsuleSliceResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleSummaryResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.MyGroupCapsuleSliceResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.facade.GroupCapsuleFacade;
import site.timecapsulearchive.core.domain.capsule.group_capsule.service.GroupCapsuleService;
import site.timecapsulearchive.core.global.common.response.ApiSpec;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto;

import java.util.List;
import java.util.function.Function;
import org.locationtech.jts.geom.Point;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleDetailDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleDetailResponse;
import site.timecapsulearchive.core.domain.group.data.dto.GroupMemberSummaryDto;
import site.timecapsulearchive.core.domain.group.data.response.GroupMemberSummaryResponse;

Expand All @@ -10,7 +13,7 @@ public record GroupCapsuleDetailDto(
List<GroupMemberSummaryDto> members
) {

public List<GroupMemberSummaryResponse> toGroupMemberSummaryResponse() {
public List<GroupMemberSummaryResponse> groupMemberSummaryDtoToResponse() {
return members.stream()
.map(GroupMemberSummaryDto::toResponse)
.toList();
Expand All @@ -22,4 +25,37 @@ public GroupCapsuleDetailDto excludeDetailContents() {
members
);
}

public GroupCapsuleDetailResponse toResponse(
final Function<String, String> singlePreSignUrlFunction,
final Function<String, List<String>> multiplePreSignUrlFunction,
final Function<Point, Point> changePointFunction
) {
final Point changePoint = changePointFunction.apply(capsuleDetailDto.point());

final List<String> preSignedImageUrls = multiplePreSignUrlFunction.apply(
capsuleDetailDto.images());
final List<String> preSignedVideoUrls = multiplePreSignUrlFunction.apply(
capsuleDetailDto.videos());

return GroupCapsuleDetailResponse.builder()
.capsuleId(capsuleDetailDto.capsuleId())
.capsuleSkinUrl(singlePreSignUrlFunction.apply(capsuleDetailDto.capsuleSkinUrl()))
.members(groupMemberSummaryDtoToResponse())
.dueDate(capsuleDetailDto.dueDate())
.nickname(capsuleDetailDto.nickname())
.profileUrl(capsuleDetailDto.profileUrl())
.createdDate(capsuleDetailDto.createdAt())
.latitude(changePoint.getX())
.longitude(changePoint.getY())
.address(capsuleDetailDto.address())
.roadName(capsuleDetailDto().roadName())
.title(capsuleDetailDto().title())
.content(capsuleDetailDto.content())
.imageUrls(preSignedImageUrls)
.videoUrls(preSignedVideoUrls)
.isOpened(capsuleDetailDto.isOpened())
.capsuleType(capsuleDetailDto.capsuleType())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto;

import java.util.List;
import java.util.function.Function;
import org.locationtech.jts.geom.Point;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleSummaryResponse;
import site.timecapsulearchive.core.domain.group.data.dto.GroupMemberSummaryDto;
import site.timecapsulearchive.core.domain.group.data.response.GroupMemberSummaryResponse;

Expand All @@ -10,9 +13,31 @@ public record GroupCapsuleSummaryDto(
List<GroupMemberSummaryDto> members
) {

public List<GroupMemberSummaryResponse> toGroupMemberSummaryResponse() {
public List<GroupMemberSummaryResponse> groupMemberSummaryDtoToResponse() {
return members.stream()
.map(GroupMemberSummaryDto::toResponse)
.toList();
}

public GroupCapsuleSummaryResponse toResponse(
final Function<String, String> preSignUrlFunction,
final Function<Point, Point> changePointFunction
) {
final Point changePoint = changePointFunction.apply(capsuleSummaryDto.point());

return GroupCapsuleSummaryResponse.builder()
.members(groupMemberSummaryDtoToResponse())
.nickname(capsuleSummaryDto.nickname())
.profileUrl(capsuleSummaryDto.profileUrl())
.skinUrl(preSignUrlFunction.apply(capsuleSummaryDto.skinUrl()))
.title(capsuleSummaryDto.title())
.dueDate(capsuleSummaryDto.dueDate())
.latitude(changePoint.getX())
.longitude(changePoint.getY())
.address(capsuleSummaryDto.address())
.roadName(capsuleSummaryDto.roadName())
.isOpened(capsuleSummaryDto.isOpened())
.createdAt(capsuleSummaryDto.createdAt())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import java.time.ZonedDateTime;
import java.util.List;
import java.util.function.Function;
import lombok.Builder;
import org.locationtech.jts.geom.Point;
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.group_capsule.data.dto.GroupCapsuleDetailDto;
import site.timecapsulearchive.core.domain.group.data.response.GroupMemberSummaryResponse;
import site.timecapsulearchive.core.global.common.response.ResponseMappingConstant;

@Schema(description = "그룹 캡슐 상세 정보")
@Builder
public record GroupCapsuleDetailResponse(
@Schema(description = "캡슐 아이디")
Long capsuleId,
Expand Down Expand Up @@ -79,33 +80,8 @@ public static GroupCapsuleDetailResponse createOf(
final Function<String, List<String>> multiplePreSignUrlFunction,
final Function<Point, Point> changePointFunction
) {
final CapsuleDetailDto detailDto = groupCapsuleDetailDto.capsuleDetailDto();
final Point changePoint = changePointFunction.apply(detailDto.point());

final List<String> preSignedImageUrls = multiplePreSignUrlFunction.apply(
detailDto.images());
final List<String> preSignedVideoUrls = multiplePreSignUrlFunction.apply(
detailDto.videos());

return new GroupCapsuleDetailResponse(
detailDto.capsuleId(),
singlePreSignUrlFunction.apply(detailDto.capsuleSkinUrl()),
groupCapsuleDetailDto.toGroupMemberSummaryResponse(),
detailDto.dueDate(),
detailDto.nickname(),
detailDto.profileUrl(),
detailDto.createdAt(),
changePoint.getX(),
changePoint.getY(),
detailDto.address(),
detailDto.roadName(),
detailDto.title(),
detailDto.content(),
preSignedImageUrls,
preSignedVideoUrls,
detailDto.isOpened(),
detailDto.capsuleType()
);
return groupCapsuleDetailDto.toResponse(singlePreSignUrlFunction,
multiplePreSignUrlFunction, changePointFunction);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.function.Function;
import lombok.Builder;
import org.locationtech.jts.geom.Point;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.group.data.response.GroupMemberSummaryResponse;
import site.timecapsulearchive.core.global.common.response.ResponseMappingConstant;
Expand Down Expand Up @@ -65,22 +64,6 @@ public static GroupCapsuleSummaryResponse createOf(
final Function<String, String> preSignUrlFunction,
final Function<Point, Point> changePointFunction
) {
final CapsuleSummaryDto capsuleSummaryDto = summaryDto.capsuleSummaryDto();
final Point changePoint = changePointFunction.apply(capsuleSummaryDto.point());

return new GroupCapsuleSummaryResponse(
summaryDto.toGroupMemberSummaryResponse(),
capsuleSummaryDto.nickname(),
capsuleSummaryDto.profileUrl(),
preSignUrlFunction.apply(capsuleSummaryDto.skinUrl()),
capsuleSummaryDto.title(),
capsuleSummaryDto.dueDate(),
changePoint.getX(),
changePoint.getY(),
capsuleSummaryDto.address(),
capsuleSummaryDto.roadName(),
capsuleSummaryDto.isOpened(),
capsuleSummaryDto.createdAt()
);
return summaryDto.toResponse(preSignUrlFunction, changePointFunction);
}
}
Loading

0 comments on commit b991378

Please sign in to comment.