generated from pricelees/issue-pr-template
feat: 일정 생성시 중복된 시간 검증 추가
This commit is contained in:
parent
9c279e1ec2
commit
d5037664d7
@ -33,16 +33,17 @@ class ScheduleValidator(
|
|||||||
val date: LocalDate = schedule.date
|
val date: LocalDate = schedule.date
|
||||||
val time: LocalTime = request.time ?: schedule.time
|
val time: LocalTime = request.time ?: schedule.time
|
||||||
|
|
||||||
validateDateTime(date, time)
|
validateNotInPast(date, time)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun validateCanCreate(request: ScheduleCreateRequest) {
|
fun validateCanCreate(storeId: Long, request: ScheduleCreateRequest) {
|
||||||
val date: LocalDate = request.date
|
val date: LocalDate = request.date
|
||||||
val time: LocalTime = request.time
|
val time: LocalTime = request.time
|
||||||
val themeId: Long = request.themeId
|
val themeId: Long = request.themeId
|
||||||
|
|
||||||
validateAlreadyExists(date, themeId, time)
|
validateAlreadyExists(date, themeId, time)
|
||||||
validateDateTime(date, time)
|
validateNotInPast(date, time)
|
||||||
|
validateTimeNotConflict(storeId, request.date, request.themeId, request.time)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun validateAlreadyExists(date: LocalDate, themeId: Long, time: LocalTime) {
|
private fun validateAlreadyExists(date: LocalDate, themeId: Long, time: LocalTime) {
|
||||||
@ -54,7 +55,7 @@ class ScheduleValidator(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun validateDateTime(date: LocalDate, time: LocalTime) {
|
private fun validateNotInPast(date: LocalDate, time: LocalTime) {
|
||||||
val dateTime = LocalDateTime.of(date, time)
|
val dateTime = LocalDateTime.of(date, time)
|
||||||
|
|
||||||
if (dateTime.isBefore(LocalDateTime.now())) {
|
if (dateTime.isBefore(LocalDateTime.now())) {
|
||||||
@ -64,4 +65,13 @@ class ScheduleValidator(
|
|||||||
throw ScheduleException(ScheduleErrorCode.PAST_DATE_TIME)
|
throw ScheduleException(ScheduleErrorCode.PAST_DATE_TIME)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun validateTimeNotConflict(storeId: Long, date: LocalDate, themeId: Long, time: LocalTime) {
|
||||||
|
scheduleRepository.findStoreSchedulesWithThemeByDate(storeId, date, themeId)
|
||||||
|
.firstOrNull { it.containsTime(time) }
|
||||||
|
?.let {
|
||||||
|
log.info { "[ScheduleValidator.validateTimeNotConflict] 시간이 겹치는 일정 존재: conflictSchedule(Id=${it.id}, time=${it.time}~${it.getEndAt()})" }
|
||||||
|
throw ScheduleException(ScheduleErrorCode.SCHEDULE_TIME_CONFLICT)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,5 +12,6 @@ enum class ScheduleErrorCode(
|
|||||||
SCHEDULE_ALREADY_EXISTS(HttpStatus.CONFLICT, "S002", "이미 동일한 일정이 있어요."),
|
SCHEDULE_ALREADY_EXISTS(HttpStatus.CONFLICT, "S002", "이미 동일한 일정이 있어요."),
|
||||||
PAST_DATE_TIME(HttpStatus.BAD_REQUEST, "S003", "과거 날짜와 시간은 선택할 수 없어요."),
|
PAST_DATE_TIME(HttpStatus.BAD_REQUEST, "S003", "과거 날짜와 시간은 선택할 수 없어요."),
|
||||||
SCHEDULE_IN_USE(HttpStatus.CONFLICT, "S004", "예약이 진행중이거나 완료된 일정은 삭제할 수 없어요."),
|
SCHEDULE_IN_USE(HttpStatus.CONFLICT, "S004", "예약이 진행중이거나 완료된 일정은 삭제할 수 없어요."),
|
||||||
SCHEDULE_NOT_AVAILABLE(HttpStatus.CONFLICT, "S005", "예약이 완료되었거나 예약할 수 없는 일정이에요.")
|
SCHEDULE_NOT_AVAILABLE(HttpStatus.CONFLICT, "S005", "예약이 완료되었거나 예약할 수 없는 일정이에요."),
|
||||||
|
SCHEDULE_TIME_CONFLICT(HttpStatus.CONFLICT, "S006", "시간이 겹치는 다른 일정이 있어요.")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user