1
00:00:00,660 --> 00:00:01,950
In this video.

2
00:00:01,950 --> 00:00:09,810
Let's go ahead and finish up the MVC design pattern to have clean folder structure.

3
00:00:10,050 --> 00:00:17,820
So looking at the route here at this point, I think everything is okay because we have what is called

4
00:00:17,820 --> 00:00:19,380
separation of concern.

5
00:00:19,440 --> 00:00:27,210
But to be able to finish up with the MVC design part in the purpose for the routing is to take a function

6
00:00:27,210 --> 00:00:29,550
and then just render that.

7
00:00:29,550 --> 00:00:34,320
So we need to catch the logic inside this route.

8
00:00:34,320 --> 00:00:38,430
So for this route, where is our business logic?

9
00:00:38,430 --> 00:00:41,010
This is the entire route.

10
00:00:41,040 --> 00:00:46,320
The business logic lies inside the callback, which is this one.

11
00:00:48,930 --> 00:00:54,160
So we need to catch this one and put it on a separate file called controller.

12
00:00:54,180 --> 00:01:00,540
The responsibility of a controller is where we implement the business logic.

13
00:01:00,570 --> 00:01:07,390
So let's go ahead and then refactor the code inside the root so inside the controllers.

14
00:01:07,440 --> 00:01:17,190
And let's start with the users and let me create one file and our code is one as users dot JS And let's

15
00:01:17,190 --> 00:01:18,570
come back to the root.

16
00:01:18,570 --> 00:01:26,100
So let me get back to the users root here and this is a callback function, so I'm going to cut the

17
00:01:26,100 --> 00:01:33,510
callback function inside here as that and come back to the controller and I'll paste it as that.

18
00:01:33,930 --> 00:01:40,770
This is a valid function and this is what we call anonymous function, meaning a function without a

19
00:01:40,770 --> 00:01:41,280
name.

20
00:01:41,580 --> 00:01:50,010
So what we need to do is to assign a variable to this, or we can make use of normal function creation.

21
00:01:50,010 --> 00:01:52,110
But I would like to use a function.

22
00:01:52,110 --> 00:02:00,090
So this one going to be as a registered user controller or registered controller equal to that, and

23
00:02:00,090 --> 00:02:01,100
that is it.

24
00:02:01,110 --> 00:02:06,120
The next step is that I need to require that one inside the root.

25
00:02:06,120 --> 00:02:16,110
So I need to export down here as module dot exports is equal to remember this file is going to contain

26
00:02:16,110 --> 00:02:22,680
all the logic about the users, meaning we are going to export multiple functions from this file.

27
00:02:22,680 --> 00:02:28,050
So we need to export them as an object as register controller.

28
00:02:28,230 --> 00:02:38,310
So in here I need to require the registered user controller and our pass to this one as a second element

29
00:02:38,310 --> 00:02:39,510
and that is it.

30
00:02:39,510 --> 00:02:46,050
So when I go ahead and then make a request to register, you can see that it worked fine.

31
00:02:46,050 --> 00:02:48,840
So let's finish up the refactoring.

32
00:02:48,840 --> 00:02:56,400
So back here I'm going to cut all the callback function and inside here I'm going to paste it here.

33
00:02:56,550 --> 00:02:59,190
So it's not going to be as log in.

34
00:03:00,360 --> 00:03:02,790
And this one is registered.

35
00:03:06,640 --> 00:03:10,480
It's supposed to be here before the export.

36
00:03:10,570 --> 00:03:20,500
So I need to assign to a variable called log in const log in controller is equal to that.

37
00:03:22,210 --> 00:03:28,480
All right, so let me collapse the finished one and let me export us log in controller.

38
00:03:28,480 --> 00:03:32,530
And here, let's require it as log in.

39
00:03:32,530 --> 00:03:39,640
Sorry as log in and here as log in.

40
00:03:39,940 --> 00:03:45,640
The next one is for the getting details about the user.

41
00:03:45,670 --> 00:03:53,470
So here I'm going to be as details so PC eight.

42
00:03:54,670 --> 00:03:59,530
And I signed to a variable called user details.

43
00:04:02,300 --> 00:04:06,830
Controller is equal to that.

44
00:04:06,830 --> 00:04:13,130
So let's export it as that and here require it as that.

45
00:04:13,490 --> 00:04:19,010
And for details, I'll start next one going to be the profile.

46
00:04:19,010 --> 00:04:25,490
So let me select and cut and here, let me collapse this one also.

47
00:04:26,060 --> 00:04:35,990
And this one is going to be the profile piece, its end cost profile controller.

48
00:04:37,010 --> 00:04:41,390
Is equal to that exports.

