Skip to content

Instantly share code, notes, and snippets.

@jeroenr
Created July 8, 2021 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroenr/c8b625847dd1567e23476e8485675a85 to your computer and use it in GitHub Desktop.
Save jeroenr/c8b625847dd1567e23476e8485675a85 to your computer and use it in GitHub Desktop.
Application Service example
open class DepositOrchestrationService(
private val depositService: DepositService,
private val userAccountRepositoryPort: UserAccountRepositoryPort,
private val userAccountEventPublisherPort: UserAccountEventPublisherPort
) {
@Transactional
open suspend fun deposit(request: DepositRequestDto): DepositResponseDto? =
userAccountRepositoryPort.findById(request.userId)?.let { userAccount ->
val oldBalance = userAccount.balance
val updated = depositService.deposit(userAccount, request.amount)
userAccountRepositoryPort.save(updated)
userAccountEventPublisherPort.publishUserAccountUpdated(
userAccount.id,
"Updated balance: $oldBalance -> ${updated.balance}"
)
DepositResponseDto(request.userId, oldBalance, updated.balance)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment