1
00:00:01,130 --> 00:00:06,500
In this video, we are going to create a controller to update a comment.

2
00:00:06,530 --> 00:00:11,020
Again, the concept is going to be the same for updating a post.

3
00:00:11,030 --> 00:00:15,290
So let's get into post and let's copy the logic.

4
00:00:15,290 --> 00:00:17,540
So this is the update.

5
00:00:17,540 --> 00:00:24,860
So inside the try, I'm going to copy the entire logic as that.

6
00:00:24,860 --> 00:00:32,990
And back to the command controller, which is this and let's collapse this and here is the implementation

7
00:00:33,110 --> 00:00:34,430
I'm going to paste.

8
00:00:34,430 --> 00:00:35,840
The one I copied.

9
00:00:36,080 --> 00:00:39,140
The first step is find the comment.

10
00:00:39,530 --> 00:00:44,060
So let me change this one to find the comment.

11
00:00:45,050 --> 00:00:46,580
Likewise this.

12
00:00:48,130 --> 00:00:53,410
And then check if the comment belongs to the user.

13
00:00:53,530 --> 00:00:54,100
All right.

14
00:00:54,100 --> 00:00:59,320
So the same concept here, we are going to find the comment by ID.

15
00:00:59,350 --> 00:01:05,740
So here is going to be the comment model and here is going to be comment.

16
00:01:06,430 --> 00:01:13,630
And on the comment, we have the user and then we are comparing to the look in user, which is this.

17
00:01:13,630 --> 00:01:18,070
The message would be you are not allowed to update this comment.

18
00:01:20,300 --> 00:01:25,760
And if everything goes right, then you go ahead and update the comment.

19
00:01:25,760 --> 00:01:29,750
And here is going to be as the comments update updated.

20
00:01:33,160 --> 00:01:33,670
All right.

21
00:01:33,670 --> 00:01:36,040
And let's send that.

22
00:01:37,550 --> 00:01:38,660
For this one.

23
00:01:38,660 --> 00:01:44,870
We are not uploading any image, so let's remove this and let's remove the category.

24
00:01:44,960 --> 00:01:46,850
What we want is a message.

25
00:01:46,850 --> 00:01:53,270
So going to be the message and the value can be found on the rec, the body, the message.

26
00:01:54,110 --> 00:01:55,650
All right, that is it, guys.

27
00:01:55,670 --> 00:01:59,270
Again, we need to put this one behind authentication.

28
00:01:59,270 --> 00:02:02,780
So let me send the error here in case we have one.

29
00:02:02,780 --> 00:02:12,320
So next and pass in the app error and then the actual message, could it be error message?

30
00:02:12,320 --> 00:02:14,840
So let's pass next into this.

31
00:02:15,860 --> 00:02:18,380
Likewise the delete.

32
00:02:18,410 --> 00:02:32,060
Let's go to pass next into that and inside here pass next and then the app error and error message or

33
00:02:32,060 --> 00:02:38,330
we can we pass in the entire error so let's remove this one to make it as error.

34
00:02:38,900 --> 00:02:39,620
All right.

35
00:02:39,620 --> 00:02:40,770
So that is it.

36
00:02:40,790 --> 00:02:43,730
What about the fetching single?

37
00:02:43,760 --> 00:02:55,610
Let's also pass in the next and then here, let's send the error by calling next, then pass in the

38
00:02:55,610 --> 00:03:00,590
app error and then the message, the error into that.

39
00:03:00,920 --> 00:03:01,670
All right.

40
00:03:01,670 --> 00:03:03,000
What about the details?

41
00:03:03,020 --> 00:03:09,980
Let's also pass the next here and let's copy this one going to be the same concept.

42
00:03:10,400 --> 00:03:11,110
Okay.

43
00:03:11,120 --> 00:03:12,820
So moment of truth.

44
00:03:12,830 --> 00:03:15,680
Let's go ahead and update a comment.

45
00:03:16,040 --> 00:03:20,720
So let's create a new comment with the same value as good.

46
00:03:20,720 --> 00:03:31,280
Let's copy this ID and click on Update and let's provide the ID again, let's put the end points behind

47
00:03:31,280 --> 00:03:34,000
authentication for update, which is this.

48
00:03:34,010 --> 00:03:36,140
We're going to be as protected.

49
00:03:36,740 --> 00:03:46,220
So let's pass in the message as that and now change this one to the best and hit send.

50
00:03:47,710 --> 00:03:51,130
Well, I got an error, so let's have a look.

51
00:03:51,640 --> 00:03:54,130
Well, app error is not defined.

52
00:03:54,130 --> 00:04:00,130
Meaning less require the app error inside the controller of comment.

53
00:04:00,430 --> 00:04:07,570
So here const app error is equal to required.

54
00:04:10,010 --> 00:04:14,480
And inside the utils then app error.

55
00:04:15,540 --> 00:04:17,160
All right, so let's hit send.

56
00:04:17,760 --> 00:04:22,740
Well, you got this error meaning that cannot read properly of user list.

57
00:04:22,740 --> 00:04:25,440
Locate which line of code comments.

58
00:04:25,440 --> 00:04:27,150
Line number 92.

59
00:04:27,420 --> 00:04:38,370
So command, line number 92 for update, which is this This error was called meaning a kind of find

60
00:04:38,370 --> 00:04:41,100
the user on the comment.

61
00:04:41,280 --> 00:04:43,500
So what is the problem?

62
00:04:44,100 --> 00:04:47,330
Let's console.log the comment.

63
00:04:47,340 --> 00:04:50,280
So let's see what is inside the comments.

64
00:04:50,280 --> 00:04:51,990
So let's click on send.

65
00:04:52,080 --> 00:04:53,910
Let's check the terminal.

66
00:04:54,360 --> 00:05:02,430
And we got undefined meaning that there is no comment being found so we can even make a check.

67
00:05:02,430 --> 00:05:05,490
If there is no comment, then we can throw an error.

68
00:05:05,490 --> 00:05:06,120
Right.

69
00:05:06,120 --> 00:05:15,180
So here before we go ahead and then update, we are going to check if there is no comment, then we

70
00:05:15,180 --> 00:05:24,090
are going to return and call next, then pass in the app error the message by saying that comment not

71
00:05:24,090 --> 00:05:24,660
found.

72
00:05:29,120 --> 00:05:34,820
All right, So with this one, we can get beautiful message as comment not found.

73
00:05:34,820 --> 00:05:39,680
So let's check the route for comment and let's see if you have the ID.

74
00:05:39,710 --> 00:05:41,990
Yes, we have it as that.

75
00:05:41,990 --> 00:05:46,460
So let's go ahead and then create a new comment.

76
00:05:46,580 --> 00:05:52,190
So let me change this one to excellent and hit send.

77
00:05:53,540 --> 00:06:02,690
Now we have a comment being created so our copy the ID of this comment and I'll provide the ID for the

78
00:06:02,690 --> 00:06:04,520
update and hit send.

79
00:06:05,830 --> 00:06:09,130
And it has been updated successfully.

80
00:06:09,340 --> 00:06:10,210
All right, guys.

81
00:06:10,210 --> 00:06:18,550
So here ends the entire API for the blog application and you can improve this API if you want.

82
00:06:18,670 --> 00:06:23,670
What has left is how we can connect the API to the front end.

83
00:06:23,680 --> 00:06:26,140
So let's get into that in the next video.

