Skip to content

Commit

Permalink
Merge pull request #357 from tukcomCD2024/ARCH-161-B-feat/group_capsu…
Browse files Browse the repository at this point in the history
…le_detail

feat : 그룹 캡슐 상세 & 요약 조회
  • Loading branch information
seokho-1116 authored May 5, 2024
2 parents 1e101f6 + b991378 commit 13ebd94
Show file tree
Hide file tree
Showing 37 changed files with 1,113 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.util.Objects;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import site.timecapsulearchive.core.domain.member.entity.Member;
Expand All @@ -26,11 +28,21 @@ public class GroupCapsuleOpen extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

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

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "capsule_id", nullable = false)
private Capsule capsule;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
private Member member;

@Builder
private GroupCapsuleOpen(Boolean isOpened, Capsule capsule, Member member) {
this.isOpened = Objects.requireNonNull(isOpened);
this.capsule = Objects.requireNonNull(capsule);
this.member = Objects.requireNonNull(member);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +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 All @@ -10,6 +14,7 @@ public record CapsuleDetailDto(
String nickname,
String profileUrl,
ZonedDateTime createdAt,
Point point,
String address,
String roadName,
String title,
Expand All @@ -28,6 +33,7 @@ public CapsuleDetailDto excludeTitleAndContentAndImagesAndVideos() {
nickname,
profileUrl,
createdAt,
point,
address,
roadName,
"",
Expand All @@ -38,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,17 +1,41 @@
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,
String profileUrl,
String skinUrl,
String title,
ZonedDateTime dueDate,
Point point,
String address,
String roadName,
Boolean isOpened,
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 @@ -5,6 +5,7 @@
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.global.common.response.ResponseMappingConstant;
Expand All @@ -28,6 +29,12 @@ public record CapsuleDetailResponse(
@Schema(description = "생성일")
ZonedDateTime createdDate,

@Schema(description = "캡슐 위도 좌표")
Double latitude,

@Schema(description = "캡슐 경도 좌표")
Double longitude,

@Schema(description = "캡슐 생성 주소")
String address,

Expand Down Expand Up @@ -64,27 +71,10 @@ public record CapsuleDetailResponse(
public static CapsuleDetailResponse createOf(
final CapsuleDetailDto detailDto,
final Function<String, String> singlePreSignUrlFunction,
final Function<String, List<String>> multiplePreSignUrlFunction
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());

return new CapsuleDetailResponse(
singlePreSignUrlFunction.apply(detailDto.capsuleSkinUrl()),
detailDto.dueDate(),
detailDto.nickname(),
detailDto.profileUrl(),
detailDto.createdAt(),
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 @@ -4,6 +4,7 @@
import java.time.ZonedDateTime;
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.global.common.response.ResponseMappingConstant;

Expand All @@ -26,6 +27,12 @@ public record CapsuleSummaryResponse(
@Schema(description = "개봉일")
ZonedDateTime dueDate,

@Schema(description = "캡슐 위도 좌표")
Double latitude,

@Schema(description = "캡슐 경도 좌표")
Double longitude,

@Schema(description = "캡슐 생성 주소")
String address,

Expand All @@ -49,18 +56,9 @@ public record CapsuleSummaryResponse(

public static CapsuleSummaryResponse createOf(
final CapsuleSummaryDto summaryDto,
final Function<String, String> preSignUrlFunction
final Function<String, String> preSignUrlFunction,
final Function<Point, Point> changePointFunction
) {
return new CapsuleSummaryResponse(
summaryDto.nickname(),
summaryDto.profileUrl(),
preSignUrlFunction.apply(summaryDto.skinUrl()),
summaryDto.title(),
summaryDto.dueDate(),
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 @@ -67,7 +67,7 @@ ResponseEntity<ApiSpec<String>> createGroupCapsule(

@Operation(
summary = "그룹 캡슐 상세 조회",
description = "그룹원만 볼 수 있는 그룹 캡슐 내용을 조회한다.",
description = "그룹원만 볼 수 있는 그룹 캡슐 내용을 상세 조회한다.",
security = {@SecurityRequirement(name = "user_token")},
tags = {"group capsule"}
)
Expand All @@ -77,16 +77,30 @@ ResponseEntity<ApiSpec<String>> createGroupCapsule(
description = "처리 완료"
)
})
@GetMapping(
value = "/groups/{group_id}/capsules/{capsule_id}",
produces = {"application/json"}
ResponseEntity<ApiSpec<GroupCapsuleDetailResponse>> getGroupCapsuleDetailByCapsuleId(
Long memberId,

@Parameter(in = ParameterIn.PATH, description = "조회할 캡슐 아이디", required = true)
Long capsuleId
);

@Operation(
summary = "그룹 캡슐 요약 조회",
description = "그룹원만 볼 수 있는 그룹 캡슐 내용을 요약 조회한다.",
security = {@SecurityRequirement(name = "user_token")},
tags = {"group capsule"}
)
ResponseEntity<GroupCapsuleDetailResponse> findGroupCapsuleByIdAndGroupId(
@Parameter(in = ParameterIn.PATH, description = "조회할 그룹 아이디", required = true, schema = @Schema())
@PathVariable("group_id") Long groupId,
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "처리 완료"
)
})
ResponseEntity<ApiSpec<GroupCapsuleSummaryResponse>> getGroupCapsuleSummaryByCapsuleId(
Long memberId,

@Parameter(in = ParameterIn.PATH, description = "조회할 캡슐 아이디", required = true, schema = @Schema())
@PathVariable("capsule_id") Long capsuleId
@Parameter(in = ParameterIn.PATH, description = "조회할 캡슐 아이디", required = true)
Long capsuleId
);

@Operation(
Expand Down
Loading

0 comments on commit 13ebd94

Please sign in to comment.