Skip to content

Instantly share code, notes, and snippets.

@LukaKordic
Last active September 4, 2019 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LukaKordic/8faa3d499b51a2ef4274b4af40a450cf to your computer and use it in GitHub Desktop.
Save LukaKordic/8faa3d499b51a2ef4274b4af40a450cf to your computer and use it in GitHub Desktop.
class WeatherRepositoryImpl(private val weatherApi: WeatherApi,
private val weatherDao: WeatherDao) : BaseRepository<WeatherInfo, WeatherEntity>(), WeatherRepository {
override suspend fun getWeatherForLocation(location: String): Result<WeatherInfo> {
return fetchData(
apiDataProvider = {
weatherApi.getWeatherForLocation(location).getData(
fetchFromCacheAction = { weatherDao.getWeatherInfoForCity(location) },
cacheAction = { weatherDao.saveWeatherInfo(it) })
},
dbDataProvider = { weatherDao.getWeatherInfoForCity(location) }
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment