Skip to content

Commit

Permalink
#84 [feat] 로그아웃 성공
Browse files Browse the repository at this point in the history
  • Loading branch information
emjayMJkim committed Jan 17, 2024
1 parent f6fa53c commit 921d221
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sopetit.softie.domain.usecase.auth

import com.sopetit.softie.domain.repository.AuthRepository
import javax.inject.Inject

class LogOutUseCase @Inject constructor(
private val authRepository: AuthRepository
) {

suspend operator fun invoke() = authRepository.logOut()
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.sopetit.softie.ui.setting

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProvider
import com.sopetit.softie.R
import com.sopetit.softie.databinding.FragmentSettingInitBinding
import com.sopetit.softie.ui.login.LoginActivity
import com.sopetit.softie.ui.setting.SettingActivity.Companion.USER_EXIT
import com.sopetit.softie.ui.setting.SettingActivity.Companion.USER_SECURITY
import com.sopetit.softie.util.OriginalBottomSheet.Companion.BOTTOM_SHEET_TAG
import com.sopetit.softie.util.binding.BindingBottomSheet
import com.sopetit.softie.util.binding.BindingFragment
import timber.log.Timber

class SettingInitFragment :
BindingFragment<FragmentSettingInitBinding>(R.layout.fragment_setting_init) {
Expand Down Expand Up @@ -63,7 +66,17 @@ class SettingInitFragment :
doBtnContent = getString(R.string.user_logout_exit),
doBtnColor = R.drawable.shape_red_fill_12_rect,
backBtnAction = {},
doBtnAction = {}
doBtnAction = {
viewModel.setLogOut()

val intent = Intent(requireActivity(), LoginActivity::class.java)
viewModel.isLogOutResponse.observe(viewLifecycleOwner) { logOutSuccess ->
if (logOutSuccess) {
Timber.d("setting -> 로그 아웃 성공")
startActivity(intent)
}
}
}
).show(parentFragmentManager, BOTTOM_SHEET_TAG)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.lifecycle.viewModelScope
import com.sopetit.softie.domain.usecase.InitSIgnUpStateUseCase
import com.sopetit.softie.domain.usecase.InitTokenUseCase
import com.sopetit.softie.domain.usecase.auth.DeleteAuthUseCase
import com.sopetit.softie.domain.usecase.auth.LogOutUseCase
import com.sopetit.softie.ui.setting.SettingActivity.Companion.SETTING_INIT
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
Expand All @@ -16,6 +17,7 @@ import javax.inject.Inject
@HiltViewModel
class SettingViewModel @Inject constructor(
private val deleteAuthUseCase: DeleteAuthUseCase,
private val logOutUseCase: LogOutUseCase,
private val initSIgnUpStateUseCase: InitSIgnUpStateUseCase,
private val initTokenUseCase: InitTokenUseCase
) : ViewModel() {
Expand All @@ -28,6 +30,10 @@ class SettingViewModel @Inject constructor(
val isDeleteAuthResponse: LiveData<Boolean>
get() = _isDeleteAuthResponse

private val _isLogOutResponse: MutableLiveData<Boolean> = MutableLiveData()
val isLogOutResponse: LiveData<Boolean>
get() = _isLogOutResponse

fun setSettingFragment(clickFragment: String) {
_settingFragment.value = clickFragment
}
Expand All @@ -39,10 +45,26 @@ class SettingViewModel @Inject constructor(
_isDeleteAuthResponse.value = true
initSIgnUpStateUseCase(false)
initTokenUseCase("", "")
Timber.d("회원 탈퇴 성공")
}.onFailure { throwable ->
_isDeleteAuthResponse.value = false
Timber.e("서버 통신 실패 -> ${throwable.message}")
}
}
}

fun setLogOut() {
viewModelScope.launch {
logOutUseCase.invoke()
.onSuccess {
_isLogOutResponse.value = true
initSIgnUpStateUseCase(false)
initTokenUseCase("", "")
Timber.d("로그 아웃 성공")
}.onFailure { throwable ->
_isLogOutResponse.value = false
Timber.e("서버 통신 실패 -> ${throwable.message}")
}
}
}
}

0 comments on commit 921d221

Please sign in to comment.