diff --git a/src/main/java/com/burntoburn/easyshift/controller/template/ScheduleTemplateController.java b/src/main/java/com/burntoburn/easyshift/controller/template/ScheduleTemplateController.java index 9bc3818..7646c08 100644 --- a/src/main/java/com/burntoburn/easyshift/controller/template/ScheduleTemplateController.java +++ b/src/main/java/com/burntoburn/easyshift/controller/template/ScheduleTemplateController.java @@ -5,6 +5,7 @@ import com.burntoburn.easyshift.dto.template.ScheduleTemplateResponse; import com.burntoburn.easyshift.dto.template.ScheduleTemplateWithShiftsResponse; import com.burntoburn.easyshift.service.templates.ScheduleTemplateService; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; diff --git a/src/main/java/com/burntoburn/easyshift/dto/schedule/req/ScheduleUpload.java b/src/main/java/com/burntoburn/easyshift/dto/schedule/req/ScheduleUpload.java index e5a22a7..38b5e39 100644 --- a/src/main/java/com/burntoburn/easyshift/dto/schedule/req/ScheduleUpload.java +++ b/src/main/java/com/burntoburn/easyshift/dto/schedule/req/ScheduleUpload.java @@ -14,8 +14,7 @@ public class ScheduleUpload { private String scheduleName; private Long storeId; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM") - private YearMonth scheduleMonth; + private String scheduleMonth; private Long scheduleTemplateId; private String description; private List shiftDetails; diff --git a/src/main/java/com/burntoburn/easyshift/dto/schedule/res/ScheduleDetailDTO.java b/src/main/java/com/burntoburn/easyshift/dto/schedule/res/ScheduleDetailDTO.java index 89a337a..cb3b58b 100644 --- a/src/main/java/com/burntoburn/easyshift/dto/schedule/res/ScheduleDetailDTO.java +++ b/src/main/java/com/burntoburn/easyshift/dto/schedule/res/ScheduleDetailDTO.java @@ -6,6 +6,7 @@ import com.burntoburn.easyshift.entity.schedule.Shift; import com.burntoburn.easyshift.entity.templates.ScheduleTemplate; import com.burntoburn.easyshift.entity.templates.ShiftTemplate; +import java.util.Collections; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -31,5 +32,8 @@ public static ScheduleDetailDTO fromEntity(Long scheduleId, String scheduleName, return new ScheduleDetailDTO(scheduleId, scheduleName, templateDtos); } + public static ScheduleDetailDTO emptyResponse(Long scheduleId) { + return new ScheduleDetailDTO(scheduleId, "", Collections.emptyList()); + } } diff --git a/src/main/java/com/burntoburn/easyshift/service/schedule/ScheduleFactory.java b/src/main/java/com/burntoburn/easyshift/service/schedule/ScheduleFactory.java index 4225ed7..fa01e98 100644 --- a/src/main/java/com/burntoburn/easyshift/service/schedule/ScheduleFactory.java +++ b/src/main/java/com/burntoburn/easyshift/service/schedule/ScheduleFactory.java @@ -8,6 +8,7 @@ import com.burntoburn.easyshift.entity.store.Store; import com.burntoburn.easyshift.entity.templates.ScheduleTemplate; import com.burntoburn.easyshift.entity.templates.ShiftTemplate; +import java.time.format.DateTimeFormatter; import org.springframework.stereotype.Component; import java.time.YearMonth; @@ -22,7 +23,7 @@ public class ScheduleFactory { public Schedule createSchedule(Store store, ScheduleTemplate scheduleTemplate, ScheduleUpload request) { Schedule schedule = Schedule.builder() .scheduleName(request.getScheduleName()) - .scheduleMonth(request.getScheduleMonth()) + .scheduleMonth(YearMonth.parse(request.getScheduleMonth(), DateTimeFormatter.ofPattern("yyyy-MM"))) .scheduleStatus(ScheduleStatus.PENDING) .scheduleTemplateId(scheduleTemplate.getId()) // Schedule 테이블에 scheduleTemplateId 저장 .description(request.getDescription()) diff --git a/src/main/java/com/burntoburn/easyshift/service/schedule/imp/ScheduleServiceImp.java b/src/main/java/com/burntoburn/easyshift/service/schedule/imp/ScheduleServiceImp.java index ec43b2e..b25667a 100644 --- a/src/main/java/com/burntoburn/easyshift/service/schedule/imp/ScheduleServiceImp.java +++ b/src/main/java/com/burntoburn/easyshift/service/schedule/imp/ScheduleServiceImp.java @@ -121,18 +121,12 @@ public SelectedScheduleTemplateDto getWeeklySchedule(Long scheduleTemplateId, St LocalDate endDate = monday.plusDays(6); List schedules = scheduleRepository.findSchedulesWithTemplate(scheduleTemplateId); - if (schedules.isEmpty()) { - throw ScheduleException.scheduleNotFound(); - } + List scheduleIds = schedules.stream().map(Schedule::getId).toList(); - if (scheduleIds.isEmpty()) { - throw ScheduleException.scheduleNotFound(); - } + List shifts = shiftRepository.findShiftsByScheduleIdWithUser(scheduleIds, monday, endDate); - if (shifts.isEmpty()) { - throw ShiftException.shiftNotFoundInPeriod(); - } + ScheduleTemplate scheduleTemplate = scheduleTemplateRepository @@ -145,15 +139,19 @@ public SelectedScheduleTemplateDto getWeeklySchedule(Long scheduleTemplateId, St // 스케줄 조회(all) @Override public ScheduleDetailDTO getAllSchedules(Long scheduleId) { - Schedule schedule = scheduleRepository.findScheduleWithShifts(scheduleId) - .orElseThrow(ScheduleException::scheduleNotFound); + Optional optionalSchedule = scheduleRepository.findScheduleWithShifts(scheduleId); + + if (optionalSchedule.isEmpty()) { + return ScheduleDetailDTO.emptyResponse(scheduleId); + } + + Schedule schedule = optionalSchedule.get(); ScheduleTemplate scheduleTemplate = scheduleTemplateRepository .findScheduleTemplateWithShiftsById(schedule.getScheduleTemplateId()) .orElseThrow(TemplateException::scheduleTemplateNotFound); List shiftTemplates = scheduleTemplate.getShiftTemplates(); - List shifts = schedule.getShifts(); return ScheduleDetailDTO.fromEntity(scheduleId, schedule.getScheduleName(), shiftTemplates, shifts); diff --git a/src/main/java/com/burntoburn/easyshift/service/templates/imp/ScheduleTemplateServiceImpl.java b/src/main/java/com/burntoburn/easyshift/service/templates/imp/ScheduleTemplateServiceImpl.java index b2dbe48..0cb774a 100644 --- a/src/main/java/com/burntoburn/easyshift/service/templates/imp/ScheduleTemplateServiceImpl.java +++ b/src/main/java/com/burntoburn/easyshift/service/templates/imp/ScheduleTemplateServiceImpl.java @@ -11,6 +11,7 @@ import com.burntoburn.easyshift.repository.store.StoreRepository; import com.burntoburn.easyshift.service.templates.ScheduleTemplateFactory; import com.burntoburn.easyshift.service.templates.ScheduleTemplateService; +import java.util.Collections; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -43,21 +44,13 @@ public ScheduleTemplateResponse createScheduleTemplate(Long storeId, ScheduleTem @Transactional(readOnly = true) @Override public ScheduleTemplateWithShiftsResponse getAllScheduleTemplatesByStore(Long storeId) { - boolean exists = storeRepository.existsById(storeId); - if (!exists){ - throw new NoSuchElementException("not found store"); - } - + // storeId가 존재하지 않으면 빈 리스트 반환 List scheduleTemplateList = scheduleTemplateRepository.findAllByStoreId(storeId); - // 찾는 스케줄이 비어 있을 때 예외 발생 - if(scheduleTemplateList.isEmpty()){ - throw TemplateException.scheduleTemplateNotFound(); - } - return ScheduleTemplateWithShiftsResponse.fromEntities(scheduleTemplateList); } + @Override public void deleteScheduleTemplate(Long scheduleTemplateId) { boolean exists = scheduleTemplateRepository.existsById(scheduleTemplateId);