Skip to content

Commit

Permalink
[COZY-433] fix: mateIdList를 인식하지 못하는 에러 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
eple0329 authored Dec 3, 2024
1 parent f9efb00 commit dd247d1
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.cozymate.cozymate_server.global.response.code.status.ErrorStatus;
import com.cozymate.cozymate_server.global.response.exception.GeneralException;
import java.time.LocalDate;
import java.util.HashSet;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -260,9 +261,14 @@ private TodoType classifyTodoType(List<Long> todoIdList) {
* @param mateIdList 할당자 리스트
*/
private void checkMateIdListIsSameRoomWithMate(Mate mate, List<Long> mateIdList) {
List<Mate> mateList = mateRepository.findByRoomId(mate.getRoom().getId());
if (mateIdList.stream().anyMatch(
mateId -> mateList.stream().noneMatch(m -> m.getMember().getId().equals(mateId)))) {
List<Mate> roomMateList = mateRepository.findByRoomId(mate.getRoom().getId());

// roomMateList의 id만 추출해서 hashset으로 만들어줌
HashSet<Long> roomMateIdSet = roomMateList.stream().map(Mate::getId).collect(
HashSet::new, HashSet::add, HashSet::addAll);

// mateIdList가 roomMateList에 모두 포함되어있는지 확인
if (!roomMateIdSet.containsAll(mateIdList)) {
throw new GeneralException(ErrorStatus._MATE_NOT_FOUND);
}
}
Expand Down

0 comments on commit dd247d1

Please sign in to comment.