Skip to content

Commit

Permalink
feat: 시간표 예외처리 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
urinaner committed Nov 24, 2024
1 parent 3ab3c8b commit 7e66aa4
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);

Expand All @@ -42,10 +47,10 @@ public List<TimetableResDto> 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);

Expand All @@ -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);
}
}
}

0 comments on commit 7e66aa4

Please sign in to comment.