Created
May 7, 2024 11:58
-
-
Save MkhytarMkhoian/7ffd46f3eda5503a0a11869aa1fac077 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 FaresDataRepository( | |
private val faresLocalDataSource: FaresLocalDataSource, | |
private val faresRemoteDataSource: FaresRemoteDataSource, | |
private val backgroundDispatcher: CoroutineDispatcher = Dispatchers.IO, | |
) : FaresRepository { | |
override suspend fun getFares(ryderId: String): List<Fare> = withContext(backgroundDispatcher) { | |
if (faresLocalDataSource.isValid()) { | |
faresLocalDataSource.getData(ryderId).asDomain() | |
} else { | |
val fares = faresRemoteDataSource.getData(ryderId) | |
faresLocalDataSource.setFares(fares) | |
fares.asDomain() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment