Vedran
02/04/2024, 12:41 PMclass MyMapper {
companion object AccountMapper {
fun Account.toDto() = AccountDto(
id, firstName, lastName, username, email, password, role, createdAt, lastModified,null
)
fun AccountDto.toEntity() = Account(
id, firstName, lastName, username, email, password, role, createdAt, lastModified
)
}
}
And without companion object (if I just delete "companion object AccountMapper" and leave functions) ... it does not?
Of course if there are some recomendations about how to handle mapping, please share.kenkyee
02/04/2024, 2:23 PMraphadlts
02/04/2024, 5:35 PMashmelev
02/04/2024, 5:56 PMpackage com.tempest.fuels.dbservices.mapper
import com.example.dto.CompanyDto
import com.example.domain.Company
import java.time.ZoneId
import java.util.*
fun Company.toDto(): CompanyDto =
CompanyDto(
extId = this.extId.toString(),
name = this.name,
description = this.description,
createdAt = this.createdAt.atZone(ZoneId.of("UTC")),
updatedAt = this.updatedAt.atZone(ZoneId.of("UTC"))
)
fun CompanyDto.toEntity(): Company =
Company(
name = this.name,
description = this.description,
createdAt = this.createdAt.toLocalDateTime(),
updatedAt = this.updatedAt.toLocalDateTime()
).also { e -> e.enabled = this.enabled; e.extId = UUID.fromString(this.extId) }
fun List<Company>.toDto(): List<CompanyDto> =
this.map { it.toDto() }
fun List<CompanyDto>.toEntities(): List<Company> =
this.map { it.toEntity() }
ashmelev
02/04/2024, 5:59 PMAndrew O'Hara
02/04/2024, 7:30 PMraphadlts
02/04/2024, 8:00 PMVedran
02/04/2024, 9:39 PMashmelev
02/04/2024, 10:01 PM