1
00:00:00,180 --> 00:00:00,660
Beautiful.

2
00:00:01,110 --> 00:00:09,660
I think we really clean up our dress, but we're not out of the woods yet, if we take a look at our

3
00:00:09,660 --> 00:00:16,470
Arth dress, yeah, this one looks somewhat clean, but we need to keep in mind that we only have one

4
00:00:16,470 --> 00:00:17,050
request.

5
00:00:17,490 --> 00:00:20,590
We only have one post request to our login.

6
00:00:21,110 --> 00:00:29,880
However, if we take a look at our people, just it is still somewhat of a mess because we have a bunch

7
00:00:29,880 --> 00:00:33,360
of functionality since, of course, we have more routes.

8
00:00:33,750 --> 00:00:41,990
And of course, a better setup is if we would be able to split this up into a separate file.

9
00:00:42,220 --> 00:00:44,490
And I'm talking about the functions.

10
00:00:44,850 --> 00:00:49,230
So imagine the scenario where we only would have a router.

11
00:00:49,680 --> 00:00:56,430
Then I'm going to set up my method whether or not get post or whatever, then I'm still going to have

12
00:00:56,430 --> 00:00:56,880
the route.

13
00:00:56,880 --> 00:01:02,340
But the functionality, this one, the controller is going to be in a separate file.

14
00:01:02,650 --> 00:01:09,000
So it's going to be a separate function and you'll see how much cleaner our file is going to look like

15
00:01:09,300 --> 00:01:10,620
just in a second.

16
00:01:10,920 --> 00:01:16,670
So, again, we need to head back to our express tutorial now.

17
00:01:16,670 --> 00:01:17,610
I'll zoom in.

18
00:01:17,940 --> 00:01:19,770
I'll create a new folder.

19
00:01:20,100 --> 00:01:28,860
And again, Common Convention is calling this controllers for the reason that there is a pattern called

20
00:01:28,860 --> 00:01:29,700
MVC.

21
00:01:29,850 --> 00:01:31,470
So model view controller.

22
00:01:31,770 --> 00:01:33,950
And then again, we come up with the name.

23
00:01:33,960 --> 00:01:37,230
In my case, I'm going to go with jobs or I'm sorry, not jobs.

24
00:01:37,470 --> 00:01:38,520
I'm going to go with people.

25
00:01:38,760 --> 00:01:44,310
And I'm not going to set up one for the other one for us since there's only one.

26
00:01:44,310 --> 00:01:50,260
But for people, I will set up a controllers file by the name of people jobs.

27
00:01:50,580 --> 00:01:57,090
And here I just want to set up first my functions and the way it's going to work.

28
00:01:57,360 --> 00:02:00,690
We're going to go with CONSED and then again, you just need to come up with a name.

29
00:02:00,930 --> 00:02:04,020
So for example, forget request where I'm getting people.

30
00:02:04,290 --> 00:02:05,940
I'm just going to call this get people.

31
00:02:06,240 --> 00:02:08,250
Keep in mind this is just a function.

32
00:02:08,400 --> 00:02:10,650
So the name is really up to you.

33
00:02:10,860 --> 00:02:15,450
And since I'm going to have the same functionality, of course, I need to keep in mind that I do need

34
00:02:15,450 --> 00:02:17,460
to have access to work.

35
00:02:17,460 --> 00:02:23,400
And right now it's really cool that once I pass this function as a reference, it's still going to work.

36
00:02:23,670 --> 00:02:26,970
So I simply go here with this request and setup.

37
00:02:26,970 --> 00:02:34,730
The functionality not probably faster is just going to be doing like this where I cut out my back and

38
00:02:34,740 --> 00:02:36,760
the controllers I copy and paste.

39
00:02:37,080 --> 00:02:42,000
Now I know that some people might find this annoying, but yes, I'm purposely refactoring the code

40
00:02:42,210 --> 00:02:44,760
so you can see the benefits right away.

41
00:02:45,090 --> 00:02:49,860
And I'm going to do that for all the functions and for a little bit.

42
00:02:49,860 --> 00:02:51,270
It's going to probably look messy.

43
00:02:52,330 --> 00:02:58,200
Where I'm going to do the same thing for the post, so I guess first I'm just going to cut it out and

44
00:02:58,200 --> 00:03:01,450
then back in the controllers, not around in the controllers.

45
00:03:01,720 --> 00:03:03,900
Let's come up with that function as well.

46
00:03:03,910 --> 00:03:04,060
So.

47
00:03:04,870 --> 00:03:07,840
And in this case, I'm going to call this create person.

48
00:03:08,230 --> 00:03:10,120
I'll copy and paste the code.

49
00:03:10,650 --> 00:03:11,610
OK, awesome.

50
00:03:11,950 --> 00:03:13,130
Back in or out.

51
00:03:13,470 --> 00:03:14,920
Let's get the postman one.

