generated from aura-ascend/template-service
27 lines
764 B
Kotlin
27 lines
764 B
Kotlin
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) }
|
|
}
|