diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/repository/GroupQueryRepositoryImpl.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/repository/GroupQueryRepositoryImpl.java index 1972fc22..c477f6ee 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/repository/GroupQueryRepositoryImpl.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/repository/GroupQueryRepositoryImpl.java @@ -12,7 +12,6 @@ import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; @@ -85,54 +84,48 @@ public List getTotalGroupMemberCount(final List groupIds) { .fetch(); } - /** - * 사용자를 제외한 그룹원 정보와 그룹의 상세정보를 반환한다. - * - * @param groupId 상세정보를 찾을 그룹 아이디 - * @param memberId 사용자 아이디 - * @return 그룹의 상세정보({@code memberId} 제외 그룹원) - */ @Override - public Optional findGroupDetailByGroupIdAndMemberIdExcludeMemberId(final Long groupId, + public Optional findGroupDetailByGroupIdAndMemberIdExcludeMemberId( + final Long groupId, final Long memberId) { - GroupDetailDto groupDetailDtoIncludeMe = - jpaQueryFactory - .selectFrom(group) - .join(memberGroup).on(memberGroup.group.eq(group), - memberGroup.deletedAt.isNull()) - .join(member).on(member.eq(memberGroup.member), - member.deletedAt.isNull()) - .where(group.id.eq(groupId)) - .transform( - groupBy(group.id).as( - Projections.constructor( - GroupDetailDto.class, - group.groupName, - group.groupDescription, - group.groupProfileUrl, - group.createdAt, - Expressions.asBoolean(Boolean.FALSE), - list( - Projections.constructor( - GroupMemberDto.class, - member.id, - member.profileUrl, - member.nickname, - member.tag, - memberGroup.isOwner - ) + GroupDetailDto groupDetailDtoIncludeMe = jpaQueryFactory + .selectFrom(group) + .join(memberGroup).on(memberGroup.group.eq(group), + memberGroup.deletedAt.isNull()) + .join(member).on(member.eq(memberGroup.member), + member.deletedAt.isNull()) + .where(group.id.eq(groupId)) + .transform( + groupBy(group.id).as( + Projections.constructor( + GroupDetailDto.class, + group.groupName, + group.groupDescription, + group.groupProfileUrl, + group.createdAt, + Expressions.asBoolean(Boolean.FALSE), + list( + Projections.constructor( + GroupMemberDto.class, + member.id, + member.profileUrl, + member.nickname, + member.tag, + memberGroup.isOwner ) ) ) ) - .get(groupId); + ) + .get(groupId); - if (Objects.isNull(groupDetailDtoIncludeMe)) { + if (groupDetailDtoIncludeMe == null) { return Optional.empty(); } boolean isOwner = false; - List groupMemberDtosExcludeMe = new ArrayList<>(); + List groupMemberDtosExcludeMe = new ArrayList<>( + groupDetailDtoIncludeMe.members().size()); for (GroupMemberDto dto : groupDetailDtoIncludeMe.members()) { if (!dto.memberId().equals(memberId)) { groupMemberDtosExcludeMe.add(dto);