We've now got some scaffold put together for moderation service.
So now we need to go round to all three of these different services and make a couple of changes to
each ones in some cases we need to tweak an event that already exists and in some cases we need to add
in a new event.
We're gonna go through this step by step and kind of follow the actual workflow of a user submitting
a comment.
Just think about what happens when a user submits a comment.
Remember right now we persist.
A new comment inside of our common service at present we are just storing that comments I.D. and content.
We probably also want to store that comments status as well.
Whether it is pending moderation approved or rejected.
So as soon as the user submits a comment we need to make sure that we store in addition to everything
else a status of pending.
To say this comment is still awaiting moderation.
Let's open up our code Ed right now.
We're gonna find our common service and make that change right away.
It's going to go back over to my editor.
I'll find my comment service.
Inside there is my index j ust file.
Then go down to where we create a new comment.
Inside this post your quest handler right here so let's read through this code really quickly and just
get a quick reminder of what's going on.
We generate the random I.D. we get the content the comment we then get the list of comments that already
exists that is associated with the given post and then right here is where we create the actual comment
itself.
So this object that is the comment we want to add into that object this new status property and by default
it should always be pending so inside that object I'll add in a new property of pending or submit status
that's better.
Of pending like so okay.
So that's step one.
Let's go back over to our diagram and figure out what to do next.
So step number two.
Remember whenever this whenever we create a new comment we then immediately emit a new event and that
event is the comment created event that's going to go into we are event buzz and then get sent over
to the moderation service and the query service.
Remember that we are sending it over to the query service so that the query service can immediately
store that comment and the entire idea there was that we want to make sure the query service as soon
as possible had a copy of that comment so that if a user refresh this page after adding a new comment
they could immediately see it on the screen as opposed to waiting for some moderation event coming out
of the moderation service so we need to open up our query service now and we need to make sure that
when we send over that event we take off the status property from the event and save it inside the query
service as well.
We also need to make sure that the event itself also includes that status property so let's go to our
comment service first.
Here's where we were just looking at a moment ago.
This is where we create the comment created event.
Right now it does not reflect the status of the comment.
So let's add in that status right now in the data property I'll add in status of pending.
So now when this event goes over to our query service the query service is going to understand OK a
comment was created and its status is pending.
So now we can go and open up our query service.
We're going to make sure that when receives this event it persists that little extra piece of information
that we are now adding in of status pending so I will now go over to my query service.
Here's the index not just file inside their I'll go down to our code where we are handling a comment
created event so we're going to pull off that new status property that we just added in and we'll make
sure that when we add in this comment to our array of comments we also persist the status flag as well
like so OK.
So that looks good.
All right.
That gets us up to this point in time.
So now the next we need to do is make sure that we also handle this common creation inside the moderation
service.
Remember that the entire goal here is to actually look at that content property inside that event and
see if it has the word orange or not if it has the word orange then we're going to emit comment moderated
with a status of rejected otherwise will come comment moderated with a status of approved.
Let's take a quick pause right here however and then continue with moderation service in just a moment.