diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/data/dto/GroupDetailDto.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/data/dto/GroupDetailDto.java index e80c619f6..ed8cff73e 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/data/dto/GroupDetailDto.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/data/dto/GroupDetailDto.java @@ -11,4 +11,14 @@ public record GroupDetailDto( List members ) { + public static GroupDetailDto as( + String groupName, + String groupDescription, + String groupProfileUrl, + ZonedDateTime createdAt, + List members + ) { + return new GroupDetailDto(groupName, groupDescription, groupProfileUrl, createdAt, members); + } + } 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 ef08d827d..6d42c08a2 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 @@ -10,6 +10,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import java.time.ZonedDateTime; import java.util.List; +import java.util.Objects; import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; @@ -59,12 +60,11 @@ public Slice findGroupsSlice( public Optional findGroupDetailByGroupIdAndMemberId(final Long groupId, final Long memberId) { - return Optional.ofNullable( + GroupDetailDto groupDetailDtoIncludeMe = jpaQueryFactory .selectFrom(group) .join(memberGroup).on(memberGroup.group.id.eq(groupId)) .join(member).on(member.id.eq(memberGroup.member.id)) - .where(member.id.ne(memberId)) .transform( groupBy(group.id).as( Projections.constructor( @@ -86,7 +86,23 @@ public Optional findGroupDetailByGroupIdAndMemberId(final Long g ) ) ) - .get(groupId) + .get(groupId); + + if (Objects.isNull(groupDetailDtoIncludeMe)) { + return Optional.empty(); + } + + List groupMemberDtosExcludeMe = groupDetailDtoIncludeMe.members().stream() + .filter(memberDto -> !memberDto.memberId().equals(memberId)) + .toList(); + + return Optional.of( + GroupDetailDto.as( + groupDetailDtoIncludeMe.groupName(), + groupDetailDtoIncludeMe.groupDescription(), + groupDetailDtoIncludeMe.groupProfileUrl(), + groupDetailDtoIncludeMe.createdAt(), + groupMemberDtosExcludeMe) ); } diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/query/GroupQueryService.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/query/GroupQueryService.java index 016377994..c971191f7 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/query/GroupQueryService.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/group/service/query/GroupQueryService.java @@ -40,8 +40,7 @@ public Slice findGroupsSlice( public GroupDetailTotalDto findGroupDetailByGroupId(final Long memberId, final Long groupId) { final GroupDetailDto groupDetailDto = groupRepository.findGroupDetailByGroupIdAndMemberId( - groupId, - memberId).orElseThrow(GroupNotFoundException::new); + groupId, memberId).orElseThrow(GroupNotFoundException::new); final Long groupCapsuleCount = groupCapsuleQueryRepository.findGroupCapsuleCount(groupId); final Boolean canGroupEdit = groupRepository.findGroupEditPermission(groupId, memberId);