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 : 소셜(친구, 그룹) 캡슐 요약, 디테일 조회 API 수정 #556

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
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.CombinedGroupCapsuleDetailDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.CombinedGroupCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleDetailDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleMemberDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleOpenStateDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleSliceRequestDto;
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;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleOpenStateResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleMembersResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleOpenStateResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleSliceResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleSummaryResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.MyGroupCapsuleSliceResponse;
Expand Down Expand Up @@ -72,16 +72,16 @@ public ResponseEntity<ApiSpec<GroupCapsuleDetailResponse>> getGroupCapsuleDetail
@AuthenticationPrincipal Long memberId,
@PathVariable("capsule_id") Long capsuleId
) {
final GroupCapsuleDetailDto detailDto = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId(
capsuleId);
final CombinedGroupCapsuleDetailDto detailDto = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId(
memberId, capsuleId);

return ResponseEntity.ok(
ApiSpec.success(
SuccessCode.SUCCESS,
GroupCapsuleDetailResponse.createOf(
detailDto,
s3PreSignedUrlManager::getS3PreSignedUrlForGet,
s3PreSignedUrlManager::getS3PreSignedUrlsForGet,
s3PreSignedUrlManager::getS3PreSignedUrlForGet,
geoTransformManager::changePoint3857To4326
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto;

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

public record CombinedGroupCapsuleDetailDto(
Long groupId,
Long capsuleId,
String capsuleSkinUrl,
ZonedDateTime dueDate,
Long creatorId,
String nickname,
String profileUrl,
ZonedDateTime createdAt,
Point point,
String address,
String roadName,
String title,
String content,
String images,
String videos,
Boolean isCapsuleOpened,
CapsuleType capsuleType,
Boolean isRequestMemberCapsuleOpen,
Boolean hasEditPermission,
Boolean hasDeletePermission,
List<GroupCapsuleMemberSummaryDto> groupMembers
) {

public static CombinedGroupCapsuleDetailDto create(
final GroupCapsuleDetailDto groupCapsuleDetailDto,
final List<GroupCapsuleMemberSummaryDto> groupCapsuleMemberSummaryDtos,
final Boolean isRequestMemberCapsuleOpen,
final Boolean hasEditPermission,
final Boolean hasDeletePermission
) {
return new CombinedGroupCapsuleDetailDto(
groupCapsuleDetailDto.groupId(),
groupCapsuleDetailDto.capsuleId(),
groupCapsuleDetailDto.capsuleSkinUrl(),
groupCapsuleDetailDto.dueDate(),
groupCapsuleDetailDto.creatorId(),
groupCapsuleDetailDto.nickname(),
groupCapsuleDetailDto.profileUrl(),
groupCapsuleDetailDto.createdAt(),
groupCapsuleDetailDto.point(),
groupCapsuleDetailDto.address(),
groupCapsuleDetailDto.roadName(),
groupCapsuleDetailDto.title(),
groupCapsuleDetailDto.content(),
groupCapsuleDetailDto.images(),
groupCapsuleDetailDto.videos(),
groupCapsuleDetailDto.isCapsuleOpened(),
groupCapsuleDetailDto.capsuleType(),
isRequestMemberCapsuleOpen,
hasEditPermission,
hasDeletePermission,
groupCapsuleMemberSummaryDtos
);
}

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

final List<GroupCapsuleMemberSummaryResponse> groupMembers = this.groupMembers.stream()
.map(GroupCapsuleMemberSummaryDto::toResponse)
.toList();

return GroupCapsuleDetailResponse.builder()
.groupId(groupId)
.capsuleId(capsuleId)
.capsuleSkinUrl(preSignUrlFunction.apply(capsuleSkinUrl))
.members(groupMembers)
.dueDate(dueDate)
.nickname(nickname)
.profileUrl(profileUrl)
.createdDate(createdAt)
.latitude(changePoint.getX())
.longitude(changePoint.getY())
.address(address)
.roadName(roadName)
.title(title)
.content(content)
.imageUrls(multiplePreSignUrlFunction.apply(images))
.videoUrls(multiplePreSignUrlFunction.apply(videos))
.isCapsuleOpened(isCapsuleOpened)
.capsuleType(capsuleType)
.isRequestMemberCapsuleOpened(isRequestMemberCapsuleOpen)
.hasEditPermission(hasEditPermission)
.hasDeletePermission(hasDeletePermission)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,60 +1,82 @@
package site.timecapsulearchive.core.domain.capsule.group_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.generic_capsule.data.dto.CapsuleDetailDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleDetailResponse;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.response.GroupCapsuleMemberSummaryResponse;
import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.response.CapsuleDetailResponse;

public record GroupCapsuleDetailDto(
CapsuleDetailDto capsuleDetailDto,
List<GroupCapsuleMemberSummaryDto> members
Long groupId,
Long capsuleId,
String capsuleSkinUrl,
ZonedDateTime dueDate,
Long creatorId,
String nickname,
String profileUrl,
ZonedDateTime createdAt,
Point point,
String address,
String roadName,
String title,
String content,
String images,
String videos,
Boolean isCapsuleOpened,
CapsuleType capsuleType
) {

public List<GroupCapsuleMemberSummaryResponse> groupMemberSummaryDtoToResponse() {
return members.stream()
.map(GroupCapsuleMemberSummaryDto::toResponse)
.toList();
}

public GroupCapsuleDetailDto excludeDetailContents() {
public GroupCapsuleDetailDto excludeTitleAndContentAndImagesAndVideos() {
return new GroupCapsuleDetailDto(
capsuleDetailDto.excludeTitleAndContentAndImagesAndVideos(),
members
groupId,
capsuleId,
capsuleSkinUrl,
dueDate,
creatorId,
nickname,
profileUrl,
createdAt,
point,
address,
roadName,
"",
"",
"",
"",
isCapsuleOpened,
capsuleType
);
}

public GroupCapsuleDetailResponse toResponse(
public CapsuleDetailResponse 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());
images);
final List<String> preSignedVideoUrls = multiplePreSignUrlFunction.apply(
capsuleDetailDto.videos());
videos);

final Point changePoint = changePointFunction.apply(point);

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

import java.util.List;

public record GroupCapsuleWithMemberDetailDto(
GroupCapsuleDetailDto groupCapsuleDetailDto,
List<GroupCapsuleMemberSummaryDto> members
) {

public GroupCapsuleWithMemberDetailDto excludeDetailContents() {
return new GroupCapsuleWithMemberDetailDto(
groupCapsuleDetailDto.excludeTitleAndContentAndImagesAndVideos(),
members
);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
import java.time.ZonedDateTime;
import java.util.List;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import lombok.Builder;
import org.locationtech.jts.geom.Point;
import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleDetailDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.CombinedGroupCapsuleDetailDto;
import site.timecapsulearchive.core.global.common.response.ResponseMappingConstant;

@Schema(description = "그룹 캡슐 상세 정보")
@Builder
public record GroupCapsuleDetailResponse(

@Schema(description = "그룹 아이디")
Long groupId,

@Schema(description = "캡슐 아이디")
Long capsuleId,

Expand Down Expand Up @@ -59,11 +63,20 @@ public record GroupCapsuleDetailResponse(
@Schema(description = "비디오 url들")
List<String> videoUrls,

@Schema(description = "개봉 여부")
Boolean isOpened,
@Schema(description = "캡슐 개봉 여부")
Boolean isCapsuleOpened,

@Schema(description = "캡슐 타입")
CapsuleType capsuleType
CapsuleType capsuleType,

@Schema(description = "현재 사용자 캡슐 개봉 여부")
Boolean isRequestMemberCapsuleOpened,

@Schema(description = "캡슐 수정 권한 여부")
Boolean hasEditPermission,

@Schema(description = "캡슐 삭제 권한 여부")
Boolean hasDeletePermission
) {

public GroupCapsuleDetailResponse {
GaBaljaintheroom marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -75,13 +88,16 @@ public record GroupCapsuleDetailResponse(
}

public static GroupCapsuleDetailResponse createOf(
final GroupCapsuleDetailDto groupCapsuleDetailDto,
final Function<String, String> singlePreSignUrlFunction,
final CombinedGroupCapsuleDetailDto groupCapsuleDetailDto,
GaBaljaintheroom marked this conversation as resolved.
Show resolved Hide resolved
final Function<String, List<String>> multiplePreSignUrlFunction,
final Function<Point, Point> changePointFunction
final UnaryOperator<String> singlePreSignUrlFunction,
final UnaryOperator<Point> changePointFunction
) {
return groupCapsuleDetailDto.toResponse(singlePreSignUrlFunction,
multiplePreSignUrlFunction, changePointFunction);
return groupCapsuleDetailDto.toResponse(
multiplePreSignUrlFunction,
singlePreSignUrlFunction,
changePointFunction
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
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.group_capsule.data.dto.GroupCapsuleDetailDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleMemberSummaryDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleSliceRequestDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleWithMemberDetailDto;
import site.timecapsulearchive.core.domain.member.entity.QMember;
import site.timecapsulearchive.core.global.util.SliceUtil;

Expand All @@ -37,7 +37,7 @@ public class GroupCapsuleQueryRepository {

private final JPAQueryFactory jpaQueryFactory;

public Optional<GroupCapsuleDetailDto> findGroupCapsuleDetailDtoByCapsuleId(
public Optional<GroupCapsuleWithMemberDetailDto> findGroupCapsuleDetailDtoByCapsuleId(
final Long capsuleId
) {
final QMember owner = new QMember("owner");
Expand All @@ -47,6 +47,7 @@ public Optional<GroupCapsuleDetailDto> findGroupCapsuleDetailDtoByCapsuleId(
.selectFrom(capsule)
.join(owner).on(capsule.member.id.eq(owner.id))
.join(capsuleSkin).on(capsule.capsuleSkin.id.eq(capsuleSkin.id))
.join(capsule.group, group)
.leftJoin(image).on(capsule.id.eq(image.capsule.id))
.leftJoin(video).on(capsule.id.eq(video.capsule.id))
.join(groupCapsuleOpen).on(groupCapsuleOpen.capsule.id.eq(capsuleId))
Expand All @@ -57,12 +58,14 @@ public Optional<GroupCapsuleDetailDto> findGroupCapsuleDetailDtoByCapsuleId(
.transform(
groupBy(capsule.id).as(
Projections.constructor(
GroupCapsuleDetailDto.class,
GroupCapsuleWithMemberDetailDto.class,
Projections.constructor(
CapsuleDetailDto.class,
GroupCapsuleDetailDto.class,
group.id,
capsule.id,
capsuleSkin.imageUrl,
capsule.dueDate,
owner.id,
owner.nickname,
owner.profileUrl,
capsule.createdAt,
Expand Down
Loading
Loading