[#44] 매장 기능 도입 #45

Merged
pricelees merged 116 commits from feat/#44 into main 2025-09-20 03:15:06 +00:00
2 changed files with 16 additions and 5 deletions
Showing only changes of commit d5037664d7 - Show all commits

View File

@ -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)
}
}
} }

View File

@ -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", "시간이 겹치는 다른 일정이 있어요.")
} }