From bb3da67f026a15c9b3bdbb9a33a9138f35b51230 Mon Sep 17 00:00:00 2001 From: tgyuu-An Date: Wed, 17 Jan 2024 22:34:04 +0900 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20#105=20:=20Event=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20=EC=9E=A5=EC=B0=A9=20=EB=B0=8F?= =?UTF-8?q?=20EventEdit=EC=9C=BC=EB=A1=9C=20=EC=9D=B4=EB=8F=99=20=EC=8B=9C?= =?UTF-8?q?=20Date=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=95=88?= =?UTF-8?q?=EB=B0=9B=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../management/event/edit/EventEditScreen.kt | 16 +++--- .../event/edit/EventEditViewModel.kt | 49 +++++++++++++------ .../navigation/ManagementEventNavigation.kt | 12 ++--- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/feature/management-event/src/main/java/com/wap/wapp/feature/management/event/edit/EventEditScreen.kt b/feature/management-event/src/main/java/com/wap/wapp/feature/management/event/edit/EventEditScreen.kt index cbedc3ca..9e08f534 100644 --- a/feature/management-event/src/main/java/com/wap/wapp/feature/management/event/edit/EventEditScreen.kt +++ b/feature/management-event/src/main/java/com/wap/wapp/feature/management/event/edit/EventEditScreen.kt @@ -33,7 +33,6 @@ import com.wap.designsystem.component.WappSubTopBar import com.wap.wapp.core.commmon.extensions.toSupportingText import com.wap.wapp.feature.management.event.R import com.wap.wapp.feature.management.event.registration.EventRegistrationContent -import com.wap.wapp.feature.management.event.registration.EventRegistrationEvent import com.wap.wapp.feature.management.event.registration.EventRegistrationState import kotlinx.coroutines.flow.collectLatest import java.time.LocalDate @@ -41,7 +40,6 @@ import java.time.LocalTime @Composable internal fun EventEditRoute( - date: String, eventId: String, navigateToManagement: () -> Unit, viewModel: EventEditViewModel = hiltViewModel(), @@ -72,17 +70,17 @@ internal fun EventEditRoute( viewModel.eventEditEvent.collectLatest { when (it) { - is EventRegistrationEvent.Failure -> { + is EventEditViewModel.EventEditEvent.Failure -> snackBarHostState.showSnackbar(it.error.toSupportingText()) - } - is EventRegistrationEvent.ValidationError -> { + is EventEditViewModel.EventEditEvent.ValidationError -> snackBarHostState.showSnackbar(it.message) - } - is EventRegistrationEvent.Success -> { + is EventEditViewModel.EventEditEvent.EditSuccess -> + navigateToManagement() + + is EventEditViewModel.EventEditEvent.DeleteSuccess -> navigateToManagement() - } } } } @@ -107,6 +105,7 @@ internal fun EventEditRoute( onNextButtonClicked = onNextButtonClicked, onEditButtonClicked = onRegisterButtonClicked, onBackButtonClicked = navigateToManagement, + deleteEvent = viewModel::deleteEvent, ) } @@ -132,6 +131,7 @@ internal fun EventEditScreen( onNextButtonClicked: () -> Unit, onEditButtonClicked: () -> Unit, onBackButtonClicked: () -> Unit, + deleteEvent: () -> Unit, ) { var showStartDatePicker by remember { mutableStateOf(false) } var showStartTimePicker by remember { mutableStateOf(false) } diff --git a/feature/management-event/src/main/java/com/wap/wapp/feature/management/event/edit/EventEditViewModel.kt b/feature/management-event/src/main/java/com/wap/wapp/feature/management/event/edit/EventEditViewModel.kt index 9a1da51e..5134bf76 100644 --- a/feature/management-event/src/main/java/com/wap/wapp/feature/management/event/edit/EventEditViewModel.kt +++ b/feature/management-event/src/main/java/com/wap/wapp/feature/management/event/edit/EventEditViewModel.kt @@ -6,7 +6,6 @@ import com.wap.wapp.core.commmon.util.DateUtil import com.wap.wapp.core.domain.usecase.event.DeleteEventUseCase import com.wap.wapp.core.domain.usecase.event.GetEventUseCase import com.wap.wapp.core.domain.usecase.event.UpdateEventUseCase -import com.wap.wapp.feature.management.event.registration.EventRegistrationEvent import com.wap.wapp.feature.management.event.registration.EventRegistrationState import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow @@ -28,7 +27,7 @@ class EventEditViewModel @Inject constructor( MutableStateFlow(EventRegistrationState.EVENT_DETAILS) val currentEditState = _currentEditState.asStateFlow() - private val _eventEditEvent: MutableSharedFlow = + private val _eventEditEvent: MutableSharedFlow = MutableSharedFlow() val eventEditEvent = _eventEditEvent.asSharedFlow() @@ -59,15 +58,25 @@ class EventEditViewModel @Inject constructor( private val _eventId: MutableStateFlow = MutableStateFlow("") - fun setEventTitle(eventTitle: String) { _eventTitle.value = eventTitle } + fun setEventTitle(eventTitle: String) { + _eventTitle.value = eventTitle + } - fun setEventContent(eventContent: String) { _eventContent.value = eventContent } + fun setEventContent(eventContent: String) { + _eventContent.value = eventContent + } - fun setEventLocation(eventLocation: String) { _eventLocation.value = eventLocation } + fun setEventLocation(eventLocation: String) { + _eventLocation.value = eventLocation + } - fun setEventStartDate(eventDate: LocalDate) { _eventStartDate.value = eventDate } + fun setEventStartDate(eventDate: LocalDate) { + _eventStartDate.value = eventDate + } - fun setEventStartTime(eventTime: LocalTime) { _eventStartTime.value = eventTime } + fun setEventStartTime(eventTime: LocalTime) { + _eventStartTime.value = eventTime + } fun setEventEndDate(eventDate: LocalDate) { if (!isValidEndDate(eventDate)) { @@ -116,13 +125,21 @@ class EventEditViewModel @Inject constructor( eventEndTime = _eventEndTime.value, eventId = _eventId.value, ).onSuccess { - _eventEditEvent.emit(EventRegistrationEvent.Success) + _eventEditEvent.emit(EventEditEvent.EditSuccess) }.onFailure { throwable -> - _eventEditEvent.emit(EventRegistrationEvent.Failure(throwable)) + _eventEditEvent.emit(EventEditEvent.Failure(throwable)) } } } + fun deleteEvent() = viewModelScope.launch { + deleteEventUseCase(_eventId.value).onSuccess { + _eventEditEvent.emit(EventEditEvent.DeleteSuccess) + }.onFailure { throwable -> + _eventEditEvent.emit(EventEditEvent.Failure(throwable)) + } + } + private fun isValidEndTime(eventTime: LocalTime): Boolean = _eventEndDate.value == _eventStartDate.value && eventTime > _eventStartTime.value @@ -148,11 +165,13 @@ class EventEditViewModel @Inject constructor( .onFailure { emitValidationErrorMessage("이벤트를 불러오는데 실패하였습니다.") } } - private fun emitValidationErrorMessage(message: String) { - viewModelScope.launch { - _eventEditEvent.emit( - EventRegistrationEvent.ValidationError(message), - ) - } + private fun emitValidationErrorMessage(message: String) = + viewModelScope.launch { _eventEditEvent.emit(EventEditEvent.ValidationError(message)) } + + sealed class EventEditEvent { + data class ValidationError(val message: String) : EventEditEvent() + data class Failure(val error: Throwable) : EventEditEvent() + data object EditSuccess : EventEditEvent() + data object DeleteSuccess : EventEditEvent() } } diff --git a/feature/management-event/src/main/java/com/wap/wapp/feature/management/event/navigation/ManagementEventNavigation.kt b/feature/management-event/src/main/java/com/wap/wapp/feature/management/event/navigation/ManagementEventNavigation.kt index 1fae8cf7..9e3418b5 100644 --- a/feature/management-event/src/main/java/com/wap/wapp/feature/management/event/navigation/ManagementEventNavigation.kt +++ b/feature/management-event/src/main/java/com/wap/wapp/feature/management/event/navigation/ManagementEventNavigation.kt @@ -11,18 +11,17 @@ import com.wap.wapp.feature.management.event.edit.EventEditRoute import com.wap.wapp.feature.management.event.registration.EventRegistrationRoute const val eventRegistrationNavigationRoute = "event_registration_route" -const val eventEditNavigationRoute = "event/edit/{date}/{eventId}" +const val eventEditNavigationRoute = "event/edit/{eventId}" fun NavController.navigateToEventRegistration(navOptions: NavOptions? = navOptions {}) { this.navigate(eventRegistrationNavigationRoute, navOptions) } fun NavController.navigateToEventEdit( - date: String, eventId: String, navOptions: NavOptions? = navOptions {}, ) { - this.navigate("event/edit/$date/$eventId", navOptions) + this.navigate("event/edit/$eventId", navOptions) } fun NavGraphBuilder.managementEventNavGraph( @@ -36,15 +35,10 @@ fun NavGraphBuilder.managementEventNavGraph( composable( route = eventEditNavigationRoute, - arguments = listOf( - navArgument("date") { type = NavType.StringType }, - navArgument("eventId") { type = NavType.StringType }, - ), + arguments = listOf(navArgument("eventId") { type = NavType.StringType }), ) { navBackStackEntry -> - val date = navBackStackEntry.arguments?.getString("date") ?: "" val eventId = navBackStackEntry.arguments?.getString("eventId") ?: "" EventEditRoute( - date = date, eventId = eventId, navigateToManagement = navigateToManagement, )