Skip to content

Commit

Permalink
[FEATURE] #81 : 사용자 권한 상태를 가지는 Flow 및 권한 상태 Sealed Class 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Jan 5, 2024
1 parent 354a399 commit ed2480b
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -25,11 +28,27 @@ class SurveyViewModel @Inject constructor(
private val _surveyEvent: MutableSharedFlow<SurveyUiEvent> = MutableSharedFlow()
val surveyEvent = _surveyEvent.asSharedFlow()

private val _userRoleUiState: MutableStateFlow<UserRoleUiState> =
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 ->
Expand Down Expand Up @@ -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<SurveyForm>) : SurveyFormListUiState()
Expand Down

0 comments on commit ed2480b

Please sign in to comment.