diff --git a/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/impl/UserApiImpl.kt b/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/impl/UserApiImpl.kt index 8803c37..0406f7a 100644 --- a/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/impl/UserApiImpl.kt +++ b/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/impl/UserApiImpl.kt @@ -25,13 +25,14 @@ import com.xquare.v1userservice.user.spi.JwtTokenGeneratorSpi import com.xquare.v1userservice.user.spi.PasswordEncoderSpi import com.xquare.v1userservice.user.spi.PasswordMatcherSpi import com.xquare.v1userservice.user.spi.PointSpi +import com.xquare.v1userservice.user.spi.SaveUserBaseApplicationCompensator +import com.xquare.v1userservice.user.spi.SaveUserBaseApplicationProcessor import com.xquare.v1userservice.user.spi.SaveUserBaseAuthorityCompensator import com.xquare.v1userservice.user.spi.SaveUserBaseAuthorityProcessor import com.xquare.v1userservice.user.spi.UserRepositorySpi import com.xquare.v1userservice.user.verificationcode.VerificationCode import com.xquare.v1userservice.user.verificationcode.exceptions.VerificationCodeNotFoundException import com.xquare.v1userservice.user.verificationcode.spi.VerificationCodeSpi -import com.xquare.v1userservice.utils.processAndRevertSteps import java.time.LocalDateTime import java.util.UUID import kotlinx.coroutines.coroutineScope @@ -46,6 +47,8 @@ class UserApiImpl( private val userRepositorySpi: UserRepositorySpi, private val createUserInPendingStateCompensator: CreateUserInPendingStateCompensator, private val saveUserBaseAuthorityCompensator: SaveUserBaseAuthorityCompensator, + private val saveUserBaseApplicationProcessor: SaveUserBaseApplicationProcessor, + private val saveUserBaseApplicationCompensator: SaveUserBaseApplicationCompensator, private val jwtTokenGeneratorSpi: JwtTokenGeneratorSpi, private val refreshTokenSpi: RefreshTokenSpi, private val authorityListSpi: AuthorityListSpi, @@ -60,20 +63,20 @@ class UserApiImpl( val savedUser = createUserInPendingStateProcessor.processStep(domainUser) coroutineScope { - processAndRevertSteps( - processStep = saveUserBaseAuthorityProcessor::processStep to arrayOf(savedUser.id), - revertSteps = listOf( - createUserInPendingStateCompensator::revertStep to arrayOf(savedUser.id) - ) - ) - - processAndRevertSteps( - processStep = saveUserBaseAuthorityProcessor::processStep to arrayOf(savedUser.id), - revertSteps = listOf( - saveUserBaseAuthorityCompensator::revertStep to arrayOf(savedUser.id), - createUserInPendingStateCompensator::revertStep to arrayOf(savedUser.id) - ) - ) + runCatching { + saveUserBaseAuthorityProcessor.processStep(savedUser.id) + }.onFailure { + saveUserBaseAuthorityCompensator.revertStep(savedUser.id) + createUserInPendingStateCompensator.revertStep(savedUser.id) + } + + runCatching { + saveUserBaseApplicationProcessor.processStep(savedUser.id) + }.onFailure { + saveUserBaseApplicationCompensator.revertStep(savedUser.id) + saveUserBaseAuthorityCompensator.revertStep(savedUser.id) + createUserInPendingStateCompensator.revertStep(savedUser.id) + } } updateUserCreatedStateStepProcessor.processStep(savedUser.id) diff --git a/user-domain/src/main/kotlin/com/xquare/v1userservice/user/spi/SaveUserBaseAuthorityProcessor.kt b/user-domain/src/main/kotlin/com/xquare/v1userservice/user/spi/SaveUserBaseAuthorityProcessor.kt index 9291f8f..eb8060c 100644 --- a/user-domain/src/main/kotlin/com/xquare/v1userservice/user/spi/SaveUserBaseAuthorityProcessor.kt +++ b/user-domain/src/main/kotlin/com/xquare/v1userservice/user/spi/SaveUserBaseAuthorityProcessor.kt @@ -5,5 +5,5 @@ import java.util.UUID @Spi interface SaveUserBaseAuthorityProcessor { - suspend fun processStep(userId: UUID) + suspend fun processStep(userId: UUID): Result } diff --git a/user-domain/src/main/kotlin/com/xquare/v1userservice/utils/launchAndCatch.kt b/user-domain/src/main/kotlin/com/xquare/v1userservice/utils/launchAndCatch.kt deleted file mode 100644 index a4a681b..0000000 --- a/user-domain/src/main/kotlin/com/xquare/v1userservice/utils/launchAndCatch.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.xquare.v1userservice.utils - -import kotlin.reflect.KCallable -import kotlin.reflect.full.callSuspend - -suspend inline fun processAndRevertSteps( - processStep: Pair, Array>, - revertSteps: List, Array>>, -): T = try { - processStep.first.callSuspend(*processStep.second) -} catch (e: Exception) { - revertSteps.forEach { it.first.callSuspend(*it.second) } - throw e -} diff --git a/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserRouter.kt b/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserRouter.kt index 407080e..0b74c52 100644 --- a/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserRouter.kt +++ b/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserRouter.kt @@ -18,7 +18,7 @@ class UserRouter { GET("/id/{userId}", userHandler::getUserByIdHandler) GET("/account-id/{accountId}", userHandler::getUserByAccountIdHandler) GET("/tokens/fcm", userHandler::getUserDeviceTokensHandler) - GET("/points", userHandler::getUserPointHandler) + GET("/points/{userId}", userHandler::getUserPointHandler) } } } diff --git a/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/spi/SaveUserBaseApplicationSpiImpl.kt b/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/spi/SaveUserBaseApplicationSpiImpl.kt index d97f559..410328c 100644 --- a/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/spi/SaveUserBaseApplicationSpiImpl.kt +++ b/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/spi/SaveUserBaseApplicationSpiImpl.kt @@ -19,7 +19,6 @@ class SaveUserBaseApplicationSpiImpl( ) : SaveUserBaseApplicationProcessor, SaveUserBaseApplicationCompensator { override suspend fun processStep(userId: UUID) { val baseApplicationRequest = buildBaseApplicationRequest(userId) - sendPostApplicationDefaultValue(baseApplicationRequest) } diff --git a/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/spi/SaveUserBaseAuthoritySpiImpl.kt b/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/spi/SaveUserBaseAuthoritySpiImpl.kt index d198982..6893e52 100644 --- a/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/spi/SaveUserBaseAuthoritySpiImpl.kt +++ b/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/spi/SaveUserBaseAuthoritySpiImpl.kt @@ -18,9 +18,14 @@ class SaveUserBaseAuthoritySpiImpl( @Value("\${service.scheme}") private val scheme: String ) : SaveUserBaseAuthorityProcessor, SaveUserBaseAuthorityCompensator { - override suspend fun processStep(userId: UUID) { - val request = SaveUserBaseAuthorityRequest(userId) - sendSaveUserBaseAuthorityRequest(request) + override suspend fun processStep(userId: UUID): Result { + return try { + val request = SaveUserBaseAuthorityRequest(userId) + sendSaveUserBaseAuthorityRequest(request) + Result.success(Unit) + } catch (e: Exception) { + Result.failure(e) + } } private suspend fun sendSaveUserBaseAuthorityRequest(saveUserBaseAuthorityRequest: SaveUserBaseAuthorityRequest) {