1
00:00:00,890 --> 00:00:05,870
In this video, we are going to add comments to a post.

2
00:00:05,900 --> 00:00:09,380
The hard work of the logic is done.

3
00:00:09,380 --> 00:00:12,020
That is the API implementation.

4
00:00:12,020 --> 00:00:16,610
So let's try to revisit and see the logic behind it.

5
00:00:16,730 --> 00:00:22,340
First of all, we are going to find the post that we want to add the comment to.

6
00:00:22,370 --> 00:00:32,060
Next is we go ahead and create and we push the comment into post and also we add the user into it and

7
00:00:32,060 --> 00:00:33,680
finally we save it.

8
00:00:33,680 --> 00:00:40,300
So the only requirement is the idea of the post that we need from the front end.

9
00:00:40,310 --> 00:00:48,560
So for this one, we are not going to render a form because we have the form already been rendered inside

10
00:00:48,560 --> 00:00:56,330
the post details page and lucky for us we also have the ID of the post, which is this one.

11
00:00:56,330 --> 00:01:04,330
So we can go ahead and take this ID and make the HTTP request by passing in the message of the comment.

12
00:01:04,340 --> 00:01:07,250
So let's go ahead and then finish up with that.

13
00:01:07,250 --> 00:01:13,400
So let's get back to the post details inside the views, post and post details.

14
00:01:13,400 --> 00:01:16,460
So let's go down and look for the comments.

15
00:01:16,460 --> 00:01:24,860
And this is a form the action, meaning the path is going to be let's cross check again comments and

16
00:01:24,860 --> 00:01:30,420
is going to be API version one and then the comment and then the ID of the post.

17
00:01:30,440 --> 00:01:35,150
So let's see how we are going to implement that.

18
00:01:35,240 --> 00:01:41,780
So let's get back to the post details and here is the comment form.

19
00:01:41,780 --> 00:01:46,790
The action or the path goes like API version one.

20
00:01:47,210 --> 00:01:48,380
Comments.

21
00:01:49,910 --> 00:01:52,400
And then the ID of the post.

22
00:01:53,350 --> 00:01:59,470
Which is equal to posts, and that's called ID for this one.

23
00:01:59,470 --> 00:02:07,330
We are not going to use method override because our client site form support at HTTP method called post.

24
00:02:07,330 --> 00:02:13,810
So we are lucky here as post it can be uppercase or lowercase.

25
00:02:13,900 --> 00:02:19,600
The name here would be the message that holds the value of our comments.

26
00:02:19,630 --> 00:02:22,120
If we cross check the model.

27
00:02:22,120 --> 00:02:29,950
That is what we are accepting as the value of our comment as message.

28
00:02:30,160 --> 00:02:34,240
So back here now, we are done with it, guys.

29
00:02:34,240 --> 00:02:35,650
We are done with it.

30
00:02:35,800 --> 00:02:42,880
So next step is let's make the HTTP request to test this endpoint to see if it's going to work.

31
00:02:42,880 --> 00:02:49,960
Before we check it out, let's try to console.log what we have created inside the Command create controller

32
00:02:50,320 --> 00:02:55,780
before sending the response, I would like to console.log the post.

33
00:02:56,970 --> 00:02:58,320
I Is that, sir?

34
00:02:58,350 --> 00:02:59,940
Moment of truth.

35
00:03:00,390 --> 00:03:02,130
Let's refresh it.

36
00:03:02,910 --> 00:03:03,990
And.

37
00:03:04,690 --> 00:03:08,200
Let me add my message as excellent.

38
00:03:09,880 --> 00:03:10,810
Submit.

39
00:03:12,280 --> 00:03:16,600
And you can see that my message has been submitted successfully.

40
00:03:16,600 --> 00:03:25,150
And if I check the terminal and you can see that this is a comment I just created and it is inside the

41
00:03:25,150 --> 00:03:33,670
comment array of the post so I can go ahead and then loop through the comments of this particular post

42
00:03:33,670 --> 00:03:35,860
and display it accordingly.

43
00:03:36,040 --> 00:03:39,860
So let's see if we are populating the comments.

44
00:03:39,880 --> 00:03:43,930
So let's get back to the post details and let's have a look.

45
00:03:44,020 --> 00:03:50,170
Let's get back to the post and post details.

46
00:03:53,350 --> 00:03:55,880
Let's grow up for the post details.

47
00:03:55,900 --> 00:03:57,310
Indeed we are.

48
00:03:57,310 --> 00:04:01,210
What display the comments of the post details.

49
00:04:01,360 --> 00:04:05,530
So let's go ahead and then display them accordingly.

50
00:04:05,530 --> 00:04:11,530
So let's get back to the post details and this is where we are looping through the comment.

51
00:04:11,530 --> 00:04:13,180
And this is a container.

52
00:04:13,180 --> 00:04:17,589
If you collapse eight, we can see that this is a container for the comments.

53
00:04:18,070 --> 00:04:22,210
And let's look at the number of comments that we have added so far.

54
00:04:22,210 --> 00:04:28,060
We can see we have a class called comments, meaning this one represents a single comment.

55
00:04:28,060 --> 00:04:33,460
So if I collapse eight the first comment second and that is it.

56
00:04:34,150 --> 00:04:34,630
All right.

57
00:04:34,630 --> 00:04:40,140
So the next video, let's go ahead and display all the comments that we have created.

