Skip to content

Commit

Permalink
[#185] refactor(PerformanceModifyService): 해당 공연에 속하지 않은 회차, 등장인물, 스태…
Browse files Browse the repository at this point in the history
…프를 수정하려고 할 때 에러처리 추가
  • Loading branch information
hoonyworld committed Aug 22, 2024
1 parent f1f3aa2 commit ebc5062
Showing 1 changed file with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private List<ScheduleModifyResponse> processSchedules(List<ScheduleModifyRequest
return addSchedule(request, performance);
} else {
existingScheduleIds.remove(request.scheduleId());
return updateSchedule(request);
return updateSchedule(request, performance);
}
})
.collect(Collectors.toList());
Expand Down Expand Up @@ -205,14 +205,20 @@ private Schedule addSchedule(ScheduleModifyRequest request, Performance performa
return savedSchedule;
}

private Schedule updateSchedule(ScheduleModifyRequest request) {
private Schedule updateSchedule(ScheduleModifyRequest request, Performance performance) {
log.debug("Updating schedules for scheduleId: {}", request.scheduleId());

Schedule schedule = scheduleRepository.findById(request.scheduleId())
.orElseThrow(() -> {
log.error("Schedule not found: scheduleId: {}", request.scheduleId());
return new NotFoundException(ScheduleErrorCode.NO_SCHEDULE_FOUND);
});

// 공연에 속해 있는지 검증
if (!schedule.getPerformance().equals(performance)) {
throw new ForbiddenException(ScheduleErrorCode.SCHEDULE_NOT_BELONG_TO_PERFORMANCE);
}

schedule.update(
request.performanceDate(),
request.totalTicketCount(),
Expand Down Expand Up @@ -249,7 +255,7 @@ private List<CastModifyResponse> processCasts(List<CastModifyRequest> castReques
return addCast(request, performance);
} else {
existingCastIds.remove(request.castId()); // 요청에 포함된 ID는 삭제 후보에서 제거
return updateCast(request);
return updateCast(request, performance);
}
})
.collect(Collectors.toList());
Expand Down Expand Up @@ -278,14 +284,20 @@ private CastModifyResponse addCast(CastModifyRequest request, Performance perfor
);
}

private CastModifyResponse updateCast(CastModifyRequest request) {
private CastModifyResponse updateCast(CastModifyRequest request, Performance performance) {
log.debug("Updating casts for castId: {}", request.castId());

Cast cast = castRepository.findById(request.castId())
.orElseThrow(() -> {
log.error("Cast not found: castId: {}", request.castId());
return new NotFoundException(CastErrorCode.CAST_NOT_FOUND);
});

// 공연에 속해 있는지 검증
if (!cast.getPerformance().equals(performance)) {
throw new ForbiddenException(CastErrorCode.CAST_NOT_BELONG_TO_PERFORMANCE);
}

cast.update(
request.castName(),
request.castRole(),
Expand Down Expand Up @@ -329,7 +341,7 @@ private List<StaffModifyResponse> processStaffs(List<StaffModifyRequest> staffRe
return addStaff(request, performance);
} else {
existingStaffIds.remove(request.staffId()); // 요청에 포함된 ID는 삭제 후보에서 제거
return updateStaff(request);
return updateStaff(request, performance);
}
})
.collect(Collectors.toList());
Expand Down Expand Up @@ -358,14 +370,20 @@ private StaffModifyResponse addStaff(StaffModifyRequest request, Performance per
);
}

private StaffModifyResponse updateStaff(StaffModifyRequest request) {
private StaffModifyResponse updateStaff(StaffModifyRequest request, Performance performance) {
log.debug("Updating staffs for staffId: {}", request.staffId());

Staff staff = staffRepository.findById(request.staffId())
.orElseThrow(() -> {
log.error("Staff not found: staffId: {}", request.staffId());
return new NotFoundException(StaffErrorCode.STAFF_NOT_FOUND);
});

// 공연에 속해 있는지 검증
if (!staff.getPerformance().equals(performance)) {
throw new ForbiddenException(StaffErrorCode.STAFF_NOT_BELONG_TO_PERFORMANCE);
}

staff.update(
request.staffName(),
request.staffRole(),
Expand Down

0 comments on commit ebc5062

Please sign in to comment.