Skip to content

Commit

Permalink
add: 팀내 모든 일정 조회시 예외처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
“adashkdy9960 committed Jun 4, 2024
1 parent c80c10b commit af9d583
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import wercsmik.spaghetticodingclub.domain.schedule.dto.SchedulerResponseDTO;
import wercsmik.spaghetticodingclub.domain.schedule.entity.Scheduler;
import wercsmik.spaghetticodingclub.domain.schedule.repository.SchedulerRepository;
import wercsmik.spaghetticodingclub.domain.team.entity.Team;
import wercsmik.spaghetticodingclub.domain.team.entity.TeamMember;
import wercsmik.spaghetticodingclub.domain.team.repository.TeamMemberRepository;
import wercsmik.spaghetticodingclub.domain.team.repository.TeamRepository;
import wercsmik.spaghetticodingclub.domain.user.entity.User;
import wercsmik.spaghetticodingclub.global.exception.CustomException;
import wercsmik.spaghetticodingclub.global.exception.ErrorCode;
Expand All @@ -23,6 +25,7 @@
public class SchedulerService {

private final SchedulerRepository schedulerRepository;
private final TeamRepository teamRepository;
private final TeamMemberRepository teamMemberRepository;

@Transactional
Expand Down Expand Up @@ -63,15 +66,17 @@ public SchedulerCreationResponseDTO createSchedule(UserDetailsImpl userDetails,
@Transactional(readOnly = true)
public List<SchedulerResponseDTO> getTeamSchedules(Long teamId) {

// 팀Id 조회
List<TeamMember> teamTeamId = teamMemberRepository.findByTeam_TeamId(teamId);
Team team = teamRepository.findById(teamId) // 조회
.orElseThrow(() -> new CustomException(ErrorCode.TEAM_NOT_FOUND));

if (teamTeamId.isEmpty()) {
throw new CustomException(ErrorCode.TEAM_NOT_FOUND);
List<TeamMember> teamMembers = teamMemberRepository.findByTeam_TeamId(teamId); // 팀 멤버 조회

if (teamMembers.isEmpty()) {
throw new CustomException(ErrorCode.TEAM_MEMBERS_NOT_FOUND);
}

// 팀 멤버들의 유저 리스트를 생성
List<User> users = teamTeamId.stream()
List<User> users = teamMembers.stream()
.map(TeamMember::getUser)
.collect(Collectors.toList());

Expand Down

0 comments on commit af9d583

Please sign in to comment.