49
00:04:43,460 --> 00:04:44,510
Required.

50
00:04:46,200 --> 00:04:47,520
And use it.

51
00:04:49,630 --> 00:04:50,920
Next is.

52
00:04:51,940 --> 00:04:53,650
Upload profile photo.

53
00:04:54,010 --> 00:04:56,740
So select and cut.

54
00:04:59,370 --> 00:05:04,620
Going to be upload profile photo.

55
00:05:05,430 --> 00:05:06,330
Pace eight.

56
00:05:07,390 --> 00:05:13,090
In concert upload profile.

57
00:05:15,020 --> 00:05:16,520
Photo controller.

58
00:05:17,000 --> 00:05:17,500
Wow.

59
00:05:17,510 --> 00:05:19,190
It's too long, but it's okay.

60
00:05:22,180 --> 00:05:23,800
So down here.

61
00:05:26,330 --> 00:05:30,230
Less exports and less required.

62
00:05:31,610 --> 00:05:33,800
And here, let's use it.

63
00:05:34,930 --> 00:05:50,170
The next age upload cover, photo it from here and let me collapse here as upload cover image and then

64
00:05:50,170 --> 00:05:51,100
cost.

65
00:05:53,620 --> 00:05:57,700
Upload cover image.

66
00:05:57,850 --> 00:06:01,000
Controller is equal to the function code.

67
00:06:02,410 --> 00:06:04,120
And exports.

68
00:06:04,810 --> 00:06:06,130
And here.

69
00:06:06,160 --> 00:06:07,480
Let's use it.

70
00:06:08,080 --> 00:06:12,160
The next one is I need to use it here.

71
00:06:12,160 --> 00:06:16,170
And the next one is update password.

72
00:06:16,180 --> 00:06:25,990
So here is going to be update password and const.

73
00:06:29,540 --> 00:06:31,760
Our date password.

74
00:06:34,100 --> 00:06:36,470
Controller is equal to that.

75
00:06:42,400 --> 00:06:47,740
And let's use it here as update.

76
00:06:47,770 --> 00:06:51,850
Next one is going to be the update the user.

77
00:06:52,120 --> 00:07:03,460
So let's come back here and want to be an update user and I'm going to be const update user is equal

78
00:07:03,460 --> 00:07:05,780
to the function.

79
00:07:05,940 --> 00:07:07,690
Going to be controller.

80
00:07:10,050 --> 00:07:15,660
So let's export it here and let's use it here.

81
00:07:17,270 --> 00:07:19,750
And let's use it also here.

82
00:07:19,760 --> 00:07:23,990
The last one is going to be look out.

83
00:07:27,580 --> 00:07:28,660
Cost.

84
00:07:30,010 --> 00:07:31,180
Look out.

85
00:07:32,260 --> 00:07:34,960
Controller is equal to that.

86
00:07:36,720 --> 00:07:37,700
Let me collapse.

87
00:07:37,710 --> 00:07:38,250
It's.

88
00:07:40,100 --> 00:07:41,330
Look out.

89
00:07:44,810 --> 00:07:49,880
And here I look out and let's use it here.

90
00:07:50,780 --> 00:07:55,850
All right, So let's try it out and make the request to make sure that it works fine.

91
00:08:05,720 --> 00:08:06,140
All right.

92
00:08:06,140 --> 00:08:09,050
So let's work with the post controller also.

93
00:08:09,050 --> 00:08:11,270
So let me collapse this one.

94
00:08:11,840 --> 00:08:17,960
And inside the post I'm going to create one file and call it as post.

95
00:08:20,890 --> 00:08:21,790
Jeez.

96
00:08:22,000 --> 00:08:23,830
Let's get back to the post route.

97
00:08:23,830 --> 00:08:24,820
Which is this?

98
00:08:25,860 --> 00:08:27,480
And as we did.

99
00:08:28,610 --> 00:08:39,470
Cut it from here and post const create post controller is equal to the function call.

100
00:08:40,780 --> 00:08:43,390
So here are going to be as great.

101
00:08:45,290 --> 00:08:57,010
And down here exports module dot exports is equal to create post controller collapse AIDS.

102
00:08:57,350 --> 00:08:59,600
And next step is.

103
00:09:00,430 --> 00:09:01,990
Fetching all posts.

104
00:09:02,530 --> 00:09:07,120
So here is going to be all and cost.

105
00:09:08,380 --> 00:09:09,460
Fetch post.

106
00:09:11,740 --> 00:09:13,330
Post prowler.

107
00:09:15,530 --> 00:09:22,190
Is equal to the function call and let's export us an object to here.

108
00:09:22,190 --> 00:09:24,590
Can it be as fetch post?

109
00:09:26,060 --> 00:09:29,420
And for single.

110
00:09:31,890 --> 00:09:33,180
Cut it from here.

111
00:09:35,280 --> 00:09:42,120
And details the contest fetch posts.

112
00:09:42,420 --> 00:09:48,600
Single post controller is equal to that.

113
00:09:48,780 --> 00:09:52,170
Let me add controller for the function on.

114
00:10:06,820 --> 00:10:07,630
All right.

115
00:10:07,630 --> 00:10:10,450
The next A's delete.

116
00:10:13,400 --> 00:10:15,920
Delete content.

117
00:10:16,130 --> 00:10:17,750
Delete posts.

118
00:10:20,230 --> 00:10:21,280
Controller

119
00:10:23,860 --> 00:10:25,990
is equal to that.

120
00:10:29,890 --> 00:10:34,030
And lastly is about the update.

121
00:10:43,870 --> 00:10:46,540
And let's export it here.

122
00:10:48,260 --> 00:10:49,730
As update.

123
00:10:49,730 --> 00:10:54,410
So let's require out the controllers create.

124
00:10:56,420 --> 00:10:59,720
So here are going to be as great.

125
00:11:04,820 --> 00:11:05,540
Delete.

126
00:11:07,280 --> 00:11:07,910
Fetch.

127
00:11:09,710 --> 00:11:13,130
Single update.

128
00:11:13,370 --> 00:11:16,640
So this one is for fetch.

129
00:11:17,120 --> 00:11:21,440
Post and fetch single post.

130
00:11:22,830 --> 00:11:29,040
And delete posts and update posts.

131
00:11:29,160 --> 00:11:33,030
So let's test it out and see if it works.

132
00:11:33,030 --> 00:11:40,470
So great is fine or also fine details is also fine.

133
00:11:40,690 --> 00:11:42,860
Have to rename this one to details.

134
00:11:42,870 --> 00:11:48,390
Well, spelling mistake and delete is fine.

135
00:11:48,420 --> 00:11:50,950
Updates is also fine.

136
00:11:50,970 --> 00:11:54,240
The last step is for the comment.

137
00:11:54,240 --> 00:11:57,840
So let me collapse all and insert here.

138
00:11:57,930 --> 00:12:05,730
I'm going to create a file called Comments dot touches and inside the root of comment.

139
00:12:05,760 --> 00:12:07,500
Let's start with that.

140
00:12:07,500 --> 00:12:10,170
So let me cut this one from here.

141
00:12:11,980 --> 00:12:16,110
And inside here is going to be a great comment.

142
00:12:16,120 --> 00:12:19,300
Second, great

143
00:12:21,550 --> 00:12:22,420
comment.

144
00:12:23,200 --> 00:12:25,630
Controller is equal to that.

145
00:12:26,590 --> 00:12:27,640
And then.

146
00:12:30,210 --> 00:12:32,460
Fine single comment.

147
00:12:38,940 --> 00:12:46,590
Cost comment details controller is equal to that.

148
00:12:48,810 --> 00:12:51,840
And next is the lead.

149
00:12:56,040 --> 00:12:58,860
Konst deletes comments.

150
00:13:01,230 --> 00:13:02,310
Controller.

151
00:13:06,760 --> 00:13:08,680
Is equal to that.

152
00:13:09,540 --> 00:13:13,220
And lastly is for update.

153
00:13:21,130 --> 00:13:22,210
Costs.

154
00:13:23,680 --> 00:13:24,670
Update.

155
00:13:27,880 --> 00:13:28,390
Comments.

156
00:13:28,830 --> 00:13:31,260
Controller is equal to that.

157
00:13:32,150 --> 00:13:36,680
So let's export the module.

158
00:13:37,400 --> 00:13:39,350
You're going to be as great.

159
00:13:41,520 --> 00:13:42,870
Comment details.

160
00:13:45,270 --> 00:13:46,050
Delete.

161
00:13:50,190 --> 00:13:51,060
Update.

162
00:13:51,940 --> 00:13:54,370
And that is it for now.

163
00:13:54,370 --> 00:13:58,900
So let's come here and then require great comment.

164
00:14:04,300 --> 00:14:08,770
Comment, details, delete and update.

165
00:14:08,980 --> 00:14:22,900
So here is going to be great comment and this is comment details and this is the lead comment and this

166
00:14:22,900 --> 00:14:25,540
one is update comment.

167
00:14:25,540 --> 00:14:30,060
So now we have complete MVC design pattern.

168
00:14:30,070 --> 00:14:37,030
What has left is to fill up the actual logic for our application.

169
00:14:37,030 --> 00:14:40,540
Then this video, let's start with user registration.

