add AccountUtil.kt

- AccountEntity toResponse
- Account Request toEntity
This commit is contained in:
2025-09-11 12:56:36 +02:00
parent 79357e4f4d
commit dfadf203de
2 changed files with 93 additions and 0 deletions

View 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,
)