|
1 | 1 | package modelly.modelly_be.domain.recruitment.service; |
2 | 2 |
|
3 | 3 | import lombok.RequiredArgsConstructor; |
| 4 | +import lombok.extern.slf4j.Slf4j; |
4 | 5 | import modelly.modelly_be.domain.like.service.RecruitmentLikeService; |
5 | 6 | import modelly.modelly_be.domain.recruitment.dto.internal.RecruitmentSchedule; |
6 | 7 | import modelly.modelly_be.domain.recruitment.dto.request.RecruitmentRequestDto; |
|
34 | 35 | import java.time.format.DateTimeParseException; |
35 | 36 | import java.util.Comparator; |
36 | 37 | import java.util.List; |
| 38 | +import java.util.Map; |
| 39 | +import java.util.Set; |
| 40 | +import java.util.stream.Collectors; |
37 | 41 |
|
| 42 | +@Slf4j |
38 | 43 | @Service |
39 | 44 | @RequiredArgsConstructor |
40 | 45 | public class DesignerRecruitmentService { |
@@ -122,10 +127,11 @@ public RecruitmentResponseDto updateRecruitment(User user, Long recruitmentId, U |
122 | 127 | isRecruitmentAuthor(designer,recruitment); |
123 | 128 |
|
124 | 129 | //이미 확정된 예약이 있는 경우 예외처리 |
125 | | - reservationService.hasPendingOrConfirmedReservation(recruitment); |
| 130 | + //reservationService.hasPendingOrConfirmedReservation(recruitment); |
126 | 131 |
|
127 | 132 | //스케줄 수정 |
128 | 133 | if (requestDto.recruitmentSchedule()!= null) { |
| 134 | + validateScheduleDeletion(recruitment, requestDto.recruitmentSchedule()); |
129 | 135 | recruitment.getRecruitmentDates().clear(); |
130 | 136 | updateSchedule(recruitment, requestDto.recruitmentSchedule()); |
131 | 137 | } |
@@ -260,4 +266,40 @@ public void updateSubCategory(Recruitment recruitment, Category parentCategory,L |
260 | 266 | recruitment.getSubCategoryList() |
261 | 267 | .addAll(subCategoryList); |
262 | 268 | } |
| 269 | + |
| 270 | + private void validateScheduleDeletion(Recruitment recruitment, List<RecruitmentSchedule> newSchedules) { |
| 271 | + Map<LocalDate, Set<LocalTime>> newScheduleMap = newSchedules.stream() |
| 272 | + .collect(Collectors.toMap( |
| 273 | + RecruitmentSchedule::recruitmentDate, |
| 274 | + schedule -> schedule.recruitmentTimes().stream() |
| 275 | + .map(LocalTime::parse) |
| 276 | + .collect(Collectors.toSet()) |
| 277 | + )); |
| 278 | + |
| 279 | + // 기존 스케줄 확인 |
| 280 | + for (RecruitmentDate existingDate : recruitment.getRecruitmentDates()) { |
| 281 | + Set<LocalTime> newTimes = newScheduleMap.get(existingDate.getDate()); |
| 282 | + |
| 283 | + // 날짜 자체가 삭제되는 경우 |
| 284 | + if (newTimes == null) { |
| 285 | + if (hasReservation(existingDate)) { |
| 286 | + throw new GeneralException(ErrorStatus.CAN_NOT_UPDATE_SCHEDULE); |
| 287 | + } |
| 288 | + } else { |
| 289 | + // 날짜는 유지되지만 특정 시간대가 삭제되는 경우 |
| 290 | + for (RecruitmentTime existingTime : existingDate.getRecruitmentTimes()) { |
| 291 | + if (!newTimes.contains(existingTime.getStartTime())) { |
| 292 | + if (existingTime.isReserved()) { |
| 293 | + throw new GeneralException(ErrorStatus.CAN_NOT_UPDATE_SCHEDULE); |
| 294 | + } |
| 295 | + } |
| 296 | + } |
| 297 | + } |
| 298 | + } |
| 299 | + } |
| 300 | + |
| 301 | + private boolean hasReservation(RecruitmentDate recruitmentDate) { |
| 302 | + return recruitmentDate.getRecruitmentTimes().stream() |
| 303 | + .anyMatch(RecruitmentTime::isReserved); |
| 304 | + } |
263 | 305 | } |
0 commit comments