Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save dnno/020606a9b7e2b912e2993bbb9bfe008c to your computer and use it in GitHub Desktop.
@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