Skip to content

Commit 587f24a

Browse files
committed
hotfix: 공고 수정 제약사항 변경
1 parent 403454c commit 587f24a

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/main/java/modelly/modelly_be/domain/recruitment/service/DesignerRecruitmentService.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package modelly.modelly_be.domain.recruitment.service;
22

33
import lombok.RequiredArgsConstructor;
4+
import lombok.extern.slf4j.Slf4j;
45
import modelly.modelly_be.domain.like.service.RecruitmentLikeService;
56
import modelly.modelly_be.domain.recruitment.dto.internal.RecruitmentSchedule;
67
import modelly.modelly_be.domain.recruitment.dto.request.RecruitmentRequestDto;
@@ -34,7 +35,11 @@
3435
import java.time.format.DateTimeParseException;
3536
import java.util.Comparator;
3637
import java.util.List;
38+
import java.util.Map;
39+
import java.util.Set;
40+
import java.util.stream.Collectors;
3741

42+
@Slf4j
3843
@Service
3944
@RequiredArgsConstructor
4045
public class DesignerRecruitmentService {
@@ -122,10 +127,11 @@ public RecruitmentResponseDto updateRecruitment(User user, Long recruitmentId, U
122127
isRecruitmentAuthor(designer,recruitment);
123128

124129
//이미 확정된 예약이 있는 경우 예외처리
125-
reservationService.hasPendingOrConfirmedReservation(recruitment);
130+
//reservationService.hasPendingOrConfirmedReservation(recruitment);
126131

127132
//스케줄 수정
128133
if (requestDto.recruitmentSchedule()!= null) {
134+
validateScheduleDeletion(recruitment, requestDto.recruitmentSchedule());
129135
recruitment.getRecruitmentDates().clear();
130136
updateSchedule(recruitment, requestDto.recruitmentSchedule());
131137
}
@@ -260,4 +266,40 @@ public void updateSubCategory(Recruitment recruitment, Category parentCategory,L
260266
recruitment.getSubCategoryList()
261267
.addAll(subCategoryList);
262268
}
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+
}
263305
}

src/main/java/modelly/modelly_be/global/apiPayload/code/status/ErrorStatus.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public enum ErrorStatus implements BaseErrorCode {
5353
NOT_FOUND_RECRUITMENT(HttpStatus.NOT_FOUND,"RECRUITMENT404", "공고를 찾을 수 없습니다."),
5454
FORBIDDEN_DELETE_OR_MODIFY_RECRUITMENT(HttpStatus.FORBIDDEN, "RECRUITMENT403", "작성자만 공고 삭제 및 수정이 가능합니다."),
5555
CAN_NOT_RECRUITMENT_DELETE_OR_MODIFY(HttpStatus.CONFLICT, "RECRUITMENT409", "현재 진행중이거나 확정된 예약이 있어 삭제 및 수정이 불가능합니다."),
56+
CAN_NOT_UPDATE_SCHEDULE(HttpStatus.BAD_REQUEST, "RECRUITMENT4003", "수정 전 공고 시간대에 이미 예약이 잡혀있어 일자를 수정할 수 없습니다."),
5657
SUBCATEGORY_MISMATCH(HttpStatus.BAD_REQUEST, "RECRUITMENT4001", "선택한 서브 카테고리가 상위 카테고리와 일치하지 않습니다."),
5758
REQUIRED_RECRUITMENT_IMAGE(HttpStatus.BAD_REQUEST, "RECRUITMENT4002","헤어, 네일 관련 공고는 이미지가 필수입니다."),
5859
NOT_FOUND_RECRUITMENT_TIME(HttpStatus.NOT_FOUND,"RECRUITMENT404", "공고에서 선택한 일시를 찾을 수 없습니다."),

0 commit comments

Comments
 (0)