I have in my domain layer one entity called Product.
class Product{
String barcode;
String name;
String barcode;
double price;
int amount;
}
My UI has a Product list and when I touch the barcode scanner button, the camera read a barcode and increment the Product in UI Product List. If there's no Product in List with the same barcode, the app will add this new Product, but if there's some Product with the same barcode, the app will increment the amount of this Product.
In which layer should I add this rule? Should I do this verification in UseCase? Or in Presenter? Because I could have 2 UseCases:
- The first one will expect a barcode, and will return a Product with the same barcode.
- The second will expect a Product, and will increment the Product amount and return itself.
And I could use the Presenter to verify if in list has some product with the same barcode, if there's, the Presenter will call the second UseCase to increment the Product amount. Else, the Presenter will call the first UseCase to return a new Product and then, the Presenter will add to List.
Or Should I do this all verification in UseCase? I mean, the Presenter always will call just a UseCase that increment the Product and expect all the List and return all the List.
So my UseCase will verify the List passed as a parameter, if the Product exists in list, the UseCase will increment and return the List, if the Product doesn't exists, the UseCase will return the List with the new Product.
I know that UseCase should have all the business rule, and this rule "add a product if it doesn't exists or increment it amount if it does" its like a business rule. But I don't know a way to make the UseCase use this rule.