Created
June 3, 2019 18:37
-
-
Save dnno/a6c8fcdde073fd9af82c82941076be58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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