From 41d3836ee732e6ffa280f049652bd05c354fb89d Mon Sep 17 00:00:00 2001 From: easyhz Date: Thu, 29 Aug 2024 14:52:42 +0900 Subject: [PATCH 1/7] =?UTF-8?q?fix:=20messagingToken=20body=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20(#182)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - messagingToken 저장 api requestBody 변경 --- .../com/easyhz/noffice/core/network/api/auth/AuthService.kt | 3 ++- .../core/network/model/request/token/MessagingToken.kt | 5 +++++ .../repository/messaging/CloudMessagingRepositoryImpl.kt | 3 ++- .../data/notification/service/CloudMessagingService.kt | 3 ++- 4 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 core/network/src/main/java/com/easyhz/noffice/core/network/model/request/token/MessagingToken.kt diff --git a/core/network/src/main/java/com/easyhz/noffice/core/network/api/auth/AuthService.kt b/core/network/src/main/java/com/easyhz/noffice/core/network/api/auth/AuthService.kt index 4c4003ab..cd663ebd 100644 --- a/core/network/src/main/java/com/easyhz/noffice/core/network/api/auth/AuthService.kt +++ b/core/network/src/main/java/com/easyhz/noffice/core/network/api/auth/AuthService.kt @@ -1,6 +1,7 @@ package com.easyhz.noffice.core.network.api.auth import com.easyhz.noffice.core.network.model.request.sign.LoginRequest +import com.easyhz.noffice.core.network.model.request.token.MessagingToken import com.easyhz.noffice.core.network.model.response.auth.UserResponse import com.easyhz.noffice.core.network.util.NofficeResult import retrofit2.http.Body @@ -25,7 +26,7 @@ interface AuthService { /* fcm 토큰 저장 */ @POST("/api/v1/notifications/fcm-token") suspend fun registerMessagingToken( - @Body fcmToken: String + @Body fcmToken: MessagingToken ): NofficeResult /* 회원 탈퇴 */ diff --git a/core/network/src/main/java/com/easyhz/noffice/core/network/model/request/token/MessagingToken.kt b/core/network/src/main/java/com/easyhz/noffice/core/network/model/request/token/MessagingToken.kt new file mode 100644 index 00000000..dc93711d --- /dev/null +++ b/core/network/src/main/java/com/easyhz/noffice/core/network/model/request/token/MessagingToken.kt @@ -0,0 +1,5 @@ +package com.easyhz.noffice.core.network.model.request.token + +data class MessagingToken( + val token: String +) diff --git a/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepositoryImpl.kt b/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepositoryImpl.kt index 63c4a548..2fc738aa 100644 --- a/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepositoryImpl.kt +++ b/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepositoryImpl.kt @@ -3,6 +3,7 @@ package com.easyhz.noffice.data.notification.repository.messaging import com.easyhz.noffice.core.common.di.Dispatcher import com.easyhz.noffice.core.common.di.NofficeDispatchers import com.easyhz.noffice.core.network.api.auth.AuthService +import com.easyhz.noffice.core.network.model.request.token.MessagingToken import com.easyhz.noffice.core.network.util.toResult import com.google.firebase.messaging.FirebaseMessaging import kotlinx.coroutines.CoroutineDispatcher @@ -22,6 +23,6 @@ class CloudMessagingRepositoryImpl @Inject constructor( } override suspend fun registerToken(token: String): Result = withContext(dispatcher) { - return@withContext authService.registerMessagingToken(token).toResult() + return@withContext authService.registerMessagingToken(MessagingToken(token)).toResult() } } \ No newline at end of file diff --git a/data/notification/src/main/java/com/easyhz/noffice/data/notification/service/CloudMessagingService.kt b/data/notification/src/main/java/com/easyhz/noffice/data/notification/service/CloudMessagingService.kt index 2623c77e..c83de45e 100644 --- a/data/notification/src/main/java/com/easyhz/noffice/data/notification/service/CloudMessagingService.kt +++ b/data/notification/src/main/java/com/easyhz/noffice/data/notification/service/CloudMessagingService.kt @@ -2,6 +2,7 @@ package com.easyhz.noffice.data.notification.service import android.util.Log import com.easyhz.noffice.core.network.api.auth.AuthService +import com.easyhz.noffice.core.network.model.request.token.MessagingToken import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage import dagger.hilt.android.AndroidEntryPoint @@ -32,7 +33,7 @@ class CloudMessagingService: FirebaseMessagingService() { private fun registerToken(token: String) { CoroutineScope(Dispatchers.IO).launch { - val response = authService.registerMessagingToken(token) + val response = authService.registerMessagingToken(MessagingToken(token)) response.onSuccess { Log.d(this.javaClass.name, "Success registering token") }.onFailure { e -> From a7aca9a48d7ece4a036868e134fdb252bfbe3cb2 Mon Sep 17 00:00:00 2001 From: easyhz Date: Thu, 29 Aug 2024 15:04:12 +0900 Subject: [PATCH 2/7] =?UTF-8?q?chore:=20=EC=9D=98=EC=A1=B4=EC=84=B1=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#182)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - projects.core.datastore --- data/notification/build.gradle.kts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/data/notification/build.gradle.kts b/data/notification/build.gradle.kts index 4d7a22a1..214c1e90 100644 --- a/data/notification/build.gradle.kts +++ b/data/notification/build.gradle.kts @@ -12,4 +12,6 @@ android { dependencies { implementation(projects.core.common) implementation(projects.core.network) + + implementation(projects.core.datastore) } \ No newline at end of file From ee2116441c191b15736f9995b0558d5c8ed72bf4 Mon Sep 17 00:00:00 2001 From: easyhz Date: Thu, 29 Aug 2024 15:04:36 +0900 Subject: [PATCH 3/7] =?UTF-8?q?fix:=20token=20=EB=93=B1=EB=A1=9D=20?= =?UTF-8?q?=EC=A0=84=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=97=AC=EB=B6=80=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#182)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/service/CloudMessagingService.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/data/notification/src/main/java/com/easyhz/noffice/data/notification/service/CloudMessagingService.kt b/data/notification/src/main/java/com/easyhz/noffice/data/notification/service/CloudMessagingService.kt index c83de45e..0983d73f 100644 --- a/data/notification/src/main/java/com/easyhz/noffice/data/notification/service/CloudMessagingService.kt +++ b/data/notification/src/main/java/com/easyhz/noffice/data/notification/service/CloudMessagingService.kt @@ -1,6 +1,8 @@ package com.easyhz.noffice.data.notification.service import android.util.Log +import com.easyhz.noffice.core.common.util.errorLogging +import com.easyhz.noffice.core.datastore.datasource.user.UserLocalDataSource import com.easyhz.noffice.core.network.api.auth.AuthService import com.easyhz.noffice.core.network.model.request.token.MessagingToken import com.google.firebase.messaging.FirebaseMessagingService @@ -16,6 +18,9 @@ class CloudMessagingService: FirebaseMessagingService() { @Inject lateinit var authService: AuthService + @Inject + lateinit var userLocalDataSource: UserLocalDataSource + @Inject lateinit var notificationService: NotificationService @@ -33,13 +38,17 @@ class CloudMessagingService: FirebaseMessagingService() { private fun registerToken(token: String) { CoroutineScope(Dispatchers.IO).launch { + val memberId = userLocalDataSource.getMemberId().getOrNull() + if (memberId == null || memberId == -1) { + Log.w(this.javaClass.name, "memberId is $memberId") + return@launch + } val response = authService.registerMessagingToken(MessagingToken(token)) response.onSuccess { Log.d(this.javaClass.name, "Success registering token") }.onFailure { e -> - Log.e(this.javaClass.name, "Error registering token", e) + errorLogging(this.javaClass.name, "Error registering token", e) } } } - } \ No newline at end of file From a6157a10d87fac0c724b9cf5bec14cbe9ef98e88 Mon Sep 17 00:00:00 2001 From: easyhz Date: Thu, 29 Aug 2024 15:07:44 +0900 Subject: [PATCH 4/7] =?UTF-8?q?refactor:=20register=20token=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=EB=AA=85=20=EB=B3=80=EA=B2=BD=20(#182)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - registerToken -> registerMessagingToken --- .../repository/messaging/CloudMessagingRepository.kt | 2 +- .../repository/messaging/CloudMessagingRepositoryImpl.kt | 2 +- .../notification/usecase/RegisterMessagingTokenUseCase.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepository.kt b/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepository.kt index 1971d160..29d96bdf 100644 --- a/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepository.kt +++ b/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepository.kt @@ -2,5 +2,5 @@ package com.easyhz.noffice.data.notification.repository.messaging interface CloudMessagingRepository { suspend fun getToken(): Result - suspend fun registerToken(token: String): Result + suspend fun registerMessagingToken(token: String): Result } \ No newline at end of file diff --git a/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepositoryImpl.kt b/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepositoryImpl.kt index 2fc738aa..fa087552 100644 --- a/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepositoryImpl.kt +++ b/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepositoryImpl.kt @@ -22,7 +22,7 @@ class CloudMessagingRepositoryImpl @Inject constructor( } } - override suspend fun registerToken(token: String): Result = withContext(dispatcher) { + override suspend fun registerMessagingToken(token: String): Result = withContext(dispatcher) { return@withContext authService.registerMessagingToken(MessagingToken(token)).toResult() } } \ No newline at end of file diff --git a/domain/notification/src/main/java/com/easyhz/noffice/domain/notification/usecase/RegisterMessagingTokenUseCase.kt b/domain/notification/src/main/java/com/easyhz/noffice/domain/notification/usecase/RegisterMessagingTokenUseCase.kt index 380e0a9b..44b43ff0 100644 --- a/domain/notification/src/main/java/com/easyhz/noffice/domain/notification/usecase/RegisterMessagingTokenUseCase.kt +++ b/domain/notification/src/main/java/com/easyhz/noffice/domain/notification/usecase/RegisterMessagingTokenUseCase.kt @@ -17,6 +17,6 @@ class RegisterMessagingTokenUseCase @Inject constructor( } private suspend fun registerMessagingToken(token: String): Result { - return cloudMessagingRepository.registerToken(token) + return cloudMessagingRepository.registerMessagingToken(token) } } \ No newline at end of file From 26a199a8f210f263d8ff30c5396638c6b78bc630 Mon Sep 17 00:00:00 2001 From: easyhz Date: Thu, 29 Aug 2024 15:37:10 +0900 Subject: [PATCH 5/7] =?UTF-8?q?chore:=20=EC=9D=98=EC=A1=B4=EC=84=B1=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#182)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - projects.domain.notification --- domain/my-page/build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/domain/my-page/build.gradle.kts b/domain/my-page/build.gradle.kts index 89d9aa60..be156d7d 100644 --- a/domain/my-page/build.gradle.kts +++ b/domain/my-page/build.gradle.kts @@ -16,5 +16,6 @@ dependencies { implementation(projects.data.notification) implementation(projects.data.organization) + implementation(projects.domain.notification) implementation(projects.domain.organization) } \ No newline at end of file From 67603ec8750c97bb5da09307ff3ef8e558cc419f Mon Sep 17 00:00:00 2001 From: easyhz Date: Thu, 29 Aug 2024 15:37:54 +0900 Subject: [PATCH 6/7] =?UTF-8?q?feat:=20=EB=A9=94=EC=84=B8=EC=A7=95=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EC=A0=9C=EA=B1=B0=20api=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0=20(#182)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/network/api/auth/AuthService.kt | 9 +++++++- .../messaging/CloudMessagingRepository.kt | 1 + .../messaging/CloudMessagingRepositoryImpl.kt | 4 ++++ .../usecase/DeleteMessagingTokenUseCase.kt | 22 +++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 domain/notification/src/main/java/com/easyhz/noffice/domain/notification/usecase/DeleteMessagingTokenUseCase.kt diff --git a/core/network/src/main/java/com/easyhz/noffice/core/network/api/auth/AuthService.kt b/core/network/src/main/java/com/easyhz/noffice/core/network/api/auth/AuthService.kt index cd663ebd..8dd9c4ab 100644 --- a/core/network/src/main/java/com/easyhz/noffice/core/network/api/auth/AuthService.kt +++ b/core/network/src/main/java/com/easyhz/noffice/core/network/api/auth/AuthService.kt @@ -6,6 +6,7 @@ import com.easyhz.noffice.core.network.model.response.auth.UserResponse import com.easyhz.noffice.core.network.util.NofficeResult import retrofit2.http.Body import retrofit2.http.DELETE +import retrofit2.http.HTTP import retrofit2.http.Header import retrofit2.http.POST @@ -26,7 +27,13 @@ interface AuthService { /* fcm 토큰 저장 */ @POST("/api/v1/notifications/fcm-token") suspend fun registerMessagingToken( - @Body fcmToken: MessagingToken + @Body messagingToken: MessagingToken + ): NofficeResult + + /* fcm 토큰 삭제 */ + @HTTP(method = "DELETE", path = "/api/v1/notifications/fcm-token", hasBody = true) + suspend fun deleteMessagingToken( + @Body messagingToken: MessagingToken ): NofficeResult /* 회원 탈퇴 */ diff --git a/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepository.kt b/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepository.kt index 29d96bdf..52d100c0 100644 --- a/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepository.kt +++ b/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepository.kt @@ -3,4 +3,5 @@ package com.easyhz.noffice.data.notification.repository.messaging interface CloudMessagingRepository { suspend fun getToken(): Result suspend fun registerMessagingToken(token: String): Result + suspend fun deleteMessagingToken(token: String): Result } \ No newline at end of file diff --git a/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepositoryImpl.kt b/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepositoryImpl.kt index fa087552..b2f7b620 100644 --- a/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepositoryImpl.kt +++ b/data/notification/src/main/java/com/easyhz/noffice/data/notification/repository/messaging/CloudMessagingRepositoryImpl.kt @@ -25,4 +25,8 @@ class CloudMessagingRepositoryImpl @Inject constructor( override suspend fun registerMessagingToken(token: String): Result = withContext(dispatcher) { return@withContext authService.registerMessagingToken(MessagingToken(token)).toResult() } + + override suspend fun deleteMessagingToken(token: String): Result = withContext(dispatcher) { + return@withContext authService.deleteMessagingToken(MessagingToken(token)).toResult() + } } \ No newline at end of file diff --git a/domain/notification/src/main/java/com/easyhz/noffice/domain/notification/usecase/DeleteMessagingTokenUseCase.kt b/domain/notification/src/main/java/com/easyhz/noffice/domain/notification/usecase/DeleteMessagingTokenUseCase.kt new file mode 100644 index 00000000..2092b577 --- /dev/null +++ b/domain/notification/src/main/java/com/easyhz/noffice/domain/notification/usecase/DeleteMessagingTokenUseCase.kt @@ -0,0 +1,22 @@ +package com.easyhz.noffice.domain.notification.usecase + +import com.easyhz.noffice.core.common.base.BaseUseCase +import com.easyhz.noffice.data.notification.repository.messaging.CloudMessagingRepository +import javax.inject.Inject + +class DeleteMessagingTokenUseCase @Inject constructor( + private val cloudMessagingRepository: CloudMessagingRepository, +) : BaseUseCase() { + override suspend fun invoke(param: Unit): Result = runCatching { + val token = getMessagingToken().getOrThrow() + deleteMessagingToken(token) + } + + private suspend fun getMessagingToken(): Result { + return cloudMessagingRepository.getToken() + } + + private suspend fun deleteMessagingToken(token: String): Result { + return cloudMessagingRepository.deleteMessagingToken(token) + } +} \ No newline at end of file From 05f8e8beeb062aa9aa8bad841d1426addead48fa Mon Sep 17 00:00:00 2001 From: easyhz Date: Thu, 29 Aug 2024 15:38:54 +0900 Subject: [PATCH 7/7] =?UTF-8?q?feat:=20=EB=A9=94=EC=84=B8=EC=A7=95=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EC=A0=9C=EA=B1=B0=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#182)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 토큰 제거 로직 추가 - 에러 로깅 추가 --- .../navigation/my_page/MyPageNavigation.kt | 3 ++- .../domain/my_page/usecase/LogoutUseCase.kt | 17 ++++++++++--- .../domain/my_page/usecase/WithdrawUseCase.kt | 25 +++++++++++++++++++ .../my_page/usecase/WithdrawUserCase.kt | 14 ----------- .../detail/withdrawal/WithdrawalSideEffect.kt | 2 ++ .../my_page/contract/menu/MenuSideEffect.kt | 2 ++ .../my_page/screen/MyPageMenuViewModel.kt | 9 +++++++ .../feature/my_page/screen/MyPageScreen.kt | 6 +++++ .../detail/withdrawal/WithdrawalScreen.kt | 8 ++++++ .../detail/withdrawal/WithdrawalViewModel.kt | 12 ++++++--- 10 files changed, 77 insertions(+), 21 deletions(-) create mode 100644 domain/my-page/src/main/java/com/easyhz/noffice/domain/my_page/usecase/WithdrawUseCase.kt delete mode 100644 domain/my-page/src/main/java/com/easyhz/noffice/domain/my_page/usecase/WithdrawUserCase.kt diff --git a/app/src/main/java/com/easyhz/noffice/navigation/my_page/MyPageNavigation.kt b/app/src/main/java/com/easyhz/noffice/navigation/my_page/MyPageNavigation.kt index 67da9e9b..dd10f757 100644 --- a/app/src/main/java/com/easyhz/noffice/navigation/my_page/MyPageNavigation.kt +++ b/app/src/main/java/com/easyhz/noffice/navigation/my_page/MyPageNavigation.kt @@ -84,7 +84,8 @@ internal fun NavGraphBuilder.myPageGraph( composable { WithdrawalScreen( navigateToUp = navigateToUp, - navigateToLogin = navigateToLogin + navigateToLogin = navigateToLogin, + snackBarHostState = snackBarHostState ) } } diff --git a/domain/my-page/src/main/java/com/easyhz/noffice/domain/my_page/usecase/LogoutUseCase.kt b/domain/my-page/src/main/java/com/easyhz/noffice/domain/my_page/usecase/LogoutUseCase.kt index 3862997c..2502bb6a 100644 --- a/domain/my-page/src/main/java/com/easyhz/noffice/domain/my_page/usecase/LogoutUseCase.kt +++ b/domain/my-page/src/main/java/com/easyhz/noffice/domain/my_page/usecase/LogoutUseCase.kt @@ -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() { - override suspend fun invoke(param: Context): Result { - return authRepository.logout(param) + override suspend fun invoke(param: Context): Result = runCatching { + deleteMessagingToken() + authRepository.logout(param) + } + + private suspend fun deleteMessagingToken() { + deleteMessagingTokenUseCase(Unit).onFailure { e -> + errorLogging(this.javaClass.name, "deleteMessagingToken", e) + throw e + } } } \ No newline at end of file diff --git a/domain/my-page/src/main/java/com/easyhz/noffice/domain/my_page/usecase/WithdrawUseCase.kt b/domain/my-page/src/main/java/com/easyhz/noffice/domain/my_page/usecase/WithdrawUseCase.kt new file mode 100644 index 00000000..7c74802c --- /dev/null +++ b/domain/my-page/src/main/java/com/easyhz/noffice/domain/my_page/usecase/WithdrawUseCase.kt @@ -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() { + override suspend fun invoke(param: Context): Result = runCatching { + deleteMessagingToken() + authRepository.withdraw(param) + } + + private suspend fun deleteMessagingToken() { + deleteMessagingTokenUseCase(Unit).onFailure { e -> + errorLogging(this.javaClass.name, "deleteMessagingToken", e) + throw e + } + } +} \ No newline at end of file diff --git a/domain/my-page/src/main/java/com/easyhz/noffice/domain/my_page/usecase/WithdrawUserCase.kt b/domain/my-page/src/main/java/com/easyhz/noffice/domain/my_page/usecase/WithdrawUserCase.kt deleted file mode 100644 index 35a6e044..00000000 --- a/domain/my-page/src/main/java/com/easyhz/noffice/domain/my_page/usecase/WithdrawUserCase.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.easyhz.noffice.domain.my_page.usecase - -import android.content.Context -import com.easyhz.noffice.core.common.base.BaseUseCase -import com.easyhz.noffice.data.auth.repository.auth.AuthRepository -import javax.inject.Inject - -class WithdrawUserCase @Inject constructor( - private val authRepository: AuthRepository -): BaseUseCase() { - override suspend fun invoke(param: Context): Result { - return authRepository.withdraw(param) - } -} \ No newline at end of file diff --git a/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/contract/detail/withdrawal/WithdrawalSideEffect.kt b/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/contract/detail/withdrawal/WithdrawalSideEffect.kt index 6799bc01..1ee57eb1 100644 --- a/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/contract/detail/withdrawal/WithdrawalSideEffect.kt +++ b/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/contract/detail/withdrawal/WithdrawalSideEffect.kt @@ -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() } \ No newline at end of file diff --git a/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/contract/menu/MenuSideEffect.kt b/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/contract/menu/MenuSideEffect.kt index b32feb1a..d299193a 100644 --- a/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/contract/menu/MenuSideEffect.kt +++ b/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/contract/menu/MenuSideEffect.kt @@ -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() { @@ -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() } \ No newline at end of file diff --git a/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/MyPageMenuViewModel.kt b/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/MyPageMenuViewModel.kt index b165c297..edf89ef4 100644 --- a/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/MyPageMenuViewModel.kt +++ b/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/MyPageMenuViewModel.kt @@ -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 @@ -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) } } @@ -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) } + } } \ No newline at end of file diff --git a/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/MyPageScreen.kt b/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/MyPageScreen.kt index 728b49ee..5b1e6e93 100644 --- a/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/MyPageScreen.kt +++ b/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/MyPageScreen.kt @@ -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 + ) + } } } } diff --git a/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/detail/withdrawal/WithdrawalScreen.kt b/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/detail/withdrawal/WithdrawalScreen.kt index 20661d9d..bfac065b 100644 --- a/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/detail/withdrawal/WithdrawalScreen.kt +++ b/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/detail/withdrawal/WithdrawalScreen.kt @@ -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 @@ -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 ) { @@ -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 + ) + } } } } \ No newline at end of file diff --git a/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/detail/withdrawal/WithdrawalViewModel.kt b/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/detail/withdrawal/WithdrawalViewModel.kt index 432dc4de..47d6626f 100644 --- a/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/detail/withdrawal/WithdrawalViewModel.kt +++ b/feature/my-page/src/main/java/com/easyhz/noffice/feature/my_page/screen/detail/withdrawal/WithdrawalViewModel.kt @@ -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 @@ -15,7 +16,7 @@ import javax.inject.Inject @HiltViewModel class WithdrawalViewModel @Inject constructor( - private val withdrawUserCase: WithdrawUserCase + private val withdrawUseCase: WithdrawUseCase ): BaseViewModel( initialState = WithdrawalState.init() ) { @@ -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) } @@ -53,4 +55,8 @@ class WithdrawalViewModel @Inject constructor( private fun onClickBackButton() { postSideEffect { WithdrawalSideEffect.NavigateToUp } } + + private fun showSnackBar(stringId: Int) { + postSideEffect { WithdrawalSideEffect.ShowSnackBar(stringId) } + } } \ No newline at end of file