From ed2480b006926a674f474591fe4778f826d179f2 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 5 Jan 2024 17:27:12 +0900 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20#81=20:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=EA=B6=8C=ED=95=9C=20=EC=83=81=ED=83=9C=EB=A5=BC=20?= =?UTF-8?q?=EA=B0=80=EC=A7=80=EB=8A=94=20Flow=20=EB=B0=8F=20=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=20=EC=83=81=ED=83=9C=20Sealed=20Class=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wapp/feature/survey/SurveyViewModel.kt | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyViewModel.kt b/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyViewModel.kt index f94f0d41..6b1ea72f 100644 --- a/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyViewModel.kt +++ b/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyViewModel.kt @@ -4,7 +4,9 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.wap.wapp.core.domain.usecase.survey.GetSurveyFormListUseCase import com.wap.wapp.core.domain.usecase.survey.IsSubmittedSurveyUseCase +import com.wap.wapp.core.domain.usecase.user.GetUserRoleUseCase import com.wap.wapp.core.model.survey.SurveyForm +import com.wap.wapp.core.model.user.UserRole import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow @@ -15,6 +17,7 @@ import javax.inject.Inject @HiltViewModel class SurveyViewModel @Inject constructor( + private val getUserRoleUseCase: GetUserRoleUseCase, private val getSurveyFormListUseCase: GetSurveyFormListUseCase, private val isSubmittedSurveyUseCase: IsSubmittedSurveyUseCase, ) : ViewModel() { @@ -25,11 +28,27 @@ class SurveyViewModel @Inject constructor( private val _surveyEvent: MutableSharedFlow = MutableSharedFlow() val surveyEvent = _surveyEvent.asSharedFlow() + private val _userRoleUiState: MutableStateFlow = + MutableStateFlow(UserRoleUiState.Init) + val userRoleUiState = _userRoleUiState.asStateFlow() + init { - getSurveyFormList() + getUserRole() } - private fun getSurveyFormList() { + private fun getUserRole() { + viewModelScope.launch { + getUserRoleUseCase() + .onSuccess { userRole -> + _userRoleUiState.value = UserRoleUiState.Success(userRole) + } + .onFailure { throwable -> + _surveyEvent.emit(SurveyUiEvent.Failure(throwable)) + } + } + } + + fun getSurveyFormList() { viewModelScope.launch { getSurveyFormListUseCase() .onSuccess { surveyFormList -> @@ -57,6 +76,11 @@ class SurveyViewModel @Inject constructor( } } + sealed class UserRoleUiState { + data object Init : UserRoleUiState() + data class Success(val userRole: UserRole) : UserRoleUiState() + } + sealed class SurveyFormListUiState { data object Init : SurveyFormListUiState() data class Success(val surveyFormList: List) : SurveyFormListUiState()