Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package windall.console.account.api.model
- import javax.persistence.*
- import java.math.BigDecimal
- import java.time.LocalDate
- import windall.console.account.api.dto.TenantDto
- import windall.console.account.api.dto.ReceiptDto
- import windall.console.account.api.persistence.ReceiptEntity
- @Entity
- @Table(name="tenant")
- internal data class TenantEntity (
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- val id: Long? = null,
- val name: String,
- val weeklyRent: BigDecimal,
- val paidTill: LocalDate = LocalDate.now(),
- val rentCredit: BigDecimal = BigDecimal(0),
- @OneToMany(mappedBy = "tenant", cascade = arrayOf(CascadeType.ALL), fetch = FetchType.EAGER)
- val receipts: List<ReceiptEntity> = emptyList()
- ) {
- @Suppress("unused")
- private constructor() : this(name = "", weeklyRent = BigDecimal.ZERO)
- fun toDto(): TenantDto = TenantDto (
- id = this.id!!,
- name = this.name,
- weeklyRent = this.weeklyRent,
- paidTill = this.paidTill,
- rentCredit = this.rentCredit,
- receipts = this.receipts.map { it.toDto() }.toMutableList()
- )
- companion object {
- fun fromDto(dto: TenantDto) = TenantEntity (
- id = dto.id,
- name = dto.name,
- weeklyRent = dto.weeklyRent,
- paidTill = dto.paidTill,
- rentCredit = dto.rentCredit,
- receipts = dto.receipts.map { ReceiptEntity.fromDto(it) }
- )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment