Created
September 3, 2019 23:01
-
-
Save DenisBronx/983fc99cdf83dafcb6778ca2c130f4d3 to your computer and use it in GitHub Desktop.
Repository Pattern Repository getWishlist
This file contains hidden or 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 getWishlist(): Single<Result<List<Product>>> { | |
return productApiService.getWishlist(productPreferences.getFavourites()).map { | |
when (it) { | |
is Result.Success -> Result.Success(mapWishlist(it.value)) | |
is Result.Failure -> Result.Failure<List<Product>>(it.throwable) | |
} | |
} | |
} | |
private fun mapWishlist(wishlist: List<NetworkProduct>): List<Product> { | |
return wishlist.map { | |
productDataMapper.map(DataProduct(it, true)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment