Hi! Im doing Clean Architecture pattern in my app....
# android
j
Hi! Im doing Clean Architecture pattern in my app. Let’s say I have a
Product
item. Now, that
Product
must contain
category
and
subcategory
. Currently, the API only returns the
guid
of the category and subcategory. Now the question is. Should the mapping of getting the
category
and
subcategory
from the API and putting them inside the
Product
class be inside the
data
module? OR I can put it inside my
GetProductUseCase
? If I choose the latter. So my usecase would look something like this:
Copy code
getProducts()
    .zip(repo.getCategory(), repo.getSubCategory())
    .flatMap { 
        product.category = category
        product.subcategory = subcategory
     }
What’s the best practice for this?
w
I’d say
data
module. My reasoning is that this is a shortcoming of the API, and ideally API would return product, category and subcategory in one call. Once the API is fixed you shouldn’t have to modify your use case to adjust to the new data layer behavior. Conversely if it was business requirement that category and subcategory must be fetched separately (e.g. because they change more often than the Product), or it was an application requirement (we need product very early and categories later on) only then I would move fetching them to some use case.
👍 1
💯 2
j
@wasyl Great insight. Thanks for the input! 💯 Appreciated.