diff --git a/src/main/kotlin/backendsquid/buckpal/account/adapter/in/web/SendMoneyController.kt b/src/main/kotlin/backendsquid/buckpal/account/adapter/in/web/SendMoneyController.kt index 09cb65b..da6129d 100644 --- a/src/main/kotlin/backendsquid/buckpal/account/adapter/in/web/SendMoneyController.kt +++ b/src/main/kotlin/backendsquid/buckpal/account/adapter/in/web/SendMoneyController.kt @@ -2,6 +2,7 @@ package backendsquid.buckpal.account.adapter.`in`.web import backendsquid.buckpal.account.application.port.`in`.SendMoneyCommand import backendsquid.buckpal.account.application.port.`in`.SendMoneyUseCase +import backendsquid.buckpal.account.application.service.SendMoneyResult import org.springframework.validation.annotation.Validated import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping @@ -21,7 +22,7 @@ class SendMoneyController( @PathVariable("sourceAccountId") @Positive sourceAccountId: Long, @PathVariable("targetAccountId") @Positive targetAccountId: Long, @PathVariable("amount") @Positive amount: Long, - ): Boolean { + ): SendMoneyResult { val command = SendMoneyCommand( sourceAccountId = sourceAccountId, targetAccountId = targetAccountId, @@ -34,7 +35,7 @@ class SendMoneyController( @PostMapping("/accounts/send") fun sendMoneyByBody( @RequestBody @Valid sendMoneyResource: SendMoneyResource - ): Boolean { + ): SendMoneyResult { val command = SendMoneyCommand( sourceAccountId = sendMoneyResource.sourceAccountId, targetAccountId = sendMoneyResource.targetAccountId, diff --git a/src/main/kotlin/backendsquid/buckpal/account/application/port/in/SendMoneyUseCase.kt b/src/main/kotlin/backendsquid/buckpal/account/application/port/in/SendMoneyUseCase.kt index 8df9e25..2a4c020 100644 --- a/src/main/kotlin/backendsquid/buckpal/account/application/port/in/SendMoneyUseCase.kt +++ b/src/main/kotlin/backendsquid/buckpal/account/application/port/in/SendMoneyUseCase.kt @@ -1,5 +1,7 @@ package backendsquid.buckpal.account.application.port.`in` +import backendsquid.buckpal.account.application.service.SendMoneyResult + interface SendMoneyUseCase { - fun sendMoney(command: SendMoneyCommand): Boolean + fun sendMoney(command: SendMoneyCommand): SendMoneyResult } diff --git a/src/main/kotlin/backendsquid/buckpal/account/application/service/SendMoneyResult.kt b/src/main/kotlin/backendsquid/buckpal/account/application/service/SendMoneyResult.kt new file mode 100644 index 0000000..415efc8 --- /dev/null +++ b/src/main/kotlin/backendsquid/buckpal/account/application/service/SendMoneyResult.kt @@ -0,0 +1,5 @@ +package backendsquid.buckpal.account.application.service + +data class SendMoneyResult( + val boolean : Boolean +) \ No newline at end of file diff --git a/src/main/kotlin/backendsquid/buckpal/account/application/service/SendMoneyService.kt b/src/main/kotlin/backendsquid/buckpal/account/application/service/SendMoneyService.kt index fa4c899..5d23bbc 100644 --- a/src/main/kotlin/backendsquid/buckpal/account/application/service/SendMoneyService.kt +++ b/src/main/kotlin/backendsquid/buckpal/account/application/service/SendMoneyService.kt @@ -16,7 +16,7 @@ class SendMoneyService( private val accountLock: AccountLock, private val updateAccountStatePort: UpdateAccountStatePort, ): SendMoneyUseCase { - override fun sendMoney(command: SendMoneyCommand): Boolean { + override fun sendMoney(command: SendMoneyCommand): SendMoneyResult { val baseline = LocalDateTime.now().minusDays(10) val sourceAccount = loadAccountPort.loadAccount( accountId = command.sourceAccountId, @@ -30,13 +30,13 @@ class SendMoneyService( accountLock.lockAccount(sourceAccount.id) if (!sourceAccount.withdraw(money = command.money, targetAccountId = targetAccount.id)) { accountLock.releaseAccount(sourceAccount.id) - return false + return SendMoneyResult(false) } accountLock.lockAccount(targetAccount.id) if (!targetAccount.deposit(money = command.money, sourceAccountId = sourceAccount.id)) { accountLock.releaseAccount(targetAccount.id) - return false + return SendMoneyResult(false) } updateAccountStatePort.updateActivities(sourceAccount) @@ -45,6 +45,6 @@ class SendMoneyService( accountLock.releaseAccount(sourceAccount.id) accountLock.releaseAccount(targetAccount.id) - return true + return SendMoneyResult(true) } }