We now need to open up our moderation service and make sure that we've got some code inside there to
handle this comment.
Created event so as soon as we receive that comment we'll then do some checking on the content of the
comments and then we're going to attempt to emit comment moderated.
So let's go ahead and give it a shot.
Back inside my editor I will find the moderation service.
Inside there I'll find the index dot as file so we've got this post request handler right here to watch
for any request going to our events end point.
So this is where we are going to receive an event from our broker.
Remember that the event itself is going to be contained on the wrecked body property because we are
receiving all these events as simple post requests for right now so off of that record body property.
We will pull off the events type and the data associated with it will then take a look at the type and
we'll say if the type is equal to comment created then we want to go through this entire comment moderation
thing.
The first thing to do inside of here is decide whether or not to approve or reject the comment to do
so.
We're gonna set up a ternary expression we'll say con status is going to be data dot content.
Remember that is the actual content of the comment itself.
We're going to check to see if that includes the string of orange if it does that we want to assign
rejected to status.
Otherwise we'll assign approved like so
now that we've moderate the comment we've got the status right here.
So now we need to make sure that we emit this comment.
Moderated event so we're gonna make a post request over to our event bus just as we've done several
times.
We will make sure that we include the comments along with the new updated status
so I will make a post request to H TTP Colin flash flash local host and remember our event bus is at
four thousand five flash events then we will give this thing a type of comment moderated and for the
data we will include the comments I.D. as post I.D. the content itself and the updated status.
So we will say the idea.
This comment is data that I.D. The Post I.D. is data dot to post I.D. the status is going to be the
status that we just calculated right here and then finally the content will be data dot content.
Now one thing I want to point out right here is that I just kind of pulled these properties of I.D.
post I.D. and content off the top of my head.
I just kind of remembered them but I could have very easily forgotten the different properties that
were contained inside of an event of type common created.
You and I know what is inside of the comic created event because we were just looking at the definition
of that event a moment ago when it was emitted from our comment service.
So here's the comment service.
Here's where we create that event so we can look back at this thing right here and very easily see the
different properties that comment created has.
Well I think you can kind of imagine that if we were working on a large system understanding the different
properties that were contained inside of any given events can be really challenging deftly without a
doubt would be hard to remember off the top of your head.
So to answer we would want some kind of documentation or something like that to reflect or kind of document
what different properties exist inside of every event that exist inside of our application.
That's just what you want you to keep in your mind right now because it's going to be very relevant
later on OK.
So now next up we made use of the awake keyword inside of here.
Let's make sure that we mark this function as async.
And then finally right after the closing curly brace of the if statement we do need to make sure that
we eventually send off a response.
Otherwise this request handler is just going to hang OK.
So it looks good.
So this gets us caught up to creating this comment moderated event and send it off to our event bus.
There is one little thing that we need to make sure we do very quickly.
Right now our event bus is not sending any events to the moderation service just because we created
the moderation service after we made the event bus.
Let's make sure that whenever the event bus reads or receives a comment it sends it out to the moderation
service as well so back inside of my event bus directory.
I'll find the next dot jazz file right years where we receive all the different events and we just turn
right back around and send them off to all these different running services.
So again 4000 is posts comments query and we just have not added in the moderation one just yet.
So let's just run those lines down and then just make sure we update the port to four thousand three
which is where our moderation service is running at.
I'll say this file and close it get.
So let's take another pause right here.
When we come back the next video we're going to make sure that when the event bus receives come at moderated
and sends it over to comments service we're going to make sure that we receive that event inside of
comments service.
Take a look at these status property update the status of the appropriate comment and then emit this
comment.
Updated event as well.
So still a little bit to do was take care of that in just a moment.