Skip to content

Commit

Permalink
refactor(#69): 단일 조회를 반복하는 부분 IN 이용해 한번에 조회하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jusung-c committed Oct 18, 2023
1 parent 669263d commit 2f41049
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
@Transactional(readOnly = true)
Expand Down Expand Up @@ -61,12 +63,8 @@ public void createHouseworkInfo(UserInfoResponse requestUser, HouseworkInfoCreat


// 담당자 지정 - HOUSEWORK_MEMBER 생성
for (Long groupMemberId : request.getGroupMemberIdList()) {
GroupMember gm = groupMemberRepository.findById(groupMemberId).orElseThrow(() -> {
log.warn(">>>> GroupMember Not Found : {}", ExceptionMessage.GROUP_MEMBER_NOT_FOUND);
throw new GroupMemberException(ExceptionMessage.GROUP_MEMBER_NOT_FOUND);
});

List<GroupMember> groupMemberList = groupMemberRepository.findGroupMemberListByGroupMemberIdList(request.getGroupMemberIdList());
for (GroupMember gm : groupMemberList) {
HouseworkMember hm = HouseworkMember.builder()
.groupMember(gm)
.houseworkInfo(houseworkInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ public interface GroupMemberRepositoryCustom {

// GroupId를 통해 그룹의 구성원을 리턴해주는 쿼리
public List<GroupMember> findGroupMemberByGroupId(Long groupId);

// HouseworkInfo 조회하는데 List<GroupMember>로 조회한다. - 집안일 추가시 담당자 지정을 위해 필요
public List<GroupMember> findGroupMemberListByGroupMemberIdList(List<Long> groupMemberIdList);

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@ public List<GroupMember> findGroupMemberByGroupId(Long groupId) {
.and(groupMember.status.eq(GroupMemberStatus.ACCEPT)))
.fetch();
}

@Override
public List<GroupMember> findGroupMemberListByGroupMemberIdList(List<Long> groupMemberIdList) {
// select gm from groupMember gm where gm.id in groupMemberIdList
return queryFactory.selectFrom(groupMember)
.where(groupMember.id.in(groupMemberIdList))
.fetch();
}
}

0 comments on commit 2f41049

Please sign in to comment.