Created
September 3, 2019 22:58
-
-
Save DenisBronx/d21890aef45030b91421bf8cad630414 to your computer and use it in GitHub Desktop.
Repository Pattern Repository getProducts
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 ProductRepositoryImpl( | |
private val productApiService: ProductApiService, | |
private val productDataMapper: Mapper<DataProduct, Product>, | |
private val productPreferences: ProductPreferences | |
) : ProductRepository { | |
override fun getProducts(): Single<Result<List<Product>>> { | |
return productApiService.getProducts().map { | |
when(it) { | |
is Result.Success -> Result.Success(mapProducts(it.value)) | |
is Result.Failure -> Result.Failure<List<Product>>(it.throwable) | |
} | |
} | |
} | |
private fun mapProducts(networkProductList: List<NetworkProduct>): List<Product> { | |
return networkProductList.map { | |
productDataMapper.map(DataProduct(it, productPreferences.isFavourite(it.id))) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment