1
votes

I am new to DDD design concepts but I'd like to clarify something as I read articles about it. Jimmy Boggard use the following words: "Nothing outside the Aggregate boundary can hold a reference to anything inside, except to the root Entity.", "Only Aggregate Roots can be obtained directly with database queries. Everything else must be done through traversal."

Let's say I want to delete a review of a post. Here as far as I understood, post is root. So all the communication with a review should be made through post object. That means I need to get both the id of aggregate root and the id of the aggregate entity as parameters of an HTTP delete request?

2

2 Answers

2
votes

That means I need to get both the id of aggregate root and the id of the aggregate entity as parameters of an HTTP delete request?

Short answer: yes.

Somewhat longer answer: in order to interact with an entity that is subordinate to an aggregate root, you need to route to the root (so you need the Id), and you need to pass to the root as arguments the information needed to specify the target entity.

DELETE doesn't support a request body; so the arguments need to be something that the origin server can recover from the URI alone (either the arguments are encoded into the URI, or the URI gives you access to a resource that knows what the arguments are).

Note: it's not immediately obvious that Review should be a subordinate entity in the Post aggregate. Aggregate design is about behaviors not relations. If modeling Review as a separate aggregate from Post makes your life easier, you should consider it.

0
votes

It would be more practical to do so but you don't absolutely have to. Your REST API doesn't have to be an exact reflection of your domain model - HTTP and DDD are two very different paradigms with their own constraints and view of the world.

A valid alternative would be to retrieve the correct Post based solely on the ReviewId and ask that Post to delete the Review

DELETE /reviews/1234

...
post = postRepository.getPostForReview(reviewId);
post.deleteReview(reviewId);

though I agree that in this particular instance, DELETE /posts/1234/reviews/5678 is probably a better URI.