Created
July 13, 2020 14:26
-
-
Save sberoch/6d7e31dd998a559addd305340eac1478 to your computer and use it in GitHub Desktop.
This file contains 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
class CharacterRepository @Inject constructor( | |
private val remoteDataSource: CharacterRemoteDataSource, | |
private val localDataSource: CharacterDao | |
) { | |
fun getCharacter(id: Int) = performGetOperation( | |
databaseQuery = { localDataSource.getCharacter(id) }, | |
networkCall = { remoteDataSource.getCharacter(id) }, | |
saveCallResult = { localDataSource.insert(it) } | |
) | |
fun getCharacters() = performGetOperation( | |
databaseQuery = { localDataSource.getAllCharacters() }, | |
networkCall = { remoteDataSource.getCharacters() }, | |
saveCallResult = { localDataSource.insertAll(it.results) } | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment