Skip to content

Commit

Permalink
Merge pull request #401 from tukcomCD2024/fix/update_group_capsule-B-…
Browse files Browse the repository at this point in the history
…#400

Fix/update group capsule b #400
seokho-1116 authored May 6, 2024
2 parents 2b8c7f8 + 1f16fee commit fce88b5
Showing 10 changed files with 219 additions and 218 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package site.timecapsulearchive.core.domain.capsule.group_capsule.repository;

import static com.querydsl.core.group.GroupBy.groupBy;
import static com.querydsl.core.group.GroupBy.list;
import static site.timecapsulearchive.core.domain.capsule.entity.QCapsule.capsule;
import static site.timecapsulearchive.core.domain.capsule.entity.QGroupCapsuleOpen.groupCapsuleOpen;
import static site.timecapsulearchive.core.domain.capsule.entity.QImage.image;
@@ -26,6 +28,7 @@
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.MyGroupCapsuleDto;
import site.timecapsulearchive.core.domain.group.data.dto.GroupMemberSummaryDto;
import site.timecapsulearchive.core.domain.member.entity.QMember;

@Repository
@RequiredArgsConstructor
@@ -36,43 +39,50 @@ public class GroupCapsuleQueryRepository {
public Optional<GroupCapsuleDetailDto> findGroupCapsuleDetailDtoByCapsuleId(
final Long capsuleId
) {
final CapsuleDetailDto capsuleDetailDto = jpaQueryFactory
.select(
Projections.constructor(
CapsuleDetailDto.class,
capsule.id,
capsuleSkin.imageUrl,
capsule.dueDate,
member.nickname,
member.profileUrl,
capsule.createdAt,
capsule.point,
capsule.address.fullRoadAddressName,
capsule.address.roadName,
capsule.title,
capsule.content,
groupConcatDistinct(image.imageUrl),
groupConcatDistinct(video.videoUrl),
capsule.isOpened,
capsule.type
)
)
.from(capsule)
.join(member).on(capsule.member.id.eq(member.id))
final QMember owner = new QMember("owner");
final QMember groupMember = new QMember("groupMember");

return Optional.ofNullable(jpaQueryFactory
.selectFrom(capsule)
.join(owner).on(capsule.member.id.eq(owner.id))
.join(capsuleSkin).on(capsule.capsuleSkin.id.eq(capsuleSkin.id))
.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))
.join(groupMember).on(groupMember.id.eq(groupCapsuleOpen.member.id))
.groupBy(groupCapsuleOpen.id)
.where(groupCapsuleOpen.capsule.id.eq(capsuleId))
.where(capsule.id.eq(capsuleId).and(capsule.type.eq(CapsuleType.GROUP)))
.fetchFirst();

if (capsuleDetailDto.capsuleId() == null) {
return Optional.empty();
}

final List<GroupMemberSummaryDto> memberSummaryDtos = getGroupMemberSummaryDtos(
capsuleId);

return Optional.of(new GroupCapsuleDetailDto(capsuleDetailDto, memberSummaryDtos));
.transform(
groupBy(capsule.id).as(
Projections.constructor(
GroupCapsuleDetailDto.class,
Projections.constructor(
CapsuleDetailDto.class,
capsule.id,
capsuleSkin.imageUrl,
capsule.dueDate,
owner.nickname,
owner.profileUrl,
capsule.createdAt,
capsule.point,
capsule.address.fullRoadAddressName,
capsule.address.roadName,
capsule.title,
capsule.content,
groupConcatDistinct(image.imageUrl),
groupConcatDistinct(video.videoUrl),
capsule.isOpened,
capsule.type
),
list(Projections.constructor(GroupMemberSummaryDto.class,
groupMember.nickname,
groupMember.profileUrl,
groupCapsuleOpen.isOpened)
)
)
)
).get(capsuleId));
}

