-
Notifications
You must be signed in to change notification settings - Fork 0
[Fix] 탈퇴하기 리팩토링 #354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix] 탈퇴하기 리팩토링 #354
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,11 @@ | ||
| package com.eatssu.android.domain.usecase.auth | ||
|
|
||
| import com.eatssu.android.data.dto.response.BaseResponse | ||
| import com.eatssu.android.domain.repository.UserRepository | ||
| import kotlinx.coroutines.flow.Flow | ||
| import javax.inject.Inject | ||
|
|
||
| class SignOutUseCase @Inject constructor( | ||
| private val userRepository: UserRepository, | ||
| ) { | ||
| suspend operator fun invoke(): Flow<BaseResponse<Boolean>> = | ||
| suspend operator fun invoke(): Boolean = | ||
| userRepository.signOut() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,17 +4,15 @@ import androidx.lifecycle.ViewModel | |
| import androidx.lifecycle.viewModelScope | ||
| import com.eatssu.android.domain.usecase.auth.LogoutUseCase | ||
| import com.eatssu.android.domain.usecase.auth.SignOutUseCase | ||
| import com.eatssu.android.presentation.UiEvent | ||
| import com.eatssu.android.presentation.UiState | ||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||
| import kotlinx.coroutines.flow.MutableSharedFlow | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.SharedFlow | ||
| import kotlinx.coroutines.flow.StateFlow | ||
| import kotlinx.coroutines.flow.asStateFlow | ||
| import kotlinx.coroutines.flow.catch | ||
| import kotlinx.coroutines.flow.collectLatest | ||
| import kotlinx.coroutines.flow.onCompletion | ||
| import kotlinx.coroutines.flow.onStart | ||
| import kotlinx.coroutines.flow.update | ||
| import kotlinx.coroutines.launch | ||
| import timber.log.Timber | ||
| import javax.inject.Inject | ||
|
|
||
| @HiltViewModel | ||
|
|
@@ -23,45 +21,33 @@ class SignOutViewModel @Inject constructor( | |
| private val signOutUseCase: SignOutUseCase, | ||
| ) : ViewModel() { | ||
|
|
||
| private val _uiState: MutableStateFlow<SignOutState> = MutableStateFlow(SignOutState()) | ||
| val uiState: StateFlow<SignOutState> = _uiState.asStateFlow() | ||
| private val _uiState: MutableStateFlow<UiState<SignOutState>> = MutableStateFlow(UiState.Init) | ||
| val uiState: StateFlow<UiState<SignOutState>> = _uiState.asStateFlow() | ||
|
|
||
| private val _uiEvent = MutableSharedFlow<UiEvent>() | ||
| val uiEvent: SharedFlow<UiEvent> = _uiEvent | ||
|
|
||
| fun signOut() { | ||
| viewModelScope.launch { | ||
| signOutUseCase().onStart { | ||
| _uiState.update { it.copy(loading = true) } | ||
| }.onCompletion { | ||
| _uiState.update { it.copy(loading = false, error = true) } | ||
| }.catch { e -> | ||
| _uiState.update { it.copy(error = true, toastMessage = "정보를 불러올 수 없습니다.") } | ||
| Timber.d(TAG, e.toString()) | ||
| }.collectLatest { result -> | ||
| Timber.d(TAG, result.toString()) | ||
| if (result.result == true) { | ||
| logoutUseCase() | ||
| _uiState.update { | ||
| it.copy( | ||
| isSignOuted = true, | ||
| toastMessage = "탈퇴가 완료되었습니다." | ||
| ) | ||
| } | ||
| _uiState.value = UiState.Loading | ||
| try { | ||
| val isSignOut = signOutUseCase() | ||
| if (isSignOut) { | ||
| _uiState.value = UiState.Success(SignOutState(isSignOuted = true)) | ||
| _uiEvent.emit(UiEvent.ShowToast("탈퇴가 완료되었습니다.")) | ||
| logoutUseCase() // 자동 로그인 정보 삭제 | ||
| } else { | ||
| _uiState.value = UiState.Error | ||
| _uiEvent.emit(UiEvent.ShowToast("오류가 발생했습니다.")) | ||
| } | ||
| } catch (e: Exception) { | ||
| _uiState.value = UiState.Error | ||
| _uiEvent.emit(UiEvent.ShowToast("오류가 발생했습니다.")) | ||
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| val TAG = "SignOutViewModel" | ||
| } | ||
| } | ||
|
|
||
| data class SignOutState( | ||
| var loading: Boolean = true, | ||
| var error: Boolean = false, | ||
| var toastMessage: String = "", | ||
| var nickname: String = "", | ||
| var platform: String = "", | ||
| var isNicknameNull: Boolean = false, | ||
| var isLoginOuted: Boolean = false, | ||
| var isSignOuted: Boolean = false, | ||
| val isSignOuted: Boolean = false, | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BaseResponse에 result가 T?라서 Boolean이 올 자리에 Boolean?이 와서 false로 기본값을 주었는데, 이렇게 해도 괜찮을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
signOut에 대한 result도 단순 Boolean값이라 null로 올 것 같지는 않지만
null인 경우 false로 두는 거 괜찮을거같은데요?!