From 7e66aa4ec45b4320317e3f8f322895af1e995fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=EC=98=81=EC=9E=AC?= Date: Sun, 24 Nov 2024 13:49:21 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=8B=9C=EA=B0=84=ED=91=9C=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=EC=B2=98=EB=A6=AC=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../timetable/service/TimetableService.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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