Skip to content

Instantly share code, notes, and snippets.

@DenisBronx
Last active September 5, 2020 06:10
Show Gist options
  • Save DenisBronx/d0331dd423ce5279729301031f5eabc0 to your computer and use it in GitHub Desktop.
Save DenisBronx/d0331dd423ce5279729301031f5eabc0 to your computer and use it in GitHub Desktop.
Repository Pattern components
// A wrapper for handling failing requests
sealed class Result<T> {
data class Success<T>(val value: T) : Result<T>()
data class Failure<T>(val throwable: Throwable) : Result<T>()
}
// A DataSource for the SharedPreferences
interface ProductPreferences {
fun isFavourite(id: String?): Boolean
}
// A DataSource for the Remote DB
interface ProductApiService {
fun getProducts(): Single<Result<List<NetworkProduct>>>
fun getWishlist(productIds: List<String>): Single<Result<List<NetworkProduct>>>
}
// A cluster of DTOs to be mapped into a Product
data class DataProduct(
val networkProduct: NetworkProduct,
val isFavourite: Boolean
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment