leumas95

ReceiptEntity

Nov 17th, 2017
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.90 KB | None | 0 0
  1. package windall.console.account.api.persistence
  2.  
  3. import javax.persistence.*
  4. import java.math.BigDecimal
  5. import windall.console.account.api.model.TenantEntity
  6. import windall.console.account.api.dto.ReceiptDto
  7.  
  8. @Entity
  9. @Table(name="receipt")
  10. internal data class ReceiptEntity (
  11.        
  12.         @Id
  13.         @GeneratedValue(strategy = GenerationType.IDENTITY)
  14.         val id: Long? = null,
  15.        
  16.         val amount: BigDecimal,
  17.        
  18.         @ManyToOne(fetch = FetchType.EAGER)
  19.         @JoinColumn(name = "tenant_id")
  20.         val tenant: TenantEntity? = null
  21.  
  22. ) {
  23.    
  24.     @Suppress("unused")
  25.     private constructor() : this(amount = BigDecimal.ZERO)
  26.    
  27.     fun toDto(): ReceiptDto = ReceiptDto ( 
  28.             id = this.id!!,
  29.             amount = this.amount,
  30.             tenant = this.tenant!!.toDto()
  31.     )
  32.    
  33.     companion object {
  34.  
  35.         fun fromDto(dto: ReceiptDto) = ReceiptEntity (
  36.             id = dto.id,
  37.             amount = dto.amount,
  38.             tenant = TenantEntity.fromDto(dto.tenant)
  39.         )
  40.  
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment