generated from aura-ascend/template-service
add TransactionService
This commit is contained in:
26
src/main/kotlin/ltd/lulz/service/TransactionService.kt
Normal file
26
src/main/kotlin/ltd/lulz/service/TransactionService.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
package ltd.lulz.service
|
||||
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import java.math.BigDecimal
|
||||
import java.util.UUID
|
||||
import ltd.lulz.model.AccountEntity
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
private val log = KotlinLogging.logger {}
|
||||
|
||||
@Service
|
||||
class TransactionService(
|
||||
private val accountService: AccountService,
|
||||
) {
|
||||
|
||||
@Transactional
|
||||
fun deposit(
|
||||
id: UUID,
|
||||
amount: BigDecimal,
|
||||
): Mono<AccountEntity> = accountService.getForUpdateById(id)
|
||||
.map { it.copy(amount = it.amount + amount) }
|
||||
.doOnNext { log.trace { "Deposited $amount to account ${it.id}" } }
|
||||
.flatMap { accountService.save(it) }
|
||||
}
|
||||
Reference in New Issue
Block a user