Skip to content

Commit

Permalink
[FEATURE] #125 : 일정 등록 및 수정 유효성 검증 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Feb 17, 2024
1 parent 74435b9 commit b08b383
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ class EventEditViewModel @Inject constructor(
return
}

if (!isValidEndTime(_eventEndTime.value)) {
emitValidationErrorMessage("일정 종료는 시작보다 늦어야 합니다.")
return
}

viewModelScope.launch {
updateEventUseCase(
eventTitle = _eventTitle.value,
Expand All @@ -130,8 +135,17 @@ class EventEditViewModel @Inject constructor(
}
}

private fun isValidEndTime(eventTime: LocalTime): Boolean =
_eventEndDate.value == _eventStartDate.value && eventTime > _eventStartTime.value
private fun isValidEndTime(eventTime: LocalTime): Boolean {
if (_eventEndDate.value > _eventStartDate.value) {
return true
}

if (_eventEndDate.value == _eventStartDate.value && eventTime > _eventStartTime.value) {
return true
}

return false
}

private fun isValidEndDate(eventDate: LocalDate): Boolean = eventDate >= _eventStartDate.value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ class EventRegistrationViewModel @Inject constructor(
emitValidationErrorMessage("장소를 입력 하세요.")
return
}

if (!isValidEndTime(_eventEndTime.value)) {
emitValidationErrorMessage("일정 종료는 시작보다 늦어야 합니다.")
return
}

viewModelScope.launch {
postEventUseCase(
eventTitle = _eventTitle.value,
Expand Down

0 comments on commit b08b383

Please sign in to comment.