From 921d2219f75999aa97f6e084886a1478b53a663c Mon Sep 17 00:00:00 2001 From: KIM MINJEONG Date: Thu, 18 Jan 2024 03:51:50 +0900 Subject: [PATCH] =?UTF-8?q?#84=20[feat]=20=EB=A1=9C=EA=B7=B8=EC=95=84?= =?UTF-8?q?=EC=9B=83=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/usecase/auth/LogOutUseCase.kt | 11 ++++++++++ .../softie/ui/setting/SettingInitFragment.kt | 15 ++++++++++++- .../softie/ui/setting/SettingViewModel.kt | 22 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/sopetit/softie/domain/usecase/auth/LogOutUseCase.kt diff --git a/app/src/main/java/com/sopetit/softie/domain/usecase/auth/LogOutUseCase.kt b/app/src/main/java/com/sopetit/softie/domain/usecase/auth/LogOutUseCase.kt new file mode 100644 index 00000000..e8fbc19d --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/domain/usecase/auth/LogOutUseCase.kt @@ -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() +} diff --git a/app/src/main/java/com/sopetit/softie/ui/setting/SettingInitFragment.kt b/app/src/main/java/com/sopetit/softie/ui/setting/SettingInitFragment.kt index b181149d..545a1b24 100644 --- a/app/src/main/java/com/sopetit/softie/ui/setting/SettingInitFragment.kt +++ b/app/src/main/java/com/sopetit/softie/ui/setting/SettingInitFragment.kt @@ -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(R.layout.fragment_setting_init) { @@ -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) } } diff --git a/app/src/main/java/com/sopetit/softie/ui/setting/SettingViewModel.kt b/app/src/main/java/com/sopetit/softie/ui/setting/SettingViewModel.kt index 1af4c0f5..7d0ab342 100644 --- a/app/src/main/java/com/sopetit/softie/ui/setting/SettingViewModel.kt +++ b/app/src/main/java/com/sopetit/softie/ui/setting/SettingViewModel.kt @@ -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 @@ -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() { @@ -28,6 +30,10 @@ class SettingViewModel @Inject constructor( val isDeleteAuthResponse: LiveData get() = _isDeleteAuthResponse + private val _isLogOutResponse: MutableLiveData = MutableLiveData() + val isLogOutResponse: LiveData + get() = _isLogOutResponse + fun setSettingFragment(clickFragment: String) { _settingFragment.value = clickFragment } @@ -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}") + } + } + } }