Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ShiftDetail> shiftDetails;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,12 @@ public SelectedScheduleTemplateDto getWeeklySchedule(Long scheduleTemplateId, St
LocalDate endDate = monday.plusDays(6);

List<Schedule> schedules = scheduleRepository.findSchedulesWithTemplate(scheduleTemplateId);
if (schedules.isEmpty()) {
throw ScheduleException.scheduleNotFound();
}


List<Long> scheduleIds = schedules.stream().map(Schedule::getId).toList();
if (scheduleIds.isEmpty()) {
throw ScheduleException.scheduleNotFound();
}

List<Shift> shifts = shiftRepository.findShiftsByScheduleIdWithUser(scheduleIds, monday, endDate);
if (shifts.isEmpty()) {
throw ShiftException.shiftNotFoundInPeriod();
}



ScheduleTemplate scheduleTemplate = scheduleTemplateRepository
Expand All @@ -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<Schedule> 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<ShiftTemplate> shiftTemplates = scheduleTemplate.getShiftTemplates();

List<Shift> shifts = schedule.getShifts();

return ScheduleDetailDTO.fromEntity(scheduleId, schedule.getScheduleName(), shiftTemplates, shifts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ScheduleTemplate> 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);
Expand Down