diff --git a/backend/src/main/java/org/example/backend/timetable/service/TimetableService.java b/backend/src/main/java/org/example/backend/timetable/service/TimetableService.java index f58142a4..fac21f2b 100644 --- a/backend/src/main/java/org/example/backend/timetable/service/TimetableService.java +++ b/backend/src/main/java/org/example/backend/timetable/service/TimetableService.java @@ -1,14 +1,19 @@ package org.example.backend.timetable.service; -import jakarta.persistence.EntityNotFoundException; +import static org.example.backend.seminarRoom.exception.SeminarRoomExceptionType.NOT_FOUND_SEMINAR_ROOM; +import static org.example.backend.timetable.exception.TimetableExceptionType.NOT_FOUND_TIMETABLE; + import java.util.List; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.example.backend.seminarRoom.domain.SeminarRoom; +import org.example.backend.seminarRoom.exception.SeminarRoomException; import org.example.backend.seminarRoom.repository.SeminarRoomRepository; import org.example.backend.timetable.domain.Timetable; import org.example.backend.timetable.domain.dto.TimetableReqDto; import org.example.backend.timetable.domain.dto.TimetableResDto; +import org.example.backend.timetable.exception.TimetableException; +import org.example.backend.timetable.exception.TimetableExceptionType; import org.example.backend.timetable.repository.TimetableRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -23,7 +28,7 @@ public class TimetableService { @Transactional public TimetableResDto createTimetable(TimetableReqDto reqDto) { SeminarRoom seminarRoom = seminarRoomRepository.findById(reqDto.getSeminarRoomId()) - .orElseThrow(() -> new IllegalArgumentException("세미나실이 존재하지 않습니다.")); + .orElseThrow(() -> new TimetableException(NOT_FOUND_TIMETABLE)); validateTimeRange(reqDto); @@ -42,10 +47,10 @@ public List getAllTimetables() { @Transactional public TimetableResDto updateTimetable(Long timetableId, TimetableReqDto reqDto) { Timetable timetable = timetableRepository.findById(timetableId) - .orElseThrow(() -> new IllegalArgumentException("시간표가 존재하지 않습니다.")); + .orElseThrow(() -> new TimetableException(NOT_FOUND_TIMETABLE)); SeminarRoom seminarRoom = seminarRoomRepository.findById(reqDto.getSeminarRoomId()) - .orElseThrow(() -> new IllegalArgumentException("세미나실이 존재하지 않습니다.")); + .orElseThrow(() -> new SeminarRoomException(NOT_FOUND_SEMINAR_ROOM)); validateTimeRange(reqDto); @@ -56,16 +61,16 @@ public TimetableResDto updateTimetable(Long timetableId, TimetableReqDto reqDto) @Transactional public void deleteTimetable(Long timetableId) { Timetable timetable = timetableRepository.findById(timetableId) - .orElseThrow(() -> new IllegalArgumentException("시간표가 존재하지 않습니다.")); + .orElseThrow(() -> new TimetableException(NOT_FOUND_TIMETABLE)); timetableRepository.delete(timetable); } private void validateTimeRange(TimetableReqDto reqDto) { if (reqDto.getStartDate().isAfter(reqDto.getEndDate())) { - throw new IllegalArgumentException("시작 날짜는 종료 날짜보다 이후일 수 없습니다."); + throw new TimetableException(TimetableExceptionType.INVALID_INPUT_TIME); } if (reqDto.getStartTime().isAfter(reqDto.getEndTime())) { - throw new IllegalArgumentException("시작 시간은 종료 시간보다 이후일 수 없습니다."); + throw new TimetableException(TimetableExceptionType.INVALID_INPUT_TIME); } } } \ No newline at end of file