Skip to content

Instantly share code, notes, and snippets.

@dnno
Created June 3, 2019 18:37
Show Gist options
  • Select an option

  • Save dnno/a6c8fcdde073fd9af82c82941076be58 to your computer and use it in GitHub Desktop.

Select an option

Save dnno/a6c8fcdde073fd9af82c82941076be58 to your computer and use it in GitHub Desktop.
@Entity
@Table(name="city")
internal data class CityEntity(
@Id val id: Long? = null,
val name: String,
val description: String? = null) {
fun toDto(): CityDto = CityDto(
id = this.id!!,
name = this.name,
description = this.description)
companion object {
fun fromDto(dto: CityDto) = CityEntity(
id = dto.id,
name = dto.name,
description = dto.description)
fun fromDto(dto: CreateCityDto) = CityEntity(
name = dto.name,
description = dto.description)
fun fromDto(dto: UpdateCityDto, defaultCity: CityEntity) = CityEntity(
id = defaultCity.id!!,
name = dto.name ?: defaultCity.name,
description = dto.description ?: defaultCity.description)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment