Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package windall.console.account.api.persistence
- import javax.persistence.*
- import java.math.BigDecimal
- import windall.console.account.api.model.TenantEntity
- import windall.console.account.api.dto.ReceiptDto
- @Entity
- @Table(name="receipt")
- internal data class ReceiptEntity (
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- val id: Long? = null,
- val amount: BigDecimal,
- @ManyToOne(fetch = FetchType.EAGER)
- @JoinColumn(name = "tenant_id")
- val tenant: TenantEntity? = null
- ) {
- @Suppress("unused")
- private constructor() : this(amount = BigDecimal.ZERO)
- fun toDto(): ReceiptDto = ReceiptDto (
- id = this.id!!,
- amount = this.amount,
- tenant = this.tenant!!.toDto()
- )
- companion object {
- fun fromDto(dto: ReceiptDto) = ReceiptEntity (
- id = dto.id,
- amount = dto.amount,
- tenant = TenantEntity.fromDto(dto.tenant)
- )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment