1 00:00:00,890 --> 00:00:03,930 We've now got some scaffold put together for moderation service. 2 00:00:03,930 --> 00:00:07,910 So now we need to go round to all three of these different services and make a couple of changes to 3 00:00:07,910 --> 00:00:13,580 each ones in some cases we need to tweak an event that already exists and in some cases we need to add 4 00:00:13,580 --> 00:00:15,170 in a new event. 5 00:00:15,170 --> 00:00:19,790 We're gonna go through this step by step and kind of follow the actual workflow of a user submitting 6 00:00:19,820 --> 00:00:20,820 a comment. 7 00:00:20,910 --> 00:00:23,360 Just think about what happens when a user submits a comment. 8 00:00:23,360 --> 00:00:25,300 Remember right now we persist. 9 00:00:25,310 --> 00:00:31,840 A new comment inside of our common service at present we are just storing that comments I.D. and content. 10 00:00:31,880 --> 00:00:35,540 We probably also want to store that comments status as well. 11 00:00:35,540 --> 00:00:39,180 Whether it is pending moderation approved or rejected. 12 00:00:39,200 --> 00:00:43,760 So as soon as the user submits a comment we need to make sure that we store in addition to everything 13 00:00:43,760 --> 00:00:45,550 else a status of pending. 14 00:00:45,590 --> 00:00:48,930 To say this comment is still awaiting moderation. 15 00:00:49,010 --> 00:00:50,990 Let's open up our code Ed right now. 16 00:00:50,990 --> 00:00:53,920 We're gonna find our common service and make that change right away. 17 00:00:54,780 --> 00:00:56,990 It's going to go back over to my editor. 18 00:00:56,990 --> 00:00:59,060 I'll find my comment service. 19 00:00:59,060 --> 00:01:03,210 Inside there is my index j ust file. 20 00:01:03,240 --> 00:01:05,120 Then go down to where we create a new comment. 21 00:01:05,130 --> 00:01:09,980 Inside this post your quest handler right here so let's read through this code really quickly and just 22 00:01:09,980 --> 00:01:11,920 get a quick reminder of what's going on. 23 00:01:11,960 --> 00:01:18,430 We generate the random I.D. we get the content the comment we then get the list of comments that already 24 00:01:18,430 --> 00:01:24,700 exists that is associated with the given post and then right here is where we create the actual comment 25 00:01:24,700 --> 00:01:25,600 itself. 26 00:01:25,600 --> 00:01:32,050 So this object that is the comment we want to add into that object this new status property and by default 27 00:01:32,080 --> 00:01:39,790 it should always be pending so inside that object I'll add in a new property of pending or submit status 28 00:01:41,220 --> 00:01:42,050 that's better. 29 00:01:43,990 --> 00:01:46,910 Of pending like so okay. 30 00:01:46,970 --> 00:01:48,180 So that's step one. 31 00:01:48,320 --> 00:01:51,270 Let's go back over to our diagram and figure out what to do next. 32 00:01:51,840 --> 00:01:52,910 So step number two. 33 00:01:52,920 --> 00:01:59,790 Remember whenever this whenever we create a new comment we then immediately emit a new event and that 34 00:01:59,790 --> 00:02:06,790 event is the comment created event that's going to go into we are event buzz and then get sent over 35 00:02:06,820 --> 00:02:11,880 to the moderation service and the query service. 36 00:02:12,250 --> 00:02:16,690 Remember that we are sending it over to the query service so that the query service can immediately 37 00:02:16,750 --> 00:02:22,090 store that comment and the entire idea there was that we want to make sure the query service as soon 38 00:02:22,090 --> 00:02:27,670 as possible had a copy of that comment so that if a user refresh this page after adding a new comment 39 00:02:27,670 --> 00:02:32,260 they could immediately see it on the screen as opposed to waiting for some moderation event coming out 40 00:02:32,260 --> 00:02:38,280 of the moderation service so we need to open up our query service now and we need to make sure that 41 00:02:38,280 --> 00:02:44,630 when we send over that event we take off the status property from the event and save it inside the query 42 00:02:44,630 --> 00:02:46,290 service as well. 43 00:02:46,310 --> 00:02:53,570 We also need to make sure that the event itself also includes that status property so let's go to our 44 00:02:53,570 --> 00:02:55,360 comment service first. 45 00:02:55,520 --> 00:02:57,640 Here's where we were just looking at a moment ago. 46 00:02:57,830 --> 00:03:00,480 This is where we create the comment created event. 47 00:03:00,560 --> 00:03:03,450 Right now it does not reflect the status of the comment. 48 00:03:03,530 --> 00:03:10,040 So let's add in that status right now in the data property I'll add in status of pending. 49 00:03:10,050 --> 00:03:15,360 So now when this event goes over to our query service the query service is going to understand OK a 50 00:03:15,360 --> 00:03:19,330 comment was created and its status is pending. 51 00:03:19,350 --> 00:03:21,390 So now we can go and open up our query service. 52 00:03:21,390 --> 00:03:25,650 We're going to make sure that when receives this event it persists that little extra piece of information 53 00:03:25,650 --> 00:03:31,430 that we are now adding in of status pending so I will now go over to my query service. 54 00:03:31,430 --> 00:03:37,130 Here's the index not just file inside their I'll go down to our code where we are handling a comment 55 00:03:37,130 --> 00:03:45,420 created event so we're going to pull off that new status property that we just added in and we'll make 56 00:03:45,420 --> 00:03:50,790 sure that when we add in this comment to our array of comments we also persist the status flag as well 57 00:03:50,850 --> 00:03:54,210 like so OK. 58 00:03:54,300 --> 00:03:56,280 So that looks good. 59 00:03:56,440 --> 00:03:56,790 All right. 60 00:03:56,800 --> 00:03:58,760 That gets us up to this point in time. 61 00:03:58,770 --> 00:04:03,580 So now the next we need to do is make sure that we also handle this common creation inside the moderation 62 00:04:03,580 --> 00:04:04,440 service. 63 00:04:04,630 --> 00:04:09,520 Remember that the entire goal here is to actually look at that content property inside that event and 64 00:04:09,520 --> 00:04:16,270 see if it has the word orange or not if it has the word orange then we're going to emit comment moderated 65 00:04:16,330 --> 00:04:21,770 with a status of rejected otherwise will come comment moderated with a status of approved. 66 00:04:21,790 --> 00:04:25,720 Let's take a quick pause right here however and then continue with moderation service in just a moment.