Created
June 3, 2019 18:40
-
-
Save dnno/020606a9b7e2b912e2993bbb9bfe008c 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
| @Service | |
| @Transactional | |
| internal class JpaCityService(val cityRepo: CityRepository) : CityService { | |
| override fun retrieveCity(cityId: Long) : CityDto? { | |
| return cityRepo.findOne(cityId)?.toDto() | |
| } | |
| override fun retrieveCities() : List<CityDto> { | |
| return cityRepo.findAll().map { it.toDto() } | |
| } | |
| override fun addCity(city: CreateCityDto) : CityRepo { | |
| return cityRepo.save(CityEntity.fromDto(city)).toDto() | |
| } | |
| override fun updateCity(id: Long, city: UpdateCityDto): CityDto? { | |
| val currentCity = cityRepo.findOne(id) | |
| return if (currentCity != null) cityRepo.save(CityEntity.fromDto(city, currentCity)).toDto() | |
| else null | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment