Skip to content

Commit

Permalink
feat: 메세징 토큰 제거 로직 추가 (#182)
Browse files Browse the repository at this point in the history
- 토큰 제거 로직 추가
- 에러 로깅 추가
  • Loading branch information
easyhz committed Aug 29, 2024
1 parent 67603ec commit 05f8e8b
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ internal fun NavGraphBuilder.myPageGraph(
composable<Withdrawal> {
WithdrawalScreen(
navigateToUp = navigateToUp,
navigateToLogin = navigateToLogin
navigateToLogin = navigateToLogin,
snackBarHostState = snackBarHostState
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@ package com.easyhz.noffice.domain.my_page.usecase

import android.content.Context
import com.easyhz.noffice.core.common.base.BaseUseCase
import com.easyhz.noffice.core.common.util.errorLogging
import com.easyhz.noffice.data.auth.repository.auth.AuthRepository
import com.easyhz.noffice.domain.notification.usecase.DeleteMessagingTokenUseCase
import javax.inject.Inject

class LogoutUseCase @Inject constructor(
private val authRepository: AuthRepository
private val authRepository: AuthRepository,
private val deleteMessagingTokenUseCase: DeleteMessagingTokenUseCase
): BaseUseCase<Context, Unit>() {
override suspend fun invoke(param: Context): Result<Unit> {
return authRepository.logout(param)
override suspend fun invoke(param: Context): Result<Unit> = runCatching {
deleteMessagingToken()
authRepository.logout(param)
}

private suspend fun deleteMessagingToken() {
deleteMessagingTokenUseCase(Unit).onFailure { e ->
errorLogging(this.javaClass.name, "deleteMessagingToken", e)
throw e
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.easyhz.noffice.domain.my_page.usecase

import android.content.Context
import com.easyhz.noffice.core.common.base.BaseUseCase
import com.easyhz.noffice.core.common.util.errorLogging
import com.easyhz.noffice.data.auth.repository.auth.AuthRepository
import com.easyhz.noffice.domain.notification.usecase.DeleteMessagingTokenUseCase
import javax.inject.Inject

class WithdrawUseCase @Inject constructor(
private val authRepository: AuthRepository,
private val deleteMessagingTokenUseCase: DeleteMessagingTokenUseCase
): BaseUseCase<Context, Unit>() {
override suspend fun invoke(param: Context): Result<Unit> = runCatching {
deleteMessagingToken()
authRepository.withdraw(param)
}

private suspend fun deleteMessagingToken() {
deleteMessagingTokenUseCase(Unit).onFailure { e ->
errorLogging(this.javaClass.name, "deleteMessagingToken", e)
throw e
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.easyhz.noffice.feature.my_page.contract.detail.withdrawal

import androidx.annotation.StringRes
import com.easyhz.noffice.core.common.base.UiSideEffect

sealed class WithdrawalSideEffect: UiSideEffect() {
data object NavigateToUp: WithdrawalSideEffect()
data object NavigateToLogin: WithdrawalSideEffect()
data class ShowSnackBar(@StringRes val stringId: Int): WithdrawalSideEffect()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.easyhz.noffice.feature.my_page.contract.menu

import android.net.Uri
import androidx.annotation.StringRes
import com.easyhz.noffice.core.common.base.UiSideEffect

sealed class MenuSideEffect: UiSideEffect() {
Expand All @@ -11,4 +12,5 @@ sealed class MenuSideEffect: UiSideEffect() {
data object NavigateToConsentToInformation: MenuSideEffect()
data object NavigateToWithdrawal: MenuSideEffect()
data object NavigateToLogin: MenuSideEffect()
data class ShowSnackBar(@StringRes val stringId: Int): MenuSideEffect()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.content.Context
import android.net.Uri
import androidx.lifecycle.viewModelScope
import com.easyhz.noffice.core.common.base.BaseViewModel
import com.easyhz.noffice.core.common.error.handleError
import com.easyhz.noffice.core.common.util.errorLogging
import com.easyhz.noffice.domain.my_page.usecase.LogoutUseCase
import com.easyhz.noffice.feature.my_page.contract.menu.MenuIntent
import com.easyhz.noffice.feature.my_page.contract.menu.MenuSideEffect
Expand Down Expand Up @@ -88,6 +90,9 @@ class MyPageMenuViewModel @Inject constructor(
logoutUseCase.invoke(context)
.onSuccess {
postSideEffect { MenuSideEffect.NavigateToLogin }
}.onFailure {
errorLogging(this.javaClass.name, "handleLogout", it)
showSnackBar(it.handleError())
}.also {
reduce { copy(isLoading = false) }
}
Expand All @@ -96,4 +101,8 @@ class MyPageMenuViewModel @Inject constructor(
private fun updateLogoutState(isShowLogoutDialog: Boolean = false, isLoading: Boolean) {
reduce { copy(isShowLogoutDialog = isShowLogoutDialog, isLoading = isLoading) }
}

private fun showSnackBar(stringId: Int) {
postSideEffect { MenuSideEffect.ShowSnackBar(stringId) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ fun MyPageScreen(
is MenuSideEffect.NavigateToConsentToInformation -> { navigateToConsent() }
is MenuSideEffect.NavigateToWithdrawal -> { navigateToWithdrawal() }
is MenuSideEffect.NavigateToLogin -> { navigateToLogin() }
is MenuSideEffect.ShowSnackBar -> {
snackBarHostState.showSnackbar(
message = context.getString(sideEffect.stringId),
withDismissAction = true
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -52,6 +53,7 @@ import com.easyhz.noffice.feature.my_page.util.WithdrawalType
fun WithdrawalScreen(
modifier: Modifier = Modifier,
viewModel: WithdrawalViewModel = hiltViewModel(),
snackBarHostState: SnackbarHostState,
navigateToUp: () -> Unit,
navigateToLogin: () -> Unit
) {
Expand Down Expand Up @@ -169,6 +171,12 @@ fun WithdrawalScreen(
when(sideEffect) {
is WithdrawalSideEffect.NavigateToUp -> { navigateToUp() }
is WithdrawalSideEffect.NavigateToLogin -> { navigateToLogin() }
is WithdrawalSideEffect.ShowSnackBar -> {
snackBarHostState.showSnackbar(
message = context.getString(sideEffect.stringId),
withDismissAction = true
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import android.content.Context
import androidx.lifecycle.viewModelScope
import com.easyhz.noffice.core.common.base.BaseViewModel
import com.easyhz.noffice.core.common.error.NofficeError
import com.easyhz.noffice.core.common.error.handleError
import com.easyhz.noffice.core.common.util.errorLogging
import com.easyhz.noffice.domain.my_page.usecase.WithdrawUserCase
import com.easyhz.noffice.domain.my_page.usecase.WithdrawUseCase
import com.easyhz.noffice.feature.my_page.contract.detail.withdrawal.WithdrawalIntent
import com.easyhz.noffice.feature.my_page.contract.detail.withdrawal.WithdrawalSideEffect
import com.easyhz.noffice.feature.my_page.contract.detail.withdrawal.WithdrawalState
Expand All @@ -15,7 +16,7 @@ import javax.inject.Inject

@HiltViewModel
class WithdrawalViewModel @Inject constructor(
private val withdrawUserCase: WithdrawUserCase
private val withdrawUseCase: WithdrawUseCase
): BaseViewModel<WithdrawalState, WithdrawalIntent, WithdrawalSideEffect>(
initialState = WithdrawalState.init()
) {
Expand All @@ -33,13 +34,14 @@ class WithdrawalViewModel @Inject constructor(

private fun onClickWithdrawalButton(context: Context) = viewModelScope.launch {
reduce { copy(isLoading = true) }
withdrawUserCase.invoke(context).onSuccess {
withdrawUseCase.invoke(context).onSuccess {
navigateToLogIn()
}.onFailure {
if (it is NofficeError.NoContent) {
navigateToLogIn()
} else {
errorLogging(this.javaClass.name, "withdraw", it)
showSnackBar(it.handleError())
}
}.also {
reduce { copy(isLoading = false) }
Expand All @@ -53,4 +55,8 @@ class WithdrawalViewModel @Inject constructor(
private fun onClickBackButton() {
postSideEffect { WithdrawalSideEffect.NavigateToUp }
}

private fun showSnackBar(stringId: Int) {
postSideEffect { WithdrawalSideEffect.ShowSnackBar(stringId) }
}
}

0 comments on commit 05f8e8b

Please sign in to comment.