private StringExpression groupConcatDistinct(final StringExpression expression) {
@@ -81,53 +91,44 @@ private StringExpression groupConcatDistinct(final StringExpression expression)

public Optional<GroupCapsuleSummaryDto> findGroupCapsuleSummaryDtoByCapsuleId(
final Long capsuleId) {
final CapsuleSummaryDto capsuleSummaryDto = jpaQueryFactory
.select(
Projections.constructor(
CapsuleSummaryDto.class,
member.nickname,
member.profileUrl,
capsuleSkin.imageUrl,
capsule.title,
capsule.dueDate,
capsule.point,
capsule.address.fullRoadAddressName,
capsule.address.roadName,
capsule.isOpened,
capsule.createdAt
)
)
.from(capsule)
.join(member).on(capsule.member.id.eq(member.id))
.join(capsuleSkin).on(capsule.capsuleSkin.id.eq(capsuleSkin.id))
final QMember owner = new QMember("owner");
final QMember groupMember = new QMember("groupMember");

return Optional.ofNullable(jpaQueryFactory
.selectFrom(capsule)
.join(owner).on(capsule.member.id.eq(owner.id))
.join(capsuleSkin).on(capsule.capsuleSkin.id.eq(capsuleSkin.id)).join(groupCapsuleOpen)
.on(groupCapsuleOpen.capsule.id.eq(capsuleId))
.join(groupMember).on(groupMember.id.eq(groupCapsuleOpen.member.id))
.groupBy(groupCapsuleOpen.id)
.where(groupCapsuleOpen.capsule.id.eq(capsuleId))
.where(capsule.id.eq(capsuleId).and(capsule.type.eq(CapsuleType.GROUP)))
.groupBy(capsule.id)
.fetchOne();
.transform(
groupBy(capsule.id).as(
Projections.constructor(
GroupCapsuleSummaryDto.class,
Projections.constructor(
CapsuleSummaryDto.class,
owner.nickname,
owner.profileUrl,
capsuleSkin.imageUrl,
capsule.title,
capsule.dueDate,
capsule.point,
capsule.address.fullRoadAddressName,
capsule.address.roadName,
capsule.isOpened,
capsule.createdAt
),
list(Projections.constructor(GroupMemberSummaryDto.class,
groupMember.nickname,
groupMember.profileUrl,
groupCapsuleOpen.isOpened)
)
)

if (capsuleSummaryDto == null) {
return Optional.empty();
}

final List<GroupMemberSummaryDto> memberSummaryDtos = getGroupMemberSummaryDtos(
capsuleId);

return Optional.of(new GroupCapsuleSummaryDto(capsuleSummaryDto, memberSummaryDtos));
}

private List<GroupMemberSummaryDto> getGroupMemberSummaryDtos(Long capsuleId) {
return jpaQueryFactory
.select(
Projections.constructor(
GroupMemberSummaryDto.class,
member.nickname,
member.profileUrl,
groupCapsuleOpen.isOpened
)
)
.from(groupCapsuleOpen)
.join(member).on(member.id.eq(groupCapsuleOpen.member.id))
.where(groupCapsuleOpen.capsule.id.eq(capsuleId))
.fetch();
).get(capsuleId));
}

public Slice<MyGroupCapsuleDto> findMyGroupCapsuleSlice(
Original file line number Diff line number Diff line change
@@ -60,18 +60,7 @@ public Slice<GroupSummaryDto> findGroupsSlice(
public Optional<GroupDetailDto> findGroupDetailByGroupId(final Long groupId) {
return Optional.ofNullable(
jpaQueryFactory
.select(
group.groupName,
group.groupDescription,
group.groupProfileUrl,
group.createdAt,
member.id,
member.profileUrl,
member.nickname,
member.tag,
memberGroup.isOwner
)
.from(group)
.selectFrom(group)
.join(memberGroup).on(memberGroup.group.id.eq(group.id))
.join(member).on(member.id.eq(memberGroup.member.id))
.where(group.id.eq(groupId))
Original file line number Diff line number Diff line change
@@ -157,7 +157,7 @@ public String getS3PreSignedUrlForGet(final String fileName) {
* @return 구분자 ,로 구분된 각각의 서명된 이미지 url
*/
public List<String> getS3PreSignedUrlsForGet(final String fileNames) {
if (fileNames == null) {
if (fileNames == null || fileNames.isEmpty()) {
return Collections.emptyList();
}

Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ private static void setFieldValue(Object instance, String fieldName, Object valu
* @param group 그룹
* @return {@code List<MemberGroup>} 테스트 픽스처들
*/
public static List<MemberGroup> membersGroup(List<Member> members, Group group) {
public static List<MemberGroup> memberGroups(List<Member> members, Group group) {
return members.stream()
.map(m -> memberGroup(m, group, Boolean.FALSE))
.toList();
Loading

0 comments on commit fce88b5

Please sign in to comment.