Skip to content

Commit

Permalink
feat : 로그아웃, 회원탈퇴 시 러닝 기록 Room DB 초기화 #PAR-383
Browse files Browse the repository at this point in the history
  • Loading branch information
nohjunh committed Oct 14, 2023
1 parent 34e65f1 commit 4a7e218
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import online.partyrun.partyrunapplication.core.common.result.onSuccess
import online.partyrun.partyrunapplication.core.domain.agreement.SaveAgreementStateUseCase
import online.partyrun.partyrunapplication.core.domain.auth.GoogleSignOutUseCase
import online.partyrun.partyrunapplication.core.domain.member.DeleteAccountUseCase
import online.partyrun.partyrunapplication.core.domain.my_page.DeleteRunningHistoryUseCase
import timber.log.Timber
import javax.inject.Inject

@HiltViewModel
class SettingsViewModel @Inject constructor(
private val deleteAccountUseCase: DeleteAccountUseCase,
private val googleSignOutUseCase: GoogleSignOutUseCase,
private val deleteRunningHistoryUseCase: DeleteRunningHistoryUseCase,
private val saveAgreementStateUseCase: SaveAgreementStateUseCase
) : ViewModel() {
private val _settingsUiState = MutableStateFlow(SettingsUiState())
Expand All @@ -31,10 +33,22 @@ class SettingsViewModel @Inject constructor(
_snackbarMessage.value = ""
}

fun deleteAccount() = viewModelScope.launch {
fun deleteAccountProcess() {
signOutFromGoogle()
saveAgreementState(isChecked = false)
deleteAccount()
deleteAllHistories()
}

fun signOut() {
signOutFromGoogle()
deleteAllHistories()
saveAgreementState(isChecked = false)
}

private fun deleteAccount() = viewModelScope.launch {
deleteAccountUseCase().collect { result ->
result.onSuccess {
googleSignOutUseCase()
_settingsUiState.update { state ->
state.copy(
isAccountDeletionSuccess = true
Expand All @@ -46,16 +60,22 @@ class SettingsViewModel @Inject constructor(
}
}

fun signOut() {
signOutFromGoogle()
saveAgreementState(isChecked = false)
private fun deleteAllHistories() = viewModelScope.launch {
deleteRunningHistoryUseCase().collect { result ->
result.onSuccess {
Timber.d("모든 러닝 기록 삭제 성공")
}.onFailure { errorMessage, code ->
_snackbarMessage.value = "러닝 기록 삭제 실패"
Timber.e("$code $errorMessage")
}
}
}

private fun signOutFromGoogle() = viewModelScope.launch {
googleSignOutUseCase()
}

fun saveAgreementState(isChecked: Boolean) = viewModelScope.launch {
private fun saveAgreementState(isChecked: Boolean) = viewModelScope.launch {
saveAgreementStateUseCase(isChecked)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ private fun ConfirmButton(
) {
PartyRunGradientButton(
onClick = {
settingsViewModel.saveAgreementState(isChecked = false)
settingsViewModel.deleteAccount()
settingsViewModel.deleteAccountProcess()
},
modifier = Modifier
.shadow(5.dp, shape = CircleShape)
Expand Down

0 comments on commit 4a7e218

Please sign in to comment.