restoopdomain-driven-designclean-architectureuse-case

Relating creation and update request use cases to entity in clean architecture REST


Let's say I am building a basic REST allowing CRUD operations on some object type A.

I am using clean architecture, so

Now, I would like to implement the Update Use Case. The format that this use case knows to how to handle is not exactly A, but a different, similar model that can have missing fields (a user my want to only update some of his object's fields). This is also the model used by my Data Access port interface, as it needs to be the same format the Update Use Case uses.

My question is, how, in this scenario, does my server enforce the application agnostic (domain) business rules? At no point does the update request gets translated through the domain definition of A. My Update Request cannot extend or contain A in any real manner, since it may contain even just one field of it, or no fields at all.

In my trying to solve this problem on my IRL job, I put the Update Request in the domain layer, including app agnostic rules into that model "by hand". Surely that is the wrong approach, since the Update Request is definitely an application specific format.

Is there a known, recommended way to handle this issue?


Solution

  • What I usually do in these cases is:

    Now, I would like to implement the Update Use Case. The format that this use case knows to how to handle is not exactly A, but a different, similar model that can have missing fields (a user my want to only update some of his object's fields).

    Let's call it ToChangeA

    This is also the model used by my Data Access port interface, as it needs to be the same format the Update Use Case uses.

    What's wrong here is that your DataAccessPortInterface should accept only instancies of A, not directly ToChangeA. And you get your updated instance of type A using the method A.update(ToChangeA) of the domain layer.

    I hope it's clearer now