Skip to content

Commit

Permalink
[CHORE] #125 : 불필요한 스코프 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Feb 17, 2024
1 parent 145110b commit c18af5c
Showing 1 changed file with 31 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,42 @@ class SurveyViewModel @Inject constructor(
getUserRole()
}

private fun getUserRole() {
viewModelScope.launch {
getUserRoleUseCase()
.onSuccess { userRole ->
_userRoleUiState.value = UserRoleUiState.Success(userRole)
}
.onFailure { throwable ->
_surveyEvent.emit(SurveyUiEvent.Failure(throwable))
}
}
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 ->
val filteredSurveyFormList = surveyFormList.filter { survey ->
survey.isBeforeDeadline()
}
_surveyFormListUiState.value =
SurveyFormListUiState.Success(filteredSurveyFormList)
fun getSurveyFormList() = viewModelScope.launch {
getSurveyFormListUseCase()
.onSuccess { surveyFormList ->
val filteredSurveyFormList = surveyFormList.filter { survey ->
survey.isBeforeDeadline()
}
.onFailure { throwable ->
_surveyEvent.emit(SurveyUiEvent.Failure(throwable))
}
}
_surveyFormListUiState.value =
SurveyFormListUiState.Success(filteredSurveyFormList)
}
.onFailure { throwable ->
_surveyEvent.emit(SurveyUiEvent.Failure(throwable))
}
}

fun isSubmittedSurvey(surveyFormId: String) {
viewModelScope.launch {
isSubmittedSurveyUseCase(surveyFormId)
.onSuccess { isSubmittedSurvey ->
if (isSubmittedSurvey) {
_surveyEvent.emit(SurveyUiEvent.AlreadySubmitted)
} else {
_surveyEvent.emit(SurveyUiEvent.NotSubmitted(surveyFormId))
}
}
.onFailure { throwable ->
_surveyEvent.emit(SurveyUiEvent.Failure(throwable))
fun isSubmittedSurvey(surveyFormId: String) = viewModelScope.launch {
isSubmittedSurveyUseCase(surveyFormId)
.onSuccess { isSubmittedSurvey ->
if (isSubmittedSurvey) {
_surveyEvent.emit(SurveyUiEvent.AlreadySubmitted)
} else {
_surveyEvent.emit(SurveyUiEvent.NotSubmitted(surveyFormId))
}
}
}
.onFailure { throwable ->
_surveyEvent.emit(SurveyUiEvent.Failure(throwable))
}
}

sealed class UserRoleUiState {
Expand All @@ -87,6 +81,7 @@ class SurveyViewModel @Inject constructor(

sealed class SurveyFormListUiState {
data object Init : SurveyFormListUiState()
data object Loading : SurveyFormListUiState()
data class Success(val surveyFormList: List<SurveyForm>) : SurveyFormListUiState()
}

Expand Down

0 comments on commit c18af5c

Please sign in to comment.