Skip to content

Commit

Permalink
fix : 그룹 상세 조회 쿼리 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
seokho-1116 committed Aug 14, 2024
1 parent 1c71987 commit 8012113
Showing 1 changed file with 31 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,54 +84,48 @@ public List<Long> getTotalGroupMemberCount(final List<Long> groupIds) {
.fetch();
}

/**
* 사용자를 제외한 그룹원 정보와 그룹의 상세정보를 반환한다.
*
* @param groupId 상세정보를 찾을 그룹 아이디
* @param memberId 사용자 아이디
* @return 그룹의 상세정보({@code memberId} 제외 그룹원)
*/
@Override
public Optional<GroupDetailDto> findGroupDetailByGroupIdAndMemberIdExcludeMemberId(final Long groupId,
public Optional<GroupDetailDto> 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<GroupMemberDto> groupMemberDtosExcludeMe = new ArrayList<>();
List<GroupMemberDto> groupMemberDtosExcludeMe = new ArrayList<>(
groupDetailDtoIncludeMe.members().size());
for (GroupMemberDto dto : groupDetailDtoIncludeMe.members()) {
if (!dto.memberId().equals(memberId)) {
groupMemberDtosExcludeMe.add(dto);
Expand Down

0 comments on commit 8012113

Please sign in to comment.