Skip to content

Commit

Permalink
feat: add calling application API in SignUp Saga (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhhong0509 authored Jun 22, 2022
1 parent b98985e commit 448f95b
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 9 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ subprojects {
dependencies {
implementation(Dependencies.KOTLIN_REFLECT)
implementation(Dependencies.KOTLIN_STDLIB)
implementation(Dependencies.COROUTINE_JDK)
implementation(Dependencies.KOTLINX_COROUTINE)
testImplementation(Dependencies.SPRING_TEST)
testImplementation(Dependencies.COROUTINE_TEST)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,40 @@ import com.xquare.v1userservice.user.api.CreateUserInPendingStateProcessor
import com.xquare.v1userservice.user.api.UpdateUserCreatedStateStepProcessor
import com.xquare.v1userservice.user.api.dtos.CreatUserDomainRequest
import com.xquare.v1userservice.user.spi.PasswordEncoderSpi
import com.xquare.v1userservice.user.spi.SaveUserBaseApplicationSpi
import com.xquare.v1userservice.user.spi.SaveUserBaseAuthoritySpi
import com.xquare.v1userservice.user.verificationcode.VerificationCode
import com.xquare.v1userservice.user.verificationcode.exceptions.VerificationCodeNotFoundException
import com.xquare.v1userservice.user.verificationcode.spi.VerificationCodeSpi
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch

@DomainService
class CreateUserApiImpl(
private val createUserInPendingStateProcessor: CreateUserInPendingStateProcessor,
private val updateUserCreatedStateStepProcessor: UpdateUserCreatedStateStepProcessor,
private val saveUserBaseAuthoritySpi: SaveUserBaseAuthoritySpi,
private val verificationCodeSpi: VerificationCodeSpi,
private val passwordEncoderSpi: PasswordEncoderSpi
private val passwordEncoderSpi: PasswordEncoderSpi,
private val saveUserBaseApplicationSpi: SaveUserBaseApplicationSpi
) : CreateUserApi {
override suspend fun saveUser(creatUserDomainRequest: CreatUserDomainRequest): User {
override suspend fun saveUser(creatUserDomainRequest: CreatUserDomainRequest): User = coroutineScope {
val verificationCode = verificationCodeSpi.getByCode(creatUserDomainRequest.verificationCode)
?: throw VerificationCodeNotFoundException("Verification Code Not Found")
val domainUser = verificationCode.toStudentUser(creatUserDomainRequest)
val savedUser = createUserInPendingStateProcessor.processStep(domainUser)
saveUserBaseAuthoritySpi.processStep(savedUser.id)

launch {
saveUserBaseAuthoritySpi.processStep(savedUser.id)
}

launch {
saveUserBaseApplicationSpi.processStep(savedUser.id)
}

updateUserCreatedStateStepProcessor.processStep(savedUser.id)
return savedUser

savedUser
}

private fun VerificationCode.toStudentUser(creatUserDomainRequest: CreatUserDomainRequest) = User(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.xquare.v1userservice.user.spi

import com.xquare.v1userservice.annotations.Spi
import java.util.UUID

@Spi
interface SaveUserBaseApplicationSpi {
suspend fun processStep(userId: UUID)
}
2 changes: 0 additions & 2 deletions user-infrastructure/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ dependencies {
implementation(Dependencies.MUTINY_KOTLIN)
implementation(Dependencies.MUTINY_REACTOR)
implementation(Dependencies.COROUTINE_REACTOR)
implementation(Dependencies.COROUTINE_JDK)
implementation(Dependencies.REACTOR_COROUTINE_EXTENSION)
implementation(Dependencies.KOTLINX_COROUTINE)
implementation(Dependencies.WEBFLUX)
implementation(Dependencies.VALIDATION)
implementation(Dependencies.JACKSON)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.xquare.v1userservice.application.properties

import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.ConstructorBinding

@ConstructorBinding
@ConfigurationProperties(prefix = "service.application")
class ApplicationProperties(
val host: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.xquare.v1userservice.user.spi

import com.xquare.v1userservice.application.properties.ApplicationProperties
import com.xquare.v1userservice.user.spi.dtos.SaveUserBaseApplicationRequest
import java.util.UUID
import org.springframework.stereotype.Repository
import org.springframework.web.reactive.function.client.WebClient

@Repository
class SaveUserBaseApplicationSpiImpl(
private val webClient: WebClient,
private val applicationProperties: ApplicationProperties
) : SaveUserBaseApplicationSpi {
override suspend fun processStep(userId: UUID) {
val baseApplicationRequest = buildBaseApplicationRequest(userId)

sendPostApplicationDefaultValue(baseApplicationRequest)
}

private fun buildBaseApplicationRequest(userId: UUID) =
SaveUserBaseApplicationRequest(userId)

private fun sendPostApplicationDefaultValue(saveUserBaseApplicationRequest: SaveUserBaseApplicationRequest) =
webClient.post()
.uri {
it.host(applicationProperties.host)
.path("/applications/signup")
.build()
}
.bodyValue(saveUserBaseApplicationRequest)
.retrieve()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.xquare.v1userservice.user.spi.dtos

import java.util.UUID

data class SaveUserBaseApplicationRequest(
val userId: UUID
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xquare.v1userservice.verificationcode
package com.xquare.v1userservice.user.verificationcode

import java.time.LocalDate
import java.util.UUID
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.xquare.v1userservice.verificationcode.spi
package com.xquare.v1userservice.user.verificationcode.spi

import com.linecorp.kotlinjdsl.query.HibernateMutinyReactiveQueryFactory
import com.linecorp.kotlinjdsl.querydsl.expression.col
import com.linecorp.kotlinjdsl.selectQuery
import com.xquare.v1userservice.user.verificationcode.VerificationCode
import com.xquare.v1userservice.user.verificationcode.spi.VerificationCodeSpi
import org.springframework.stereotype.Repository

@Repository
Expand Down
2 changes: 2 additions & 0 deletions user-infrastructure/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ management:
service:
authority:
host: ${AUTHORITY_SERVICE_HOST}
application:
host: ${AUTHORITY_SERVICE_HOST}

jwt:
secret-key: ${JWT_SECRET_KEY}
Expand Down

0 comments on commit 448f95b

Please sign in to comment.