ddd-forum icon indicating copy to clipboard operation
ddd-forum copied to clipboard

Question about extending domain event

Open husniadil opened this issue 5 years ago • 0 comments

Hello @stemmlerjs,

I learn many things from your solidbook and direct me here. Not sure where I should post a question. Let me know if there's a specific channel/platform for QnA.

I look at the code on how the event is prepared. I believe this is the place, in the aggregate root.

https://github.com/stemmlerjs/ddd-forum/blob/9aceab286797b6b3f7db19bf1f78267cf93894e5/src/modules/forum/domain/post.ts#L242

It says, when the aggregate id is not null, then raise PostCreated event. It is created inside the create method.

However the create method is called from many places, like when you really want to create a new post from the use case, when you edit a post, even from the PostMap to convert DTO to domain object.

I mean like:

if the id from args is null, then it's considered a new post
otherwise it could be an update.

Now, let's take another case, we need to track another event like PostUpdated event, we need it only when the post is edited by the author, not by upvote/downvote.

By the snippet above, I assume that, when the id is not null, then we can prepare for the PostUpdated event.

When we execute a getPostByPostId from repo, it calls the PostMap to convert the PostModel to domain model (and prepare the PostUpdated event).

Since the getPostByPostId is called from the UpvoteComment use case, it's preparing the PostUpdated event that I don't expect.

How do you handle this kind of scenario?

husniadil avatar Aug 30 '20 03:08 husniadil