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
@@ -1,6 +1,5 @@
package site.timecapsulearchive.core.domain.capsule.entity;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -39,42 +38,31 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Capsule extends BaseEntity {

@OneToMany(mappedBy = "capsule")
private final List<Image> images = new ArrayList<>();
@OneToMany(mappedBy = "capsule")
private final List<Video> videos = new ArrayList<>();
@OneToMany(mappedBy = "capsule")
private final List<GroupCapsuleOpen> groupCapsuleOpens = new ArrayList<>();
@Id
@Column(name = "capsule_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "due_date")
private ZonedDateTime dueDate;

@Column(name = "point", columnDefinition = "SRID 3857")
private Point point;

@Column(name = "title", nullable = false)
private String title;

@Column(name = "content", nullable = false)
private String content;

@Column(name = "type", nullable = false)
@Enumerated(EnumType.STRING)
private CapsuleType type;

@Column(name = "is_opened", nullable = false)
private Boolean isOpened;

@Embedded
private Address address;

@OneToMany(mappedBy = "capsule")
private final List<Image> images = new ArrayList<>();

@OneToMany(mappedBy = "capsule")
private final List<Video> videos = new ArrayList<>();

@OneToMany(mappedBy = "capsule")
private final List<GroupCapsuleOpen> groupCapsuleOpens = new ArrayList<>();

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "group_id")
private Group group;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.ComparablePath;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import java.util.Optional;
Expand All @@ -21,7 +20,6 @@
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.NearbyARCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.NearbyCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.treasure_capsule.data.dto.TreasureCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.member_group.entity.MemberGroup;

@Repository
@RequiredArgsConstructor
Expand Down Expand Up @@ -69,11 +67,13 @@ public List<NearbyARCapsuleSummaryDto> findARCapsuleSummaryDtosByCurrentLocation
.from(capsule)
.join(capsule.capsuleSkin, capsuleSkin)
.join(capsule.member, member)
.where(ST_Contains(mbr, capsule.point).and(capsuleFilter(capsuleType, memberId, groupIds)))
.where(
ST_Contains(mbr, capsule.point).and(capsuleFilter(capsuleType, memberId, groupIds)))
.fetch();
}

private BooleanExpression capsuleFilter(CapsuleType capsuleType, Long memberId, List<Long> groupIds) {
private BooleanExpression capsuleFilter(CapsuleType capsuleType, Long memberId,
List<Long> groupIds) {
return switch (capsuleType) {
case ALL -> capsule.member.id.eq(memberId).or(capsule.group.id.in(groupIds));
case TREASURE -> capsule.type.eq(capsuleType);
Expand Down Expand Up @@ -116,7 +116,8 @@ public List<NearbyCapsuleSummaryDto> findCapsuleSummaryDtosByCurrentLocationAndC
.from(capsule)
.join(capsule.capsuleSkin, capsuleSkin)
.join(capsule.member, member)
.where(ST_Contains(mbr, capsule.point).and(capsuleFilter(capsuleType, memberId, groupIds)))
.where(
ST_Contains(mbr, capsule.point).and(capsuleFilter(capsuleType, memberId, groupIds)))
.fetch();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ public List<NearbyARCapsuleSummaryDto> findFriendsARCapsulesByCurrentLocation(
}

@Transactional
public void deleteRelatedAllCapsuleByMemberId(final Long memberId, final ZonedDateTime deletedAt) {
public void deleteRelatedAllCapsuleByMemberId(final Long memberId,
final ZonedDateTime deletedAt) {
imageRepository.deleteByMemberId(memberId, deletedAt);
videoRepository.deleteByMemberId(memberId, deletedAt);
capsuleSkinRepository.deleteByMemberId(memberId, deletedAt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
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
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();
}
}
Loading
Loading