52
00:03:15,340 --> 00:03:24,850
So the controller let's also call this contest and create person and postman Weichsel copy and paste.

53
00:03:25,120 --> 00:03:26,590
That's my function.

54
00:03:26,860 --> 00:03:29,410
And back in roots, I have one for pot.

55
00:03:29,860 --> 00:03:38,230
So I think it would make sense if I call this, for example, of that person again, cut out everything,

56
00:03:38,470 --> 00:03:44,600
starting with a function and line all the way to the closing parentheses.

57
00:03:45,040 --> 00:03:47,770
Cut it out back in controllers.

58
00:03:48,130 --> 00:03:54,490
We're going to call it const update person like so copy and paste.

59
00:03:54,640 --> 00:03:59,670
And lastly, let's deal with a delete one as well.

60
00:04:00,100 --> 00:04:02,560
So let's keep scrolling again.

61
00:04:02,560 --> 00:04:10,090
We cut everything out like so and then back and the controller, let's create one for deleting the person.

62
00:04:10,090 --> 00:04:16,240
So const cons delete person and copy and paste.

63
00:04:16,600 --> 00:04:24,220
And if you remember, which seems like an eternity ago when we covered the exports, I said that of

64
00:04:24,220 --> 00:04:29,750
course we can also use right away module exports and then whatever.

65
00:04:30,130 --> 00:04:36,380
So for example, in this case that could be get people or create person or create person postman.

66
00:04:36,670 --> 00:04:43,750
Now in my case, I always prefer to do my exports all the random bottom where I say module export.

67
00:04:43,780 --> 00:04:48,080
Now this is going to be the object and now I just want to access all the functions.

68
00:04:48,100 --> 00:04:50,710
Keep in mind, it doesn't change the functionality.

69
00:04:50,710 --> 00:04:55,780
Functionality is the same where I'm basically exporting an object with a bunch of functions.

70
00:04:55,930 --> 00:04:57,790
So here I just need to reference their names.

71
00:04:58,030 --> 00:05:05,550
So it's get people, it is create person, create person, post man, then update person.

72
00:05:05,770 --> 00:05:09,280
And lastly, it is also for deleting the person.

73
00:05:09,490 --> 00:05:12,730
Not one thing that is missing, of course, is the people.

74
00:05:12,730 --> 00:05:14,500
Like I said, this is just going to be temporary.

75
00:05:14,920 --> 00:05:19,690
So I'm going to go to the controller here and I'll copy and paste.

76
00:05:20,110 --> 00:05:27,340
In this case, the path is correct because the route was already in a separate folder, so that should

77
00:05:27,340 --> 00:05:28,060
still work.

78
00:05:28,360 --> 00:05:35,020
And of course now I can save my controller and in the route, what I need to do is, of course, import

79
00:05:35,020 --> 00:05:35,490
all of them.

80
00:05:35,860 --> 00:05:41,920
So in this case, we go with CONSED and again on right away the structure, all of them.

81
00:05:42,250 --> 00:05:44,200
So let me just copy and paste.

82
00:05:44,200 --> 00:05:49,570
I think it's going to be faster like so since the names of course, are going to be exactly the same

83
00:05:49,820 --> 00:05:54,250
idea, structure them and the structure of them from require.

84
00:05:54,490 --> 00:06:00,580
And then of course we're looking for controllers and then more specifically, I'm looking for the people

85
00:06:00,700 --> 00:06:06,250
like so and once we have required them, of course, now we pass in the function reference.

86
00:06:06,460 --> 00:06:09,250
So for example, here I can say get people.

87
00:06:09,490 --> 00:06:15,960
Now I do need to add a comma and if everything is correct, our functionality is still going to work.

88
00:06:16,510 --> 00:06:23,590
So in the controllers, we're still accessing and and we're still sending back the response.

89
00:06:23,860 --> 00:06:26,710
But of course, the benefit of all of this work.

90
00:06:27,580 --> 00:06:33,170
Is the fact that our world is going to get much cleaner soon here?

91
00:06:33,280 --> 00:06:42,730
Remember, the name was created person like so, and then we have one for create person man and set

92
00:06:42,730 --> 00:06:46,360
it up like so then we have also one for update person.

93
00:06:47,160 --> 00:06:50,190
And lastly, we have one for the leading person, right?

94
00:06:50,520 --> 00:06:57,150
So we go here with the lead person, I say again, I'm not going to test all of them out, but I'm going

95
00:06:57,150 --> 00:07:02,640
to go with, for example, delete and I'm going to look for for this still works.

96
00:07:03,030 --> 00:07:04,950
I remove the person number four.

97
00:07:05,310 --> 00:07:12,290
And also if I check out the get one for the people, this also should get me back there.

98
00:07:12,390 --> 00:07:17,850
So I know that my functionality still works, but I nicely cleaned out my file.

99
00:07:18,280 --> 00:07:25,050
Now, lastly, before we talk about the databases, I just want to mention that when it comes to setting

100
00:07:25,050 --> 00:07:28,710
up the route, we actually have two flavors.

101
00:07:29,070 --> 00:07:35,190
So I'm going to comment these ones out and I'll show you another way how we can set up the routes.

102
00:07:35,190 --> 00:07:40,600
And effectively, the benefit is that we can set it up in fewer lines of code.

103
00:07:41,100 --> 00:07:44,220
Keep in mind, the functionality is going to be exactly the same.

104
00:07:44,460 --> 00:07:50,040
So, again, this is going to be the case where it comes down to your preference if you prefer setting

105
00:07:50,040 --> 00:07:50,650
up your odds.

106
00:07:50,670 --> 00:07:52,590
This way you can definitely do so.

107
00:07:52,610 --> 00:07:57,520
There's no rule against it if you prefer the method that I'm about to show you.

108
00:07:57,870 --> 00:08:00,840
And of course, you can use that one instead.

109
00:08:01,200 --> 00:08:05,580
So we go with a router and then we go with a route.

110
00:08:05,790 --> 00:08:08,730
And then in the route I set up the path.

111
00:08:09,180 --> 00:08:16,380
And again, since there's get and post that match, exactly what I have in base, same situation.

112
00:08:16,500 --> 00:08:23,820
I just set up the fort and instead of setting up them separately, for example, get and post, I can

113
00:08:23,820 --> 00:08:24,510
just change them.

114
00:08:24,750 --> 00:08:26,780
So change one after another.

115
00:08:27,090 --> 00:08:28,260
So I go with get.

116
00:08:28,530 --> 00:08:36,030
That is of course my method that is not changing and then I need to pass in my controller function.

117
00:08:36,299 --> 00:08:40,470
OK, as you can see, almost the same in this case.

118
00:08:40,470 --> 00:08:42,190
However, I can change it.

119
00:08:42,360 --> 00:08:46,410
Now the method names did not change, the path did not change.

120
00:08:46,620 --> 00:08:51,660
There's still actually referencing the base path in here, what we have in jazz.

121
00:08:51,960 --> 00:08:55,980
But since we can change it, we can simply write it in one line of code.

122
00:08:56,170 --> 00:09:04,080
So of course the callback function is going to be create and I believe it was person, so create and

123
00:09:04,140 --> 00:09:04,670
person.

124
00:09:04,840 --> 00:09:08,440
So then we have, of course, one for the postman.

125
00:09:08,550 --> 00:09:10,740
So in this case, of course, it's not going to change.

126
00:09:11,040 --> 00:09:18,780
It's pretty much going to be the same logic where we go the route, our route like so and then we go

127
00:09:18,780 --> 00:09:20,460
towards Postman.

128
00:09:20,670 --> 00:09:24,530
And then of course I want to change Dot and I believe it was post.

129
00:09:24,580 --> 00:09:24,870
Right.

130
00:09:25,080 --> 00:09:32,970
And then we go with Create Person Postman and then we can again set up one line of code for the post

131
00:09:33,180 --> 00:09:34,100
and delete.

132
00:09:34,380 --> 00:09:40,620
So in this case, I think I'm going to just copy what I have Rhorer that route, then we set up our

133
00:09:40,620 --> 00:09:48,050
out and in this case it is going to be forward slash and then ID and then we have to we have one for

134
00:09:48,060 --> 00:09:50,970
put and we have one for delete.

135
00:09:51,330 --> 00:09:59,280
So we go with delete and then as far as the callback functions, we go with update person and also we

136
00:09:59,280 --> 00:10:00,900
have the lead person.

137
00:10:01,080 --> 00:10:08,280
And finally, let me just stress it one more time where whichever setup you choose is really up to your

138
00:10:08,280 --> 00:10:11,040
preference, the functionality is exactly the same.

139
00:10:11,310 --> 00:10:18,270
We go with a router route and then we can just change our methods and the callback functions.

140
00:10:18,900 --> 00:10:23,070
Now, in this case, we set up each route separately.

141
00:10:23,130 --> 00:10:28,530
So, for example, if you have multiple URLs that much, yeah, you're in good shape.

142
00:10:28,530 --> 00:10:34,950
You can just set up a out pass and the URL and then change all the methods.

143
00:10:35,160 --> 00:10:37,950
And lastly, just quickly test it one more time.

144
00:10:37,950 --> 00:10:44,220
Since I made some changes, I sent it there is I successfully get back my people.

145
00:10:44,580 --> 00:10:51,930
So with this in place, with our router in place, with the fact that we have covered all the methods,

146
00:10:52,290 --> 00:10:55,080
the guest post put the lead.

147
00:10:55,350 --> 00:11:00,510
I think we're already for the next level where we connect our server to the database.

