1 00:00:01,660 --> 00:00:05,350 We now need to open up our moderation service and make sure that we've got some code inside there to 2 00:00:05,350 --> 00:00:06,310 handle this comment. 3 00:00:06,310 --> 00:00:12,790 Created event so as soon as we receive that comment we'll then do some checking on the content of the 4 00:00:12,790 --> 00:00:16,840 comments and then we're going to attempt to emit comment moderated. 5 00:00:16,840 --> 00:00:18,000 So let's go ahead and give it a shot. 6 00:00:19,360 --> 00:00:22,330 Back inside my editor I will find the moderation service. 7 00:00:22,330 --> 00:00:27,890 Inside there I'll find the index dot as file so we've got this post request handler right here to watch 8 00:00:27,890 --> 00:00:31,130 for any request going to our events end point. 9 00:00:31,280 --> 00:00:34,850 So this is where we are going to receive an event from our broker. 10 00:00:34,850 --> 00:00:39,410 Remember that the event itself is going to be contained on the wrecked body property because we are 11 00:00:39,410 --> 00:00:45,740 receiving all these events as simple post requests for right now so off of that record body property. 12 00:00:45,740 --> 00:00:52,710 We will pull off the events type and the data associated with it will then take a look at the type and 13 00:00:52,710 --> 00:00:58,800 we'll say if the type is equal to comment created then we want to go through this entire comment moderation 14 00:00:58,800 --> 00:01:00,670 thing. 15 00:01:00,870 --> 00:01:06,150 The first thing to do inside of here is decide whether or not to approve or reject the comment to do 16 00:01:06,150 --> 00:01:06,620 so. 17 00:01:06,620 --> 00:01:13,410 We're gonna set up a ternary expression we'll say con status is going to be data dot content. 18 00:01:13,410 --> 00:01:16,170 Remember that is the actual content of the comment itself. 19 00:01:17,010 --> 00:01:25,040 We're going to check to see if that includes the string of orange if it does that we want to assign 20 00:01:25,820 --> 00:01:28,370 rejected to status. 21 00:01:28,370 --> 00:01:32,270 Otherwise we'll assign approved like so 22 00:01:35,870 --> 00:01:38,930 now that we've moderate the comment we've got the status right here. 23 00:01:38,960 --> 00:01:41,750 So now we need to make sure that we emit this comment. 24 00:01:41,750 --> 00:01:46,910 Moderated event so we're gonna make a post request over to our event bus just as we've done several 25 00:01:46,910 --> 00:01:48,820 times. 26 00:01:48,910 --> 00:01:52,870 We will make sure that we include the comments along with the new updated status 27 00:01:55,770 --> 00:02:05,570 so I will make a post request to H TTP Colin flash flash local host and remember our event bus is at 28 00:02:05,570 --> 00:02:14,980 four thousand five flash events then we will give this thing a type of comment moderated and for the 29 00:02:14,980 --> 00:02:24,630 data we will include the comments I.D. as post I.D. the content itself and the updated status. 30 00:02:24,630 --> 00:02:25,830 So we will say the idea. 31 00:02:25,830 --> 00:02:36,340 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 32 00:02:36,340 --> 00:02:42,390 status that we just calculated right here and then finally the content will be data dot content. 33 00:02:44,440 --> 00:02:49,150 Now one thing I want to point out right here is that I just kind of pulled these properties of I.D. 34 00:02:49,240 --> 00:02:52,340 post I.D. and content off the top of my head. 35 00:02:52,480 --> 00:02:57,610 I just kind of remembered them but I could have very easily forgotten the different properties that 36 00:02:57,610 --> 00:03:01,120 were contained inside of an event of type common created. 37 00:03:01,330 --> 00:03:05,900 You and I know what is inside of the comic created event because we were just looking at the definition 38 00:03:05,900 --> 00:03:09,970 of that event a moment ago when it was emitted from our comment service. 39 00:03:09,970 --> 00:03:11,200 So here's the comment service. 40 00:03:11,200 --> 00:03:15,370 Here's where we create that event so we can look back at this thing right here and very easily see the 41 00:03:15,370 --> 00:03:18,460 different properties that comment created has. 42 00:03:18,490 --> 00:03:23,050 Well I think you can kind of imagine that if we were working on a large system understanding the different 43 00:03:23,050 --> 00:03:27,790 properties that were contained inside of any given events can be really challenging deftly without a 44 00:03:27,790 --> 00:03:29,860 doubt would be hard to remember off the top of your head. 45 00:03:30,580 --> 00:03:35,830 So to answer we would want some kind of documentation or something like that to reflect or kind of document 46 00:03:36,100 --> 00:03:41,620 what different properties exist inside of every event that exist inside of our application. 47 00:03:41,620 --> 00:03:45,070 That's just what you want you to keep in your mind right now because it's going to be very relevant 48 00:03:45,070 --> 00:03:48,270 later on OK. 49 00:03:48,320 --> 00:03:51,500 So now next up we made use of the awake keyword inside of here. 50 00:03:51,530 --> 00:03:53,940 Let's make sure that we mark this function as async. 51 00:03:54,200 --> 00:03:58,580 And then finally right after the closing curly brace of the if statement we do need to make sure that 52 00:03:58,580 --> 00:04:00,450 we eventually send off a response. 53 00:04:00,500 --> 00:04:04,680 Otherwise this request handler is just going to hang OK. 54 00:04:04,720 --> 00:04:05,650 So it looks good. 55 00:04:05,650 --> 00:04:11,780 So this gets us caught up to creating this comment moderated event and send it off to our event bus. 56 00:04:11,860 --> 00:04:14,920 There is one little thing that we need to make sure we do very quickly. 57 00:04:14,920 --> 00:04:20,110 Right now our event bus is not sending any events to the moderation service just because we created 58 00:04:20,110 --> 00:04:22,920 the moderation service after we made the event bus. 59 00:04:22,990 --> 00:04:28,450 Let's make sure that whenever the event bus reads or receives a comment it sends it out to the moderation 60 00:04:28,450 --> 00:04:34,050 service as well so back inside of my event bus directory. 61 00:04:34,060 --> 00:04:39,710 I'll find the next dot jazz file right years where we receive all the different events and we just turn 62 00:04:39,710 --> 00:04:43,430 right back around and send them off to all these different running services. 63 00:04:43,430 --> 00:04:49,910 So again 4000 is posts comments query and we just have not added in the moderation one just yet. 64 00:04:49,940 --> 00:04:54,590 So let's just run those lines down and then just make sure we update the port to four thousand three 65 00:04:54,860 --> 00:04:58,310 which is where our moderation service is running at. 66 00:04:58,450 --> 00:05:03,130 I'll say this file and close it get. 67 00:05:03,130 --> 00:05:04,640 So let's take another pause right here. 68 00:05:04,660 --> 00:05:10,900 When we come back the next video we're going to make sure that when the event bus receives come at moderated 69 00:05:11,020 --> 00:05:15,910 and sends it over to comments service we're going to make sure that we receive that event inside of 70 00:05:15,910 --> 00:05:17,590 comments service. 71 00:05:17,590 --> 00:05:23,710 Take a look at these status property update the status of the appropriate comment and then emit this 72 00:05:23,800 --> 00:05:24,440 comment. 73 00:05:24,460 --> 00:05:27,200 Updated event as well. 74 00:05:27,290 --> 00:05:29,680 So still a little bit to do was take care of that in just a moment.