-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from TeamPINGLE/feat-logout-and-withdraw-api-…
…connection [feat] 로그아웃, 회원탈퇴 api 연동
- Loading branch information
Showing
10 changed files
with
180 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/src/main/java/org/sopt/pingle/presentation/ui/main/more/MoreViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.sopt.pingle.presentation.ui.main.more | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
import org.sopt.pingle.data.datasource.local.PingleLocalDataSource | ||
import org.sopt.pingle.domain.repository.AuthRepository | ||
import org.sopt.pingle.util.view.UiState | ||
|
||
@HiltViewModel | ||
class MoreViewModel @Inject constructor( | ||
private val authRepository: AuthRepository, | ||
private val pingleLocalDataSource: PingleLocalDataSource | ||
) : ViewModel() { | ||
private val _logoutState = MutableStateFlow<UiState<Boolean>>(UiState.Empty) | ||
val logoutState get() = _logoutState.asStateFlow() | ||
|
||
private val _withDrawState = MutableStateFlow<UiState<Boolean>>(UiState.Empty) | ||
val withDrawState get() = _withDrawState.asStateFlow() | ||
|
||
fun logout() { | ||
viewModelScope.launch { | ||
authRepository.logout() | ||
.onSuccess { code -> | ||
if (code == SUCCESS_CODE) { | ||
_logoutState.value = UiState.Success(true) | ||
pingleLocalDataSource.clear() | ||
} else { | ||
_logoutState.value = UiState.Error(null) | ||
} | ||
}.onFailure { throwable -> | ||
_logoutState.value = UiState.Error(throwable.message) | ||
} | ||
} | ||
} | ||
|
||
fun withDraw() { | ||
viewModelScope.launch { | ||
authRepository.withDraw() | ||
.onSuccess { code -> | ||
if (code == SUCCESS_CODE) { | ||
_withDrawState.value = UiState.Success(true) | ||
pingleLocalDataSource.clear() | ||
} else { | ||
_withDrawState.value = UiState.Error(null) | ||
} | ||
}.onFailure { throwable -> | ||
_withDrawState.value = UiState.Error(throwable.message) | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
const val SUCCESS_CODE = 200 | ||
} | ||
} |