generated from aura-ascend/template-service
add AccountUtil.kt
- AccountEntity toResponse - Account Request toEntity
This commit is contained in:
18
src/main/kotlin/ltd/lulz/util/AccountUtil.kt
Normal file
18
src/main/kotlin/ltd/lulz/util/AccountUtil.kt
Normal file
@@ -0,0 +1,18 @@
|
||||
package ltd.lulz.util
|
||||
|
||||
import java.math.RoundingMode.DOWN
|
||||
import ltd.lulz.model.Account
|
||||
import ltd.lulz.model.AccountEntity
|
||||
import org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
|
||||
fun Account.Request.toEntity(): AccountEntity = AccountEntity(
|
||||
name = name,
|
||||
amount = amount.setScale(2, DOWN),
|
||||
)
|
||||
|
||||
fun AccountEntity.toResponse(): Account.Response = Account.Response(
|
||||
id = id ?: throw ResponseStatusException(INTERNAL_SERVER_ERROR),
|
||||
name = name,
|
||||
amount = amount,
|
||||
)
|
||||
Reference in New Issue
Block a user