DbDataMapper.kt 838 B

12345678910111213141516171819202122232425
  1. package com.ted.weather.data.db
  2. import com.ted.weather.domain.model.Forecast
  3. import com.ted.weather.domain.model.ForecastList
  4. class DbDataMapper {
  5. fun convertFromDomain(forecast: ForecastList) = with(forecast) {
  6. val daily = dailyForecast.map { convertDayFromDomain(id, it) }
  7. CityForecast(id, city, country, daily)
  8. }
  9. private fun convertDayFromDomain(cityId: Long, forecast: Forecast) = with(forecast) {
  10. DayForecast(date, description, high, low, iconUrl, cityId)
  11. }
  12. fun convertToDomain(forecast: CityForecast) = with(forecast) {
  13. val daily = dailyForecast.map { convertDayToDomain(it) }
  14. ForecastList(_id, city, country, daily)
  15. }
  16. fun convertDayToDomain(dayForecast: DayForecast) = with(dayForecast) {
  17. Forecast(_id, date, description, high, low, iconUrl)
  18. }
  19. }