From bb4cca7491dde0285a1f36636530578b2ae0b836 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Fri, 5 Jul 2024 21:50:53 +0900 Subject: [PATCH 1/8] =?UTF-8?q?fix=20:=20=EA=B3=B5=EA=B0=9C=20=EC=BA=A1?= =?UTF-8?q?=EC=8A=90=20=EB=AC=B8=EC=84=9C=ED=99=94=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/capsule/public_capsule/api/PublicCapsuleApi.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApi.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApi.java index 8cc625267..1034916c2 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApi.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApi.java @@ -57,7 +57,7 @@ ResponseEntity> createPublicCapsule( @Operation( summary = "공개 캡슐 요약 조회", - description = "사용자의 친구들만 볼 수 있는 공개 캡슐 내용을 요약 조회한다.", + description = "사용자와 친구들이 만든 공개 캡슐 내용을 요약 조회한다.", security = {@SecurityRequirement(name = "user_token")}, tags = {"public capsule"} ) @@ -86,7 +86,7 @@ ResponseEntity> getPublicCapsuleSummaryById( @Operation( summary = "공개 캡슐 상세 조회", - description = "사용자의 친구들만 볼 수 있는 공개 캡슐 내용을 조회한다.", + description = "사용자와 친구들이 만든 공개 캡슐 내용을 상세 조회한다.", security = {@SecurityRequirement(name = "user_token")}, tags = {"public capsule"} ) @@ -114,7 +114,7 @@ ResponseEntity> getPublicCapsuleDetailById( ); @Operation( - summary = "친구가 만든 공개 캡슐 목록 조회", + summary = "사용자와 친구가 만든 공개 캡슐 목록 조회", description = "사용자와 친구가 만든 공개 캡슐 목록을 조회한다.", security = {@SecurityRequirement(name = "user_token")}, tags = {"public capsule"} From 206550033101e10d7fc005f981b13f7debe68d3f Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Fri, 5 Jul 2024 22:48:13 +0900 Subject: [PATCH 2/8] =?UTF-8?q?feat=20:=20=EA=B3=B5=EA=B0=9C=20=EC=BA=A1?= =?UTF-8?q?=EC=8A=90=20=EC=9A=94=EC=95=BD,=20=EC=83=81=EC=84=B8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=BA=A1=EC=8A=90=20=EC=86=8C=EC=9C=A0=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20=ED=83=80=EC=9E=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public_capsule/api/PublicCapsuleApi.java | 3 +- .../api/PublicCapsuleApiController.java | 8 ++- .../data/dto/PublicCapsuleSummaryDto.java | 45 ++++++++++++ .../PublicCapsuleSummaryResponse.java | 70 +++++++++++++++++++ .../PublicCapsuleQueryRepository.java | 29 ++++++-- .../service/PublicCapsuleService.java | 3 +- .../PublicCapsuleQueryRepositoryTest.java | 9 +-- 7 files changed, 152 insertions(+), 15 deletions(-) create mode 100644 backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/dto/PublicCapsuleSummaryDto.java create mode 100644 backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/response/PublicCapsuleSummaryResponse.java diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApi.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApi.java index 1034916c2..2a33844bc 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApi.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApi.java @@ -22,6 +22,7 @@ import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.MyPublicCapsuleSliceResponse; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.reqeust.PublicCapsuleUpdateRequest; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.PublicCapsuleSliceResponse; +import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.PublicCapsuleSummaryResponse; import site.timecapsulearchive.core.global.common.response.ApiSpec; import site.timecapsulearchive.core.global.error.ErrorResponse; @@ -77,7 +78,7 @@ ResponseEntity> createPublicCapsule( content = @Content(schema = @Schema(implementation = ErrorResponse.class)) ) }) - ResponseEntity> getPublicCapsuleSummaryById( + ResponseEntity> getPublicCapsuleSummaryById( Long memberId, @Parameter(in = ParameterIn.PATH, description = "조회할 캡슐 아이디", required = true, schema = @Schema()) diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApiController.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApiController.java index 97cd4d050..11ca77c47 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApiController.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApiController.java @@ -24,8 +24,10 @@ import site.timecapsulearchive.core.domain.capsule.generic_capsule.facade.CapsuleFacade; 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.dto.PublicCapsuleSummaryDto; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.reqeust.PublicCapsuleUpdateRequest; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.PublicCapsuleSliceResponse; +import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.PublicCapsuleSummaryResponse; import site.timecapsulearchive.core.domain.capsule.public_capsule.service.PublicCapsuleService; import site.timecapsulearchive.core.global.common.response.ApiSpec; import site.timecapsulearchive.core.global.common.response.SuccessCode; @@ -62,17 +64,17 @@ public ResponseEntity> createPublicCapsule( produces = {"application/json"} ) @Override - public ResponseEntity> getPublicCapsuleSummaryById( + public ResponseEntity> getPublicCapsuleSummaryById( @AuthenticationPrincipal final Long memberId, @PathVariable("capsule_id") final Long capsuleId ) { - final CapsuleSummaryDto summaryDto = publicCapsuleService.findPublicCapsuleSummaryByMemberIdAndCapsuleId( + final PublicCapsuleSummaryDto summaryDto = publicCapsuleService.findPublicCapsuleSummaryByMemberIdAndCapsuleId( memberId, capsuleId); return ResponseEntity.ok( ApiSpec.success( SuccessCode.SUCCESS, - CapsuleSummaryResponse.createOf( + PublicCapsuleSummaryResponse.createOf( summaryDto, s3PreSignedUrlManager::getS3PreSignedUrlForGet, geoTransformManager::changePoint3857To4326 diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/dto/PublicCapsuleSummaryDto.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/dto/PublicCapsuleSummaryDto.java new file mode 100644 index 000000000..3a2fc5ed5 --- /dev/null +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/dto/PublicCapsuleSummaryDto.java @@ -0,0 +1,45 @@ +package site.timecapsulearchive.core.domain.capsule.public_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; +import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.PublicCapsuleSummaryResponse; + +public record PublicCapsuleSummaryDto( + String nickname, + String profileUrl, + String skinUrl, + String title, + ZonedDateTime dueDate, + Point point, + String address, + String roadName, + Boolean isOpened, + ZonedDateTime createdAt, + Boolean isOwner +) { + + public PublicCapsuleSummaryResponse toResponse( + final Function preSignUrlFunction, + final Function changePointFunction + ) { + final Point changePoint = changePointFunction.apply(point); + + return PublicCapsuleSummaryResponse.builder() + .nickname(nickname) + .profileUrl(profileUrl) + .skinUrl(preSignUrlFunction.apply(skinUrl)) + .title(title) + .dueDate(dueDate) + .latitude(changePoint.getX()) + .longitude(changePoint.getY()) + .address(address) + .roadName(roadName) + .isOpened(isOpened) + .createdAt(createdAt) + .isOwner(isOwner) + .build(); + } + +} \ No newline at end of file diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/response/PublicCapsuleSummaryResponse.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/response/PublicCapsuleSummaryResponse.java new file mode 100644 index 000000000..1de7d87de --- /dev/null +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/response/PublicCapsuleSummaryResponse.java @@ -0,0 +1,70 @@ +package site.timecapsulearchive.core.domain.capsule.public_capsule.data.response; + +import io.swagger.v3.oas.annotations.media.Schema; +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.domain.capsule.public_capsule.data.dto.PublicCapsuleSummaryDto; +import site.timecapsulearchive.core.global.common.response.ResponseMappingConstant; + +@Schema(description = "캡슐 요약 정보") +@Builder +public record PublicCapsuleSummaryResponse( + + @Schema(description = "생성자 닉네임") + String nickname, + + @Schema(description = "생성자 프로필 url") + String profileUrl, + + @Schema(description = "캡슐 스킨 url") + String skinUrl, + + @Schema(description = "제목") + String title, + + @Schema(description = "개봉일") + ZonedDateTime dueDate, + + @Schema(description = "캡슐 위도 좌표") + Double latitude, + + @Schema(description = "캡슐 경도 좌표") + Double longitude, + + @Schema(description = "캡슐 생성 주소") + String address, + + @Schema(description = "캡슐 생성 도로 이름") + String roadName, + + @Schema(description = "개봉 여부") + Boolean isOpened, + + @Schema(description = "캡슐 생성 일") + ZonedDateTime createdAt, + + @Schema(description = "캡슐 소유 여부") + Boolean isOwner +) { + + public PublicCapsuleSummaryResponse { + if (dueDate != null) { + dueDate = dueDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID); + } + + if (createdAt != null) { + createdAt = createdAt.withZoneSameInstant(ResponseMappingConstant.ZONE_ID); + } + } + + public static PublicCapsuleSummaryResponse createOf( + final PublicCapsuleSummaryDto summaryDto, + final Function preSignUrlFunction, + final Function changePointFunction + ) { + return summaryDto.toResponse(preSignUrlFunction, changePointFunction); + } +} diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java index b9aa3f28b..21b8f1dfd 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java @@ -8,22 +8,24 @@ import static site.timecapsulearchive.core.domain.member.entity.QMember.member; import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.CaseBuilder; import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.core.types.dsl.NumberTemplate; import com.querydsl.core.types.dsl.StringExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import java.time.ZonedDateTime; 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.public_capsule.data.dto.PublicCapsuleDetailDto; +import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.PublicCapsuleSummaryDto; import site.timecapsulearchive.core.global.util.SliceUtil; @Repository @@ -79,7 +81,7 @@ private StringExpression groupConcatDistinct(final StringExpression expression) return Expressions.stringTemplate("GROUP_CONCAT(DISTINCT {0})", expression); } - public Optional findPublicCapsuleSummaryDtosByMemberIdAndCapsuleId( + public Optional findPublicCapsuleSummaryDtosByMemberIdAndCapsuleId( final Long memberId, final Long capsuleId ) { @@ -87,7 +89,7 @@ public Optional findPublicCapsuleSummaryDtosByMemberIdAndCaps jpaQueryFactory .select( Projections.constructor( - CapsuleSummaryDto.class, + PublicCapsuleSummaryDto.class, member.nickname, member.profileUrl, capsuleSkin.imageUrl, @@ -97,7 +99,10 @@ public Optional findPublicCapsuleSummaryDtosByMemberIdAndCaps capsule.address.fullRoadAddressName, capsule.address.roadName, capsule.isOpened, - capsule.createdAt + capsule.createdAt, + new CaseBuilder() + .when(eqMemberId(memberId)).then(true) + .otherwise(false) ) ) .from(capsule) @@ -106,12 +111,24 @@ public Optional findPublicCapsuleSummaryDtosByMemberIdAndCaps .leftJoin(memberFriend).on(capsule.member.id.eq(memberFriend.owner.id) .or(capsule.member.id.eq(memberFriend.friend.id))) .where(capsule.id.eq(capsuleId).and(capsule.type.eq(CapsuleType.PUBLIC)) - .and(capsule.member.id.eq(memberId).or(memberFriend.friend.id.eq(memberId)))) + .and(eqMemberIdOrFriendId(memberId))) .groupBy(capsule.id) .fetchOne() ); } + private static BooleanExpression eqMemberIdOrFriendId(Long memberId) { + return eqMemberId(memberId).or(eqFriendId(memberId)); + } + + private static BooleanExpression eqMemberId(Long memberId) { + return capsule.member.id.eq(memberId); + } + + private static BooleanExpression eqFriendId(Long memberId) { + return memberFriend.friend.id.eq(memberId); + } + public Slice findPublicCapsulesDtoMadeByFriend( final Long memberId, final int size, diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleService.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleService.java index 75293a823..83f69f279 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleService.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleService.java @@ -11,6 +11,7 @@ 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.PublicCapsuleDetailDto; +import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.PublicCapsuleSummaryDto; import site.timecapsulearchive.core.domain.capsule.public_capsule.repository.PublicCapsuleQueryRepository; @Service @@ -44,7 +45,7 @@ private boolean capsuleNotOpened(final CapsuleDetailDto detailDto) { .isAfter(ZonedDateTime.now(ZoneOffset.UTC)); } - public CapsuleSummaryDto findPublicCapsuleSummaryByMemberIdAndCapsuleId( + public PublicCapsuleSummaryDto findPublicCapsuleSummaryByMemberIdAndCapsuleId( final Long memberId, final Long capsuleId ) { diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepositoryTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepositoryTest.java index bdab3a023..86d664263 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepositoryTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepositoryTest.java @@ -25,6 +25,7 @@ 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.PublicCapsuleDetailDto; +import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.PublicCapsuleSummaryDto; import site.timecapsulearchive.core.domain.capsuleskin.entity.CapsuleSkin; import site.timecapsulearchive.core.domain.friend.entity.MemberFriend; import site.timecapsulearchive.core.domain.member.entity.Member; @@ -140,22 +141,22 @@ void setup(@Autowired EntityManager entityManager) { void 친구가_공개_캡슐을_요약_조회하면_공개_캡슐_요약_내용을_볼_수_있다() { //given //when - Optional detailDto = publicCapsuleQueryRepository.findPublicCapsuleSummaryDtosByMemberIdAndCapsuleId( + Optional summaryDto = publicCapsuleQueryRepository.findPublicCapsuleSummaryDtosByMemberIdAndCapsuleId( friendId, friendCapsuleId); //then - assertThat(detailDto.isPresent()).isTrue(); + assertThat(summaryDto.isPresent()).isTrue(); } @Test void 친구가_아닌_사용자가_친구_캡슐을_요약_조회하면_친구_캡슐_요약_내용을_볼_수_없다() { //given //when - Optional detailDto = publicCapsuleQueryRepository.findPublicCapsuleSummaryDtosByMemberIdAndCapsuleId( + Optional summaryDto = publicCapsuleQueryRepository.findPublicCapsuleSummaryDtosByMemberIdAndCapsuleId( notFriendId, friendCapsuleId); //then - assertThat(detailDto.isEmpty()).isTrue(); + assertThat(summaryDto.isEmpty()).isTrue(); } @Test From 4e50f2152b925197a016375b3a18b5b9016428f3 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Fri, 5 Jul 2024 23:03:56 +0900 Subject: [PATCH 3/8] =?UTF-8?q?feat=20:=20=EA=B3=B5=EA=B0=9C=20=EC=BA=A1?= =?UTF-8?q?=EC=8A=90=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20=EC=BA=A1?= =?UTF-8?q?=EC=8A=90=20=EC=86=8C=EC=9C=A0=20=EC=9D=91=EB=8B=B5=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public_capsule/api/PublicCapsuleApi.java | 3 ++- .../api/PublicCapsuleApiController.java | 7 ++--- .../data/dto/PublicCapsuleDetailDto.java | 26 ++++++++++++++++++- .../response/PublicCapsuleDetailResponse.java | 20 +++++++++++++- .../PublicCapsuleQueryRepository.java | 22 +++++++--------- .../service/PublicCapsuleService.java | 6 ++--- .../common/fixture/dto/CapsuleDtoFixture.java | 12 +++++++++ .../PublicCapsuleQueryRepositoryTest.java | 6 ++--- .../service/PublicCapsuleServiceTest.java | 25 +++++++++--------- 9 files changed, 91 insertions(+), 36 deletions(-) diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApi.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApi.java index 2a33844bc..bb73c9ba9 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApi.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApi.java @@ -21,6 +21,7 @@ import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.response.CapsuleSummaryResponse; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.MyPublicCapsuleSliceResponse; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.reqeust.PublicCapsuleUpdateRequest; +import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.PublicCapsuleDetailResponse; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.PublicCapsuleSliceResponse; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.PublicCapsuleSummaryResponse; import site.timecapsulearchive.core.global.common.response.ApiSpec; @@ -107,7 +108,7 @@ ResponseEntity> getPublicCapsuleSummaryByI content = @Content(schema = @Schema(implementation = ErrorResponse.class)) ) }) - ResponseEntity> getPublicCapsuleDetailById( + ResponseEntity> getPublicCapsuleDetailById( Long memberId, @Parameter(in = ParameterIn.PATH, description = "조회할 캡슐 아이디", required = true, schema = @Schema()) diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApiController.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApiController.java index 11ca77c47..47de05f4e 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApiController.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/api/PublicCapsuleApiController.java @@ -26,6 +26,7 @@ import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.PublicCapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.PublicCapsuleSummaryDto; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.reqeust.PublicCapsuleUpdateRequest; +import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.PublicCapsuleDetailResponse; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.PublicCapsuleSliceResponse; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.PublicCapsuleSummaryResponse; import site.timecapsulearchive.core.domain.capsule.public_capsule.service.PublicCapsuleService; @@ -88,17 +89,17 @@ public ResponseEntity> getPublicCapsuleSum produces = {"application/json"} ) @Override - public ResponseEntity> getPublicCapsuleDetailById( + public ResponseEntity> getPublicCapsuleDetailById( @AuthenticationPrincipal final Long memberId, @PathVariable("capsule_id") final Long capsuleId ) { - final CapsuleDetailDto detailDto = publicCapsuleService.findPublicCapsuleDetailByMemberIdAndCapsuleId( + final PublicCapsuleDetailDto detailDto = publicCapsuleService.findPublicCapsuleDetailByMemberIdAndCapsuleId( memberId, capsuleId); return ResponseEntity.ok( ApiSpec.success( SuccessCode.SUCCESS, - CapsuleDetailResponse.createOf( + PublicCapsuleDetailResponse.createOf( detailDto, s3PreSignedUrlManager::getS3PreSignedUrlForGet, s3PreSignedUrlManager::getS3PreSignedUrlsForGet, diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/dto/PublicCapsuleDetailDto.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/dto/PublicCapsuleDetailDto.java index 84a3f0f40..4771ccfce 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/dto/PublicCapsuleDetailDto.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/dto/PublicCapsuleDetailDto.java @@ -5,6 +5,7 @@ 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.dto.CapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.PublicCapsuleDetailResponse; public record PublicCapsuleDetailDto( @@ -22,9 +23,31 @@ public record PublicCapsuleDetailDto( String images, String videos, Boolean isOpened, - CapsuleType capsuleType + CapsuleType capsuleType, + Boolean isOwner ) { + public PublicCapsuleDetailDto excludeTitleAndContentAndImagesAndVideos() { + return new PublicCapsuleDetailDto( + capsuleId, + capsuleSkinUrl, + dueDate, + nickname, + profileUrl, + createdAt, + point, + address, + roadName, + "", + "", + "", + "", + isOpened, + capsuleType, + isOwner + ); + } + public PublicCapsuleDetailResponse toResponse( final Function changePointFunction, final Function singlePreSignUrlFunction, @@ -51,6 +74,7 @@ public PublicCapsuleDetailResponse toResponse( .videoUrls(preSignedVideoUrls) .isOpened(isOpened) .capsuleType(capsuleType) + .isOwner(isOwner) .build(); } } diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/response/PublicCapsuleDetailResponse.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/response/PublicCapsuleDetailResponse.java index 606a03015..80e4dd239 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/response/PublicCapsuleDetailResponse.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/data/response/PublicCapsuleDetailResponse.java @@ -3,8 +3,13 @@ import io.swagger.v3.oas.annotations.media.Schema; 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.generic_capsule.data.response.CapsuleDetailResponse; +import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.PublicCapsuleDetailDto; import site.timecapsulearchive.core.global.common.response.ResponseMappingConstant; @Schema(description = "공개 캡슐 상세 정보") @@ -57,7 +62,10 @@ public record PublicCapsuleDetailResponse( Boolean isOpened, @Schema(description = "캡슐 타입") - CapsuleType capsuleType + CapsuleType capsuleType, + + @Schema(description = "캡슐 소유 여부") + Boolean isOwner ) { public PublicCapsuleDetailResponse { @@ -69,4 +77,14 @@ public record PublicCapsuleDetailResponse( createdDate = createdDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID); } } + + public static PublicCapsuleDetailResponse createOf( + final PublicCapsuleDetailDto detailDto, + final Function singlePreSignUrlFunction, + final Function> multiplePreSignUrlFunction, + final Function changePointFunction + ) { + return detailDto.toResponse(changePointFunction, singlePreSignUrlFunction, + multiplePreSignUrlFunction); + } } \ No newline at end of file diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java index 21b8f1dfd..c76ad7b50 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java @@ -34,14 +34,14 @@ public class PublicCapsuleQueryRepository { private final JPAQueryFactory jpaQueryFactory; - public Optional findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( + public Optional findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( final Long memberId, final Long capsuleId ) { - final CapsuleDetailDto detailDto = jpaQueryFactory + return Optional.ofNullable(jpaQueryFactory .select( Projections.constructor( - CapsuleDetailDto.class, + PublicCapsuleDetailDto.class, capsule.id, capsuleSkin.imageUrl, capsule.dueDate, @@ -56,7 +56,10 @@ public Optional findPublicCapsuleDetailDtosByMemberIdAndCapsul groupConcatDistinct(image.imageUrl), groupConcatDistinct(video.videoUrl), capsule.isOpened, - capsule.type + capsule.type, + new CaseBuilder() + .when(eqMemberId(memberId)).then(true) + .otherwise(false) ) ) .from(capsule) @@ -67,14 +70,9 @@ public Optional findPublicCapsuleDetailDtosByMemberIdAndCapsul .leftJoin(image).on(capsule.id.eq(image.capsule.id)) .leftJoin(video).on(capsule.id.eq(video.capsule.id)) .where(capsule.id.eq(capsuleId).and(capsule.type.eq(CapsuleType.PUBLIC)) - .and(capsule.member.id.eq(memberId).or(memberFriend.friend.id.eq(memberId)))) - .fetchFirst(); - - if (detailDto.capsuleId() == null) { - return Optional.empty(); - } - - return Optional.of(detailDto); + .and(eqMemberIdOrFriendId(memberId))) + .fetchFirst() + ); } private StringExpression groupConcatDistinct(final StringExpression expression) { diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleService.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleService.java index 83f69f279..aca4d41f9 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleService.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleService.java @@ -21,11 +21,11 @@ public class PublicCapsuleService { private final PublicCapsuleQueryRepository publicCapsuleQueryRepository; - public CapsuleDetailDto findPublicCapsuleDetailByMemberIdAndCapsuleId( + public PublicCapsuleDetailDto findPublicCapsuleDetailByMemberIdAndCapsuleId( final Long memberId, final Long capsuleId ) { - final CapsuleDetailDto detailDto = publicCapsuleQueryRepository.findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( + final PublicCapsuleDetailDto detailDto = publicCapsuleQueryRepository.findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( memberId, capsuleId) .orElseThrow(CapsuleNotFondException::new); @@ -36,7 +36,7 @@ public CapsuleDetailDto findPublicCapsuleDetailByMemberIdAndCapsuleId( return detailDto; } - private boolean capsuleNotOpened(final CapsuleDetailDto detailDto) { + private boolean capsuleNotOpened(final PublicCapsuleDetailDto detailDto) { if (detailDto.dueDate() == null) { return false; } diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/CapsuleDtoFixture.java b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/CapsuleDtoFixture.java index 77185d08a..7362974f4 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/CapsuleDtoFixture.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/CapsuleDtoFixture.java @@ -8,6 +8,8 @@ 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.public_capsule.data.dto.PublicCapsuleDetailDto; +import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.PublicCapsuleDetailResponse; public class CapsuleDtoFixture { @@ -22,6 +24,16 @@ public static Optional getCapsuleDetailDto(Long capsuleId, Boo ); } + public static Optional getPublicCapsuleDetailDto(Long capsuleId, Boolean isOpened, + ZonedDateTime dueDate) { + return Optional.of( + new PublicCapsuleDetailDto(capsuleId, "test", dueDate, "testNickname", "testUrl", now, + null, "testAddress", "testRoadName", "testTitle", "testContent", "testImages", + "testVideos", isOpened, CapsuleType.PUBLIC, true) + ); + } + + public static Optional getGroupCapsuleDetailDto(Long capsuleId, boolean isOpened, ZonedDateTime now, int count) { return Optional.of( diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepositoryTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepositoryTest.java index 86d664263..d09cdf8a1 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepositoryTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepositoryTest.java @@ -108,7 +108,7 @@ void setup(@Autowired EntityManager entityManager) { void 친구가_공개_캡슐을_상세_조회하면_공개_캡슐_상세_내용을_볼_수_있다() { //given //when - Optional detailDto = publicCapsuleQueryRepository.findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( + Optional detailDto = publicCapsuleQueryRepository.findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( friendId, myCapsuleId); //then @@ -119,7 +119,7 @@ void setup(@Autowired EntityManager entityManager) { void 친구가_아닌_사용자가_친구_캡슐을_상세_조회하면_친구_캡슐_상세_내용을_볼_수_없다() { //given //when - Optional detailDto = publicCapsuleQueryRepository.findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( + Optional detailDto = publicCapsuleQueryRepository.findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( notFriendId, friendCapsuleId); //then @@ -130,7 +130,7 @@ void setup(@Autowired EntityManager entityManager) { void 사용자가_만든_공개_캡슐을_상세_조회하면_공개_캡슐_상세_내용을_볼_수_있다() { //given //when - Optional detailDto = publicCapsuleQueryRepository.findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( + Optional detailDto = publicCapsuleQueryRepository.findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( memberId, myCapsuleId); //then diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleServiceTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleServiceTest.java index d8825c179..b732a53ed 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleServiceTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/public_capsule/service/PublicCapsuleServiceTest.java @@ -10,6 +10,7 @@ import org.springframework.context.annotation.Import; import site.timecapsulearchive.core.common.fixture.dto.CapsuleDtoFixture; import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleDetailDto; +import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.PublicCapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.public_capsule.repository.PublicCapsuleQueryRepository; import site.timecapsulearchive.core.global.geography.GeoTransformConfig; import site.timecapsulearchive.core.infra.s3.config.S3Config; @@ -34,10 +35,10 @@ class PublicCapsuleServiceTest { given(publicCapsuleQueryRepository.findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( anyLong(), anyLong())) .willReturn( - CapsuleDtoFixture.getCapsuleDetailDto(capsuleId, true, ZonedDateTime.now())); + CapsuleDtoFixture.getPublicCapsuleDetailDto(capsuleId, true, ZonedDateTime.now())); //when - CapsuleDetailDto response = publicCapsuleService.findPublicCapsuleDetailByMemberIdAndCapsuleId( + PublicCapsuleDetailDto response = publicCapsuleService.findPublicCapsuleDetailByMemberIdAndCapsuleId( memberId, capsuleId); //then @@ -56,10 +57,10 @@ class PublicCapsuleServiceTest { //given given(publicCapsuleQueryRepository.findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( anyLong(), anyLong())) - .willReturn(CapsuleDtoFixture.getCapsuleDetailDto(capsuleId, true, null)); + .willReturn(CapsuleDtoFixture.getPublicCapsuleDetailDto(capsuleId, true, null)); //when - CapsuleDetailDto response = publicCapsuleService.findPublicCapsuleDetailByMemberIdAndCapsuleId( + PublicCapsuleDetailDto response = publicCapsuleService.findPublicCapsuleDetailByMemberIdAndCapsuleId( memberId, capsuleId); //then @@ -78,10 +79,10 @@ class PublicCapsuleServiceTest { //given given(publicCapsuleQueryRepository.findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( anyLong(), anyLong())) - .willReturn(CapsuleDtoFixture.getCapsuleDetailDto(capsuleId, false, null)); + .willReturn(CapsuleDtoFixture.getPublicCapsuleDetailDto(capsuleId, false, null)); //when - CapsuleDetailDto response = publicCapsuleService.findPublicCapsuleDetailByMemberIdAndCapsuleId( + PublicCapsuleDetailDto response = publicCapsuleService.findPublicCapsuleDetailByMemberIdAndCapsuleId( memberId, capsuleId); //then @@ -100,11 +101,11 @@ class PublicCapsuleServiceTest { //given given(publicCapsuleQueryRepository.findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( anyLong(), anyLong())) - .willReturn(CapsuleDtoFixture.getCapsuleDetailDto(capsuleId, false, + .willReturn(CapsuleDtoFixture.getPublicCapsuleDetailDto(capsuleId, false, ZonedDateTime.now().minusDays(5))); //when - CapsuleDetailDto response = publicCapsuleService.findPublicCapsuleDetailByMemberIdAndCapsuleId( + PublicCapsuleDetailDto response = publicCapsuleService.findPublicCapsuleDetailByMemberIdAndCapsuleId( memberId, capsuleId); //then @@ -121,11 +122,11 @@ class PublicCapsuleServiceTest { //given given(publicCapsuleQueryRepository.findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( anyLong(), anyLong())) - .willReturn(CapsuleDtoFixture.getCapsuleDetailDto(capsuleId, false, + .willReturn(CapsuleDtoFixture.getPublicCapsuleDetailDto(capsuleId, false, ZonedDateTime.now().plusDays(5))); //when - CapsuleDetailDto response = publicCapsuleService.findPublicCapsuleDetailByMemberIdAndCapsuleId( + PublicCapsuleDetailDto response = publicCapsuleService.findPublicCapsuleDetailByMemberIdAndCapsuleId( memberId, capsuleId); //then @@ -142,11 +143,11 @@ class PublicCapsuleServiceTest { //given given(publicCapsuleQueryRepository.findPublicCapsuleDetailDtosByMemberIdAndCapsuleId( anyLong(), anyLong())) - .willReturn(CapsuleDtoFixture.getCapsuleDetailDto(capsuleId, true, + .willReturn(CapsuleDtoFixture.getPublicCapsuleDetailDto(capsuleId, true, ZonedDateTime.now().plusDays(5))); //when - CapsuleDetailDto response = publicCapsuleService.findPublicCapsuleDetailByMemberIdAndCapsuleId( + PublicCapsuleDetailDto response = publicCapsuleService.findPublicCapsuleDetailByMemberIdAndCapsuleId( memberId, capsuleId); //then From 6cce258a019602047211d819600abe1d8ed3f8cb Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sat, 6 Jul 2024 00:57:21 +0900 Subject: [PATCH 4/8] =?UTF-8?q?feat=20:=20=EA=B7=B8=EB=A3=B9=20=EC=BA=A1?= =?UTF-8?q?=EC=8A=90=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95,=20=EC=82=AD=EC=A0=9C=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/GroupCapsuleApiController.java | 10 +- .../dto/CombinedGroupCapsuleDetailDto.java | 104 ++++++++++++++++++ .../data/dto/GroupCapsuleDetailDto.java | 88 +++++++++------ .../dto/GroupCapsuleWithMemberDetailDto.java | 18 +++ .../response/GroupCapsuleDetailResponse.java | 34 ++++-- .../GroupCapsuleQueryRepository.java | 11 +- .../service/GroupCapsuleService.java | 46 ++++++-- .../domain/GroupCapsuleOpenFixture.java | 2 +- .../common/fixture/dto/CapsuleDtoFixture.java | 7 +- .../GroupCapsuleQueryRepositoryTest.java | 10 +- .../service/GroupCapsuleServiceTest.java | 26 ++--- 11 files changed, 273 insertions(+), 83 deletions(-) create mode 100644 backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/CombinedGroupCapsuleDetailDto.java create mode 100644 backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/GroupCapsuleWithMemberDetailDto.java diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/api/GroupCapsuleApiController.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/api/GroupCapsuleApiController.java index 807516e33..c4bfdeee1 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/api/GroupCapsuleApiController.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/api/GroupCapsuleApiController.java @@ -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; @@ -72,16 +72,16 @@ public ResponseEntity> 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 ) ) diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/CombinedGroupCapsuleDetailDto.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/CombinedGroupCapsuleDetailDto.java new file mode 100644 index 000000000..cb78b2d7a --- /dev/null +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/CombinedGroupCapsuleDetailDto.java @@ -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 groupMembers +) { + + public static CombinedGroupCapsuleDetailDto create( + final GroupCapsuleDetailDto groupCapsuleDetailDto, + final List 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> multiplePreSignUrlFunction, + final UnaryOperator preSignUrlFunction, + final UnaryOperator changePointFunction + ) { + final Point changePoint = changePointFunction.apply(point); + + final List 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(); + } + +} diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/GroupCapsuleDetailDto.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/GroupCapsuleDetailDto.java index e7e83d422..1e32ed0d8 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/GroupCapsuleDetailDto.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/GroupCapsuleDetailDto.java @@ -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 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 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 singlePreSignUrlFunction, final Function> multiplePreSignUrlFunction, final Function changePointFunction ) { - final Point changePoint = changePointFunction.apply(capsuleDetailDto.point()); - final List preSignedImageUrls = multiplePreSignUrlFunction.apply( - capsuleDetailDto.images()); + images); final List 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(); } } diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/GroupCapsuleWithMemberDetailDto.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/GroupCapsuleWithMemberDetailDto.java new file mode 100644 index 000000000..b296976b1 --- /dev/null +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/dto/GroupCapsuleWithMemberDetailDto.java @@ -0,0 +1,18 @@ +package site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto; + +import java.util.List; + +public record GroupCapsuleWithMemberDetailDto( + GroupCapsuleDetailDto groupCapsuleDetailDto, + List members +) { + + public GroupCapsuleWithMemberDetailDto excludeDetailContents() { + return new GroupCapsuleWithMemberDetailDto( + groupCapsuleDetailDto.excludeTitleAndContentAndImagesAndVideos(), + members + ); + } + + +} diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/response/GroupCapsuleDetailResponse.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/response/GroupCapsuleDetailResponse.java index fba1be05b..92e1fc841 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/response/GroupCapsuleDetailResponse.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/data/response/GroupCapsuleDetailResponse.java @@ -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, @@ -59,11 +63,20 @@ public record GroupCapsuleDetailResponse( @Schema(description = "비디오 url들") List 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 { @@ -75,13 +88,16 @@ public record GroupCapsuleDetailResponse( } public static GroupCapsuleDetailResponse createOf( - final GroupCapsuleDetailDto groupCapsuleDetailDto, - final Function singlePreSignUrlFunction, + final CombinedGroupCapsuleDetailDto groupCapsuleDetailDto, final Function> multiplePreSignUrlFunction, - final Function changePointFunction + final UnaryOperator singlePreSignUrlFunction, + final UnaryOperator changePointFunction ) { - return groupCapsuleDetailDto.toResponse(singlePreSignUrlFunction, - multiplePreSignUrlFunction, changePointFunction); + return groupCapsuleDetailDto.toResponse( + multiplePreSignUrlFunction, + singlePreSignUrlFunction, + changePointFunction + ); } } \ No newline at end of file diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepository.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepository.java index a96e7f89b..e081704f5 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepository.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepository.java @@ -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; @@ -37,7 +37,7 @@ public class GroupCapsuleQueryRepository { private final JPAQueryFactory jpaQueryFactory; - public Optional findGroupCapsuleDetailDtoByCapsuleId( + public Optional findGroupCapsuleDetailDtoByCapsuleId( final Long capsuleId ) { final QMember owner = new QMember("owner"); @@ -47,6 +47,7 @@ public Optional 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)) @@ -57,12 +58,14 @@ public Optional 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, diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleService.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleService.java index 29b858cc5..29ec3f695 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleService.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleService.java @@ -15,13 +15,14 @@ import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.capsule.CapsuleRepository; import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.image.ImageRepository; import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.video.VideoRepository; +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.GroupCapsuleCreateRequestDto; -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.dto.GroupCapsuleSummaryDto; +import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleWithMemberDetailDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.repository.GroupCapsuleOpenRepository; import site.timecapsulearchive.core.domain.capsule.group_capsule.repository.GroupCapsuleQueryRepository; import site.timecapsulearchive.core.domain.capsuleskin.entity.CapsuleSkin; @@ -58,26 +59,53 @@ public Capsule saveGroupCapsule( return capsule; } - public GroupCapsuleDetailDto findGroupCapsuleDetailByGroupIdAndCapsuleId( + public CombinedGroupCapsuleDetailDto findGroupCapsuleDetailByGroupIdAndCapsuleId( + final Long memberId, final Long capsuleId ) { - final GroupCapsuleDetailDto detailDto = groupCapsuleQueryRepository.findGroupCapsuleDetailDtoByCapsuleId( + final GroupCapsuleWithMemberDetailDto groupCapsuleWithMemberDetailDto = groupCapsuleQueryRepository.findGroupCapsuleDetailDtoByCapsuleId( capsuleId) .orElseThrow(CapsuleNotFondException::new); - if (capsuleNotOpened(detailDto)) { - return detailDto.excludeDetailContents(); + List groupCapsuleMembers = memberGroupRepository.findGroupCapsuleMembers( + groupCapsuleWithMemberDetailDto.groupCapsuleDetailDto().groupId(), capsuleId); + + GroupCapsuleMemberDto requestMember = groupCapsuleMembers.stream() + .filter(dto -> memberId.equals(dto.id())) + .findAny() + .orElseThrow(NoGroupAuthorityException::new); + + Boolean hasEditPermission = requestMember.id() + .equals(groupCapsuleWithMemberDetailDto.groupCapsuleDetailDto().creatorId()); + Boolean hasDeletePermission = hasEditPermission || requestMember.isGroupOwner(); + + if (capsuleNotOpened(groupCapsuleWithMemberDetailDto)) { + GroupCapsuleWithMemberDetailDto excludeDetailContentsDto = groupCapsuleWithMemberDetailDto.excludeDetailContents(); + return CombinedGroupCapsuleDetailDto.create( + excludeDetailContentsDto.groupCapsuleDetailDto(), + excludeDetailContentsDto.members(), + requestMember.isOpened(), + hasEditPermission, + hasDeletePermission + ); } - return detailDto; + return CombinedGroupCapsuleDetailDto.create( + groupCapsuleWithMemberDetailDto.groupCapsuleDetailDto(), + groupCapsuleWithMemberDetailDto.members(), + requestMember.isOpened(), + hasEditPermission, + hasDeletePermission + ); } - private boolean capsuleNotOpened(final GroupCapsuleDetailDto detailDto) { - if (detailDto.capsuleDetailDto().dueDate() == null) { + private boolean capsuleNotOpened(final GroupCapsuleWithMemberDetailDto detailDto) { + if (detailDto.groupCapsuleDetailDto().dueDate() == null) { return false; } - return !detailDto.capsuleDetailDto().isOpened() || detailDto.capsuleDetailDto().dueDate() + return !detailDto.groupCapsuleDetailDto().isCapsuleOpened() + || detailDto.groupCapsuleDetailDto().dueDate() .isAfter(ZonedDateTime.now(ZoneOffset.UTC)); } diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/GroupCapsuleOpenFixture.java b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/GroupCapsuleOpenFixture.java index 7a4c17ff8..00c0a67b0 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/GroupCapsuleOpenFixture.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/GroupCapsuleOpenFixture.java @@ -37,7 +37,7 @@ private static GroupCapsuleOpen getGroupCapsuleOpen( GroupCapsuleOpen groupCapsuleOpen = declaredConstructor.newInstance(); setFieldValue(groupCapsuleOpen, "group", group); setFieldValue(groupCapsuleOpen, "capsule", capsule); - setFieldValue(groupCapsuleOpen, "isOpened", isOpened); + setFieldValue(groupCapsuleOpen, "isCapsuleOpened", isOpened); setFieldValue(groupCapsuleOpen, "member", member); return groupCapsuleOpen; } catch (Exception e) { diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/CapsuleDtoFixture.java b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/CapsuleDtoFixture.java index 7362974f4..65805498a 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/CapsuleDtoFixture.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/CapsuleDtoFixture.java @@ -6,10 +6,9 @@ import java.util.stream.IntStream; 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.GroupCapsuleWithMemberDetailDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleMemberSummaryDto; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.PublicCapsuleDetailDto; -import site.timecapsulearchive.core.domain.capsule.public_capsule.data.response.PublicCapsuleDetailResponse; public class CapsuleDtoFixture { @@ -34,10 +33,10 @@ public static Optional getPublicCapsuleDetailDto(Long ca } - public static Optional getGroupCapsuleDetailDto(Long capsuleId, + public static Optional getGroupCapsuleDetailDto(Long capsuleId, boolean isOpened, ZonedDateTime now, int count) { return Optional.of( - new GroupCapsuleDetailDto(getCapsuleDetailDto(capsuleId, isOpened, now).get(), + new GroupCapsuleWithMemberDetailDto(getCapsuleDetailDto(capsuleId, isOpened, now).get(), getGroupMemberSummaryDtos(count))); } diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java index 8ffe2af6f..fea29e413 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java @@ -27,7 +27,7 @@ import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType; import site.timecapsulearchive.core.domain.capsule.entity.GroupCapsuleOpen; 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.GroupCapsuleWithMemberDetailDto; 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; @@ -93,9 +93,9 @@ void setup(@Autowired EntityManager entityManager) { void 그룹캡슐_아이디로_그룹_캡슐의_상세_조회_하면_상세_내용을_조회할_수_있다() { // given //when - GroupCapsuleDetailDto groupCapsuleDetailDto = groupCapsuleQueryRepository.findGroupCapsuleDetailDtoByCapsuleId( + GroupCapsuleWithMemberDetailDto groupCapsuleDetailDto = groupCapsuleQueryRepository.findGroupCapsuleDetailDtoByCapsuleId( capsule.getId()).orElseThrow(); - CapsuleDetailDto capsuleDetailDto = groupCapsuleDetailDto.capsuleDetailDto(); + CapsuleDetailDto capsuleDetailDto = groupCapsuleDetailDto.groupCapsuleDetailDto(); //then assertSoftly( @@ -113,7 +113,7 @@ void setup(@Autowired EntityManager entityManager) { void 그룹캡슐_아이디로_그룹_캡슐의_상세_조회_하면_그룹원_정보를_조회할_수_있다() { //given //when - GroupCapsuleDetailDto detailDto = groupCapsuleQueryRepository.findGroupCapsuleDetailDtoByCapsuleId( + GroupCapsuleWithMemberDetailDto detailDto = groupCapsuleQueryRepository.findGroupCapsuleDetailDtoByCapsuleId( capsule.getId()).orElseThrow(); List summaryDto = detailDto.members(); @@ -133,7 +133,7 @@ void setup(@Autowired EntityManager entityManager) { Long notCapsuleId = -1L; //when - Optional detailDto = groupCapsuleQueryRepository.findGroupCapsuleDetailDtoByCapsuleId( + Optional detailDto = groupCapsuleQueryRepository.findGroupCapsuleDetailDtoByCapsuleId( notCapsuleId); //then diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleServiceTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleServiceTest.java index 022f6639f..56bf35702 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleServiceTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleServiceTest.java @@ -31,7 +31,7 @@ import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.video.VideoRepository; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.CapsuleOpenStatus; 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.GroupCapsuleWithMemberDetailDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleMemberDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleMemberSummaryDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleOpenStateDto; @@ -71,12 +71,12 @@ class GroupCapsuleServiceTest { ); //when - GroupCapsuleDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( + GroupCapsuleWithMemberDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( capsuleId); //then assertSoftly(softly -> { - CapsuleDetailDto detailDto = response.capsuleDetailDto(); + CapsuleDetailDto detailDto = response.groupCapsuleDetailDto(); List members = response.members(); softly.assertThat(response).isNotNull(); softly.assertThat(detailDto.isOpened()).isTrue(); @@ -97,12 +97,12 @@ class GroupCapsuleServiceTest { ); //when - GroupCapsuleDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( + GroupCapsuleWithMemberDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( capsuleId); //then assertSoftly(softly -> { - CapsuleDetailDto detailDto = response.capsuleDetailDto(); + CapsuleDetailDto detailDto = response.groupCapsuleDetailDto(); List members = response.members(); softly.assertThat(response).isNotNull(); softly.assertThat(detailDto.isOpened()).isTrue(); @@ -123,12 +123,12 @@ class GroupCapsuleServiceTest { ); //when - GroupCapsuleDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( + GroupCapsuleWithMemberDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( capsuleId); //then assertSoftly(softly -> { - CapsuleDetailDto detailDto = response.capsuleDetailDto(); + CapsuleDetailDto detailDto = response.groupCapsuleDetailDto(); List members = response.members(); softly.assertThat(response).isNotNull(); softly.assertThat(detailDto.isOpened()).isFalse(); @@ -150,12 +150,12 @@ class GroupCapsuleServiceTest { ); //when - GroupCapsuleDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( + GroupCapsuleWithMemberDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( capsuleId); //then assertSoftly(softly -> { - CapsuleDetailDto detailDto = response.capsuleDetailDto(); + CapsuleDetailDto detailDto = response.groupCapsuleDetailDto(); List members = response.members(); softly.assertThat(response).isNotNull(); softly.assertThat(detailDto.isOpened()).isFalse(); @@ -175,12 +175,12 @@ class GroupCapsuleServiceTest { ); //when - GroupCapsuleDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( + GroupCapsuleWithMemberDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( capsuleId); //then assertSoftly(softly -> { - CapsuleDetailDto detailDto = response.capsuleDetailDto(); + CapsuleDetailDto detailDto = response.groupCapsuleDetailDto(); List members = response.members(); softly.assertThat(response).isNotNull(); softly.assertThat(detailDto.isOpened()).isFalse(); @@ -200,12 +200,12 @@ class GroupCapsuleServiceTest { ); //when - GroupCapsuleDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( + GroupCapsuleWithMemberDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( capsuleId); //then assertSoftly(softly -> { - CapsuleDetailDto detailDto = response.capsuleDetailDto(); + CapsuleDetailDto detailDto = response.groupCapsuleDetailDto(); List members = response.members(); softly.assertThat(response).isNotNull(); softly.assertThat(detailDto.isOpened()).isTrue(); From bce7d5207aff553b0cf058112c611841ed56c35f Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sat, 6 Jul 2024 01:17:48 +0900 Subject: [PATCH 5/8] =?UTF-8?q?test=20:=20=EA=B7=B8=EB=A3=B9=20=EC=BA=A1?= =?UTF-8?q?=EC=8A=90=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=8B=A4=ED=8C=A8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/GroupCapsuleOpenFixture.java | 2 +- .../common/fixture/dto/CapsuleDtoFixture.java | 14 +- .../GroupCapsuleQueryRepositoryTest.java | 3 +- .../service/GroupCapsuleServiceTest.java | 120 +++++++----------- 4 files changed, 62 insertions(+), 77 deletions(-) diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/GroupCapsuleOpenFixture.java b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/GroupCapsuleOpenFixture.java index 00c0a67b0..7a4c17ff8 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/GroupCapsuleOpenFixture.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/GroupCapsuleOpenFixture.java @@ -37,7 +37,7 @@ private static GroupCapsuleOpen getGroupCapsuleOpen( GroupCapsuleOpen groupCapsuleOpen = declaredConstructor.newInstance(); setFieldValue(groupCapsuleOpen, "group", group); setFieldValue(groupCapsuleOpen, "capsule", capsule); - setFieldValue(groupCapsuleOpen, "isCapsuleOpened", isOpened); + setFieldValue(groupCapsuleOpen, "isOpened", isOpened); setFieldValue(groupCapsuleOpen, "member", member); return groupCapsuleOpen; } catch (Exception e) { diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/CapsuleDtoFixture.java b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/CapsuleDtoFixture.java index 65805498a..84fd157c1 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/CapsuleDtoFixture.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/CapsuleDtoFixture.java @@ -6,6 +6,7 @@ import java.util.stream.IntStream; 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.GroupCapsuleWithMemberDetailDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleMemberSummaryDto; import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.PublicCapsuleDetailDto; @@ -32,11 +33,20 @@ public static Optional getPublicCapsuleDetailDto(Long ca ); } + public static Optional getGroupCapsuleDetailDto(Long groupId, Long capsuleId, Boolean isOpened, + ZonedDateTime dueDate) { + return Optional.of( + new GroupCapsuleDetailDto(groupId, capsuleId, "testCapsuleSkinUrl", dueDate, 1L, "testNickName", "testProfileUrl", + null, null, "testAddressName", "testRoadName", "testTitle", "testContent", + "testImages", "testVideos", isOpened, CapsuleType.PUBLIC) + ); + } + - public static Optional getGroupCapsuleDetailDto(Long capsuleId, + public static Optional getGroupCapsuleWithMemberDetailDto(Long groupId, Long capsuleId, boolean isOpened, ZonedDateTime now, int count) { return Optional.of( - new GroupCapsuleWithMemberDetailDto(getCapsuleDetailDto(capsuleId, isOpened, now).get(), + new GroupCapsuleWithMemberDetailDto(getGroupCapsuleDetailDto(groupId, capsuleId, isOpened, now).get(), getGroupMemberSummaryDtos(count))); } diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java index fea29e413..eea4a8afe 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java @@ -27,6 +27,7 @@ import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType; import site.timecapsulearchive.core.domain.capsule.entity.GroupCapsuleOpen; 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.GroupCapsuleWithMemberDetailDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleMemberSummaryDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleSliceRequestDto; @@ -95,7 +96,7 @@ void setup(@Autowired EntityManager entityManager) { //when GroupCapsuleWithMemberDetailDto groupCapsuleDetailDto = groupCapsuleQueryRepository.findGroupCapsuleDetailDtoByCapsuleId( capsule.getId()).orElseThrow(); - CapsuleDetailDto capsuleDetailDto = groupCapsuleDetailDto.groupCapsuleDetailDto(); + GroupCapsuleDetailDto capsuleDetailDto = groupCapsuleDetailDto.groupCapsuleDetailDto(); //then assertSoftly( diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleServiceTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleServiceTest.java index 56bf35702..457a8032a 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleServiceTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/service/GroupCapsuleServiceTest.java @@ -25,15 +25,13 @@ import site.timecapsulearchive.core.domain.capsule.entity.Capsule; import site.timecapsulearchive.core.domain.capsule.exception.CapsuleNotFondException; import site.timecapsulearchive.core.domain.capsule.exception.GroupCapsuleOpenNotFoundException; -import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CapsuleDetailDto; import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.capsule.CapsuleRepository; import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.image.ImageRepository; import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.video.VideoRepository; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.CapsuleOpenStatus; +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.GroupCapsuleWithMemberDetailDto; import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleMemberDto; -import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleMemberSummaryDto; 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.repository.GroupCapsuleOpenRepository; @@ -47,7 +45,7 @@ class GroupCapsuleServiceTest { private final Long capsuleId = 1L; private final Long memberId = 1L; - private final int groupMemberCount = 3; + private final Long groupId = 1L; private final CapsuleRepository capsuleRepository = mock(CapsuleRepository.class); private final GroupCapsuleQueryRepository groupCapsuleQueryRepository = mock( @@ -67,25 +65,18 @@ class GroupCapsuleServiceTest { //given given( groupCapsuleQueryRepository.findGroupCapsuleDetailDtoByCapsuleId(anyLong())).willReturn( - CapsuleDtoFixture.getGroupCapsuleDetailDto(capsuleId, true, ZonedDateTime.now(), 3) + CapsuleDtoFixture.getGroupCapsuleWithMemberDetailDto(groupId, capsuleId, true, + ZonedDateTime.now(), 3) ); + given(memberGroupRepository.findGroupCapsuleMembers(groupId, capsuleId)).willReturn( + GroupCapsuleMemberDtoFixture.members(1, 3, false)); //when - GroupCapsuleWithMemberDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( - capsuleId); + CombinedGroupCapsuleDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( + memberId, capsuleId); //then - assertSoftly(softly -> { - CapsuleDetailDto detailDto = response.groupCapsuleDetailDto(); - List members = response.members(); - softly.assertThat(response).isNotNull(); - softly.assertThat(detailDto.isOpened()).isTrue(); - softly.assertThat(detailDto.title()).isNotBlank(); - softly.assertThat(detailDto.content()).isNotBlank(); - softly.assertThat(detailDto.images()).isNotBlank(); - softly.assertThat(detailDto.videos()).isNotBlank(); - softly.assertThat(members.size()).isEqualTo(groupMemberCount); - }); + assertThat(response).isNotNull(); } @Test @@ -93,25 +84,18 @@ class GroupCapsuleServiceTest { //given given( groupCapsuleQueryRepository.findGroupCapsuleDetailDtoByCapsuleId(anyLong())).willReturn( - CapsuleDtoFixture.getGroupCapsuleDetailDto(capsuleId, true, null, 3) + CapsuleDtoFixture.getGroupCapsuleWithMemberDetailDto(groupId, capsuleId, true, null, 3) ); + given(memberGroupRepository.findGroupCapsuleMembers(groupId, capsuleId)).willReturn( + GroupCapsuleMemberDtoFixture.members(1, 3, false)); + //when - GroupCapsuleWithMemberDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( - capsuleId); + CombinedGroupCapsuleDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( + memberId, capsuleId); //then - assertSoftly(softly -> { - CapsuleDetailDto detailDto = response.groupCapsuleDetailDto(); - List members = response.members(); - softly.assertThat(response).isNotNull(); - softly.assertThat(detailDto.isOpened()).isTrue(); - softly.assertThat(detailDto.title()).isNotBlank(); - softly.assertThat(detailDto.content()).isNotBlank(); - softly.assertThat(detailDto.images()).isNotBlank(); - softly.assertThat(detailDto.videos()).isNotBlank(); - softly.assertThat(members.size()).isEqualTo(groupMemberCount); - }); + assertThat(response).isNotNull(); } @Test @@ -119,25 +103,18 @@ class GroupCapsuleServiceTest { //given given( groupCapsuleQueryRepository.findGroupCapsuleDetailDtoByCapsuleId(anyLong())).willReturn( - CapsuleDtoFixture.getGroupCapsuleDetailDto(capsuleId, false, null, 3) + CapsuleDtoFixture.getGroupCapsuleWithMemberDetailDto(groupId, capsuleId, false, null, 3) ); + given(memberGroupRepository.findGroupCapsuleMembers(groupId, capsuleId)).willReturn( + GroupCapsuleMemberDtoFixture.members(1, 3, false)); + //when - GroupCapsuleWithMemberDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( - capsuleId); + CombinedGroupCapsuleDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( + memberId, capsuleId); //then - assertSoftly(softly -> { - CapsuleDetailDto detailDto = response.groupCapsuleDetailDto(); - List members = response.members(); - softly.assertThat(response).isNotNull(); - softly.assertThat(detailDto.isOpened()).isFalse(); - softly.assertThat(detailDto.title()).isNotBlank(); - softly.assertThat(detailDto.content()).isNotBlank(); - softly.assertThat(detailDto.images()).isNotBlank(); - softly.assertThat(detailDto.videos()).isNotBlank(); - softly.assertThat(members.size()).isEqualTo(groupMemberCount); - }); + assertThat(response).isNotNull(); } @Test @@ -145,23 +122,22 @@ class GroupCapsuleServiceTest { //given given( groupCapsuleQueryRepository.findGroupCapsuleDetailDtoByCapsuleId(anyLong())).willReturn( - CapsuleDtoFixture.getGroupCapsuleDetailDto(capsuleId, false, + CapsuleDtoFixture.getGroupCapsuleWithMemberDetailDto(groupId, capsuleId, false, ZonedDateTime.now().minusDays(5), 3) ); + given(memberGroupRepository.findGroupCapsuleMembers(groupId, capsuleId)).willReturn( + GroupCapsuleMemberDtoFixture.members(1, 3, false)); + //when - GroupCapsuleWithMemberDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( - capsuleId); + CombinedGroupCapsuleDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( + memberId, capsuleId); //then assertSoftly(softly -> { - CapsuleDetailDto detailDto = response.groupCapsuleDetailDto(); - List members = response.members(); softly.assertThat(response).isNotNull(); - softly.assertThat(detailDto.isOpened()).isFalse(); - softly.assertThat(detailDto.images()).isNullOrEmpty(); - softly.assertThat(detailDto.videos()).isNullOrEmpty(); - softly.assertThat(members.size()).isEqualTo(groupMemberCount); + softly.assertThat(response.images()).isNullOrEmpty(); + softly.assertThat(response.videos()).isNullOrEmpty(); }); } @@ -170,23 +146,22 @@ class GroupCapsuleServiceTest { //given given( groupCapsuleQueryRepository.findGroupCapsuleDetailDtoByCapsuleId(anyLong())).willReturn( - CapsuleDtoFixture.getGroupCapsuleDetailDto(capsuleId, false, + CapsuleDtoFixture.getGroupCapsuleWithMemberDetailDto(groupId, capsuleId, false, ZonedDateTime.now().plusDays(5), 3) ); + given(memberGroupRepository.findGroupCapsuleMembers(groupId, capsuleId)).willReturn( + GroupCapsuleMemberDtoFixture.members(1, 3, false)); + //when - GroupCapsuleWithMemberDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( - capsuleId); + CombinedGroupCapsuleDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( + memberId, capsuleId); //then assertSoftly(softly -> { - CapsuleDetailDto detailDto = response.groupCapsuleDetailDto(); - List members = response.members(); softly.assertThat(response).isNotNull(); - softly.assertThat(detailDto.isOpened()).isFalse(); - softly.assertThat(detailDto.images()).isNullOrEmpty(); - softly.assertThat(detailDto.videos()).isNullOrEmpty(); - softly.assertThat(members.size()).isEqualTo(groupMemberCount); + softly.assertThat(response.images()).isNullOrEmpty(); + softly.assertThat(response.videos()).isNullOrEmpty(); }); } @@ -195,23 +170,22 @@ class GroupCapsuleServiceTest { //given given( groupCapsuleQueryRepository.findGroupCapsuleDetailDtoByCapsuleId(anyLong())).willReturn( - CapsuleDtoFixture.getGroupCapsuleDetailDto(capsuleId, true, + CapsuleDtoFixture.getGroupCapsuleWithMemberDetailDto(groupId, capsuleId, true, ZonedDateTime.now().plusDays(5), 3) ); + given(memberGroupRepository.findGroupCapsuleMembers(groupId, capsuleId)).willReturn( + GroupCapsuleMemberDtoFixture.members(1, 3, false)); + //when - GroupCapsuleWithMemberDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( - capsuleId); + CombinedGroupCapsuleDetailDto response = groupCapsuleService.findGroupCapsuleDetailByGroupIdAndCapsuleId( + memberId, capsuleId); //then assertSoftly(softly -> { - CapsuleDetailDto detailDto = response.groupCapsuleDetailDto(); - List members = response.members(); softly.assertThat(response).isNotNull(); - softly.assertThat(detailDto.isOpened()).isTrue(); - softly.assertThat(detailDto.images()).isNullOrEmpty(); - softly.assertThat(detailDto.videos()).isNullOrEmpty(); - softly.assertThat(members.size()).isEqualTo(groupMemberCount); + softly.assertThat(response.images()).isNullOrEmpty(); + softly.assertThat(response.videos()).isNullOrEmpty(); }); } From 34e1bebce79de804193acb6ebe8c62aa4c2e043f Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sat, 6 Jul 2024 01:41:49 +0900 Subject: [PATCH 6/8] =?UTF-8?q?refactor=20:=20=EA=B7=B8=EB=A3=B9=20?= =?UTF-8?q?=EC=BA=A1=EC=8A=90=20null=20=EC=B2=B4=ED=81=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PublicCapsuleQueryRepository.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java index c76ad7b50..d3216022d 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/public_capsule/repository/PublicCapsuleQueryRepository.java @@ -38,7 +38,7 @@ public Optional findPublicCapsuleDetailDtosByMemberIdAnd final Long memberId, final Long capsuleId ) { - return Optional.ofNullable(jpaQueryFactory + PublicCapsuleDetailDto publicCapsuleDetailDto = jpaQueryFactory .select( Projections.constructor( PublicCapsuleDetailDto.class, @@ -71,8 +71,13 @@ public Optional findPublicCapsuleDetailDtosByMemberIdAnd .leftJoin(video).on(capsule.id.eq(video.capsule.id)) .where(capsule.id.eq(capsuleId).and(capsule.type.eq(CapsuleType.PUBLIC)) .and(eqMemberIdOrFriendId(memberId))) - .fetchFirst() - ); + .fetchFirst(); + + if (publicCapsuleDetailDto.capsuleId() == null) { + return Optional.empty(); + } + + return Optional.of(publicCapsuleDetailDto); } private StringExpression groupConcatDistinct(final StringExpression expression) { @@ -158,7 +163,10 @@ public Slice findPublicCapsulesDtoMadeByFriend( groupConcatDistinct(image.imageUrl), groupConcatDistinct(video.videoUrl), capsule.isOpened, - capsule.type + capsule.type, + new CaseBuilder() + .when(eqMemberId(memberId)).then(true) + .otherwise(false) ) ) .from(capsule) @@ -177,9 +185,6 @@ public Slice findPublicCapsulesDtoMadeByFriend( return SliceUtil.makeSlice(size, publicCapsuleDetailDtos); } - private boolean canMoreRead(final int size, final int capsuleSize) { - return capsuleSize > size; - } public Slice findMyPublicCapsuleSlice( final Long memberId, From 83f78f9fc54738370b0e81b14f06ef94938cc509 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Mon, 8 Jul 2024 13:08:23 +0900 Subject: [PATCH 7/8] =?UTF-8?q?refact=20:=20PR=20=EB=A6=AC=EB=B7=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EA=B5=AC=EA=B8=80=20=ED=98=95?= =?UTF-8?q?=EC=8B=9D=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/domain/capsule/entity/Capsule.java | 24 +++++------------ .../capsule/CapsuleQueryRepositoryImpl.java | 11 ++++---- .../service/CapsuleService.java | 3 ++- .../group_capsule/api/GroupCapsuleApi.java | 2 +- .../dto/GroupCapsuleWithMemberDetailDto.java | 9 ++++++- .../response/GroupCapsuleDetailResponse.java | 2 +- .../GroupCapsuleOpenQueryRepository.java | 2 +- .../service/GroupCapsuleService.java | 5 +--- .../public_capsule/api/PublicCapsuleApi.java | 2 -- .../api/PublicCapsuleApiController.java | 4 --- .../data/dto/PublicCapsuleDetailDto.java | 1 - .../data/dto/PublicCapsuleSummaryDto.java | 1 - .../response/PublicCapsuleDetailResponse.java | 2 -- .../PublicCapsuleSummaryResponse.java | 1 - .../PublicCapsuleQueryRepository.java | 27 +++++++++---------- .../service/PublicCapsuleService.java | 2 -- .../data/dto/TreasureCapsuleOpenDto.java | 3 ++- .../data/dto/TreasureCapsuleSummaryDto.java | 3 ++- .../service/command/FriendCommandService.java | 3 ++- .../service/command/GroupCommandService.java | 3 ++- .../core/domain/member/api/MemberApi.java | 2 -- .../repository/MemberQueryRepository.java | 2 -- .../member_group/entity/MemberGroup.java | 3 --- .../api/NotificationApiController.java | 2 +- .../core/global/security/jwt/JwtFactory.java | 2 +- 25 files changed, 48 insertions(+), 73 deletions(-) diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/entity/Capsule.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/entity/Capsule.java index c48d10184..4bae9e45b 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/entity/Capsule.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/capsule/entity/Capsule.java @@ -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; @@ -39,42 +38,31 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Capsule extends BaseEntity { + @OneToMany(mappedBy = "capsule") + private final List images = new ArrayList<>(); + @OneToMany(mappedBy = "capsule") + private final List