1
00:00:01,050 --> 00:00:08,940
With our product model in place now, we can set up some simple responses in the controller, then add

2
00:00:08,940 --> 00:00:14,700
them to the product route and eventually set up everything in abcess.

3
00:00:14,820 --> 00:00:19,140
So not just start with controllers or have two controllers like already previously mentioned.

4
00:00:19,410 --> 00:00:26,330
We have a product controller and in here we first want to import of the product because we'll create

5
00:00:26,340 --> 00:00:27,810
product in one of the routes.

6
00:00:27,840 --> 00:00:36,030
So let's go here with CONSED product is equal to require and in this case we're looking to levels up

7
00:00:36,540 --> 00:00:39,600
and in the models we have the product one.

8
00:00:39,990 --> 00:00:41,940
And I also want to use the status codes.

9
00:00:42,330 --> 00:00:47,720
So I just go here with statis codes and that is going to be equal to require.

10
00:00:48,510 --> 00:00:53,640
And we're looking for our library of the HTP status codes.

11
00:00:53,910 --> 00:01:00,180
So let's go with require an old price here, HTP status codes.

12
00:01:00,390 --> 00:01:07,050
So those are two imports then as far as the controllers will have one for creating the product and second

13
00:01:07,050 --> 00:01:08,810
one for getting all the product.

14
00:01:09,690 --> 00:01:17,640
If you remember the front end, there is a form which will use the product and then below it there was

15
00:01:17,640 --> 00:01:18,860
a list of all the products.

16
00:01:18,870 --> 00:01:20,670
That's why we have both of these rules.

17
00:01:20,970 --> 00:01:25,260
So create product is going to be a sync function.

18
00:01:25,470 --> 00:01:28,950
We have Reckoner as nothing has changed there.

19
00:01:29,280 --> 00:01:31,890
And what we're looking for is simple response.

20
00:01:32,170 --> 00:01:39,240
So for the time being, let's just go with Meri's dots and say create Parata.

21
00:01:40,090 --> 00:01:46,450
All right, now we want to do the same thing we have, getting all the products, copy and paste, what's

22
00:01:46,450 --> 00:01:46,780
the name?

23
00:01:46,780 --> 00:01:56,380
This one get all products reckoner as far as the response and say a list of products, a list of products

24
00:01:56,680 --> 00:01:58,300
online all the way to the bottom.

25
00:01:58,310 --> 00:02:00,880
Let's just go with module exports.

26
00:02:00,880 --> 00:02:04,000
We have the object and we want to export both.

27
00:02:04,190 --> 00:02:12,820
We want to export great product as well as get all product when we want to move on to upload controller.

28
00:02:13,180 --> 00:02:18,100
And basically the gist is exactly the same where we'll have we want to root.

29
00:02:19,200 --> 00:02:26,550
And then in there will upload the product, so we're going to go here to or I'm sorry, upload the image,

30
00:02:26,880 --> 00:02:27,640
I misspoke.

31
00:02:27,990 --> 00:02:29,910
So let me take everything here.

32
00:02:30,270 --> 00:02:34,560
So take everything, starting with status codes, copy and paste.

33
00:02:34,890 --> 00:02:37,200
And you're just looking for upload.

34
00:02:38,130 --> 00:02:40,140
Product image.

35
00:02:40,460 --> 00:02:42,240
And that's exactly what will send back.

36
00:02:42,270 --> 00:02:52,510
So upload product image and will remove the second one and let's just export upload product image.

37
00:02:52,920 --> 00:03:00,810
With this in place now, we can navigate the product routes and we want to set up the roads.

38
00:03:01,350 --> 00:03:05,840
And here, remember, we needed to go with a router first.

39
00:03:05,850 --> 00:03:11,430
So express is equal to require and we're looking for Express.

40
00:03:11,880 --> 00:03:13,560
Then we want to set up the router.

41
00:03:13,570 --> 00:03:21,960
So CONSED router is equal to express and dot router we invoke awesome.

42
00:03:22,350 --> 00:03:26,990
And then let's import both the create product and get all product.

43
00:03:27,360 --> 00:03:32,110
So that's going to be from the product controller as well as upload controller.

44
00:03:32,430 --> 00:03:33,660
So let's go here.

45
00:03:33,870 --> 00:03:43,020
Const create product karma, get our product to both of these are coming from where it's coming from

46
00:03:43,020 --> 00:03:44,110
the controllers.

47
00:03:44,130 --> 00:03:44,580
Correct.

48
00:03:44,820 --> 00:03:52,350
So we go to levels up and in the controllers we're looking for product one copy and paste and the name

49
00:03:52,350 --> 00:03:55,050
here is upload product I believe.

50
00:03:55,050 --> 00:03:58,020
Now upload product image my brand.

51
00:03:58,470 --> 00:04:01,440
So we're going to go here with upload.

52
00:04:02,630 --> 00:04:10,190
Product image, and in this case, it is coming not from the product controller, we're actually looking

53
00:04:10,490 --> 00:04:14,110
in the uploads controller, so we have both imports.

54
00:04:14,480 --> 00:04:21,350
And up next, we want to set up the routes and essentially in the objets again, we'll have that API

55
00:04:21,350 --> 00:04:23,810
version one and then forward slash products.

56
00:04:24,290 --> 00:04:31,400
And therefore, for the route for that route will set up both the create product and get all products

57
00:04:31,700 --> 00:04:33,160
in line for uploads.

58
00:04:33,470 --> 00:04:35,210
We'll set up a separate world.

59
00:04:35,450 --> 00:04:39,550
So let's just go here with router then route again.

60
00:04:39,770 --> 00:04:43,100
There's going to be a API version, one product up front.

61
00:04:43,130 --> 00:04:48,560
Therefore, we'll just go with Forward Slash now for post one for the post method.

62
00:04:48,860 --> 00:04:59,110
We'll go here with a create product like So to create product and then 40 getrude to say we get all

63
00:04:59,120 --> 00:04:59,720
products.

64
00:04:59,990 --> 00:05:02,160
So that's going to be for a product.

65
00:05:02,450 --> 00:05:06,340
Now as far as the image, we want to go with a router that route online.

66
00:05:06,350 --> 00:05:14,960
Let's go forward, slash uploads and line here, post throughout and we'll go with upload product image

67
00:05:15,320 --> 00:05:17,630
and eventually we just want to export.

68
00:05:17,930 --> 00:05:27,440
So we'll go here with module exports, exports and that is equal to our our not once the product route

69
00:05:27,830 --> 00:05:34,130
is in place, then we want to navigate back to jazz and here we want to do a few things.

70
00:05:34,430 --> 00:05:37,190
First, we want to import the product router.

71
00:05:37,940 --> 00:05:42,820
So I'm going to go below the database, but above the handlers.

72
00:05:43,160 --> 00:05:48,110
I won't say routers, I just call this product router.

73
00:05:48,350 --> 00:05:51,260
So I'm going to load product router.

74
00:05:51,680 --> 00:05:59,360
Then we'll import that and say Here Consed and we're looking for product router is equal to your require

75
00:05:59,780 --> 00:06:03,190
and we're looking for the roots in this case.

76
00:06:03,650 --> 00:06:10,730
So in the same folder, meaning in the same directory, we're looking for roots and we're looking for

77
00:06:10,730 --> 00:06:11,900
product roots.

78
00:06:12,410 --> 00:06:19,310
And right after the last one, right after I get my actually going to invoke it and we're going to use

79
00:06:19,520 --> 00:06:20,060
that years.

80
00:06:20,330 --> 00:06:25,680
So go here with Abduh, use an API forward slash version one.

81
00:06:25,680 --> 00:06:30,710
And like I said, my growth path for this water is going to be product.

82
00:06:31,250 --> 00:06:35,690
And I know this is a little bit of repetition, but I just want to make sure that we're all on the same

83
00:06:35,690 --> 00:06:36,020
page.

84
00:06:36,290 --> 00:06:40,880
So this is going to be my root root API version one product.

85
00:06:40,880 --> 00:06:44,720
And we're using this because we already have everything in the postman.

86
00:06:45,140 --> 00:06:51,710
And when it comes to Roots Post and that is going to be for road and then for uploads will actually

87
00:06:51,710 --> 00:06:58,550
have to go with API version one product and then uploads and you'll see eventually why we have this

88
00:06:58,550 --> 00:06:58,880
setup.

89
00:06:59,120 --> 00:07:03,560
And for this one will use our product router.

90
00:07:03,950 --> 00:07:11,600
And also since I'm going to be adding that info, the product info using JSON, we want to go above

91
00:07:11,870 --> 00:07:14,510
douget and let's set up that express that.

92
00:07:14,540 --> 00:07:21,350
Jason, remember, that is something that we needed to use the built in middleware from Express just

93
00:07:21,350 --> 00:07:26,690
so we have access to all the data in Iraq, that body, we invoke that.

94
00:07:27,170 --> 00:07:35,600
And with this in place now, I can swing to a postman and set up the basic structure for our request

95
00:07:35,600 --> 00:07:36,190
as well.

96
00:07:36,590 --> 00:07:44,540
Now, before we do that, I notice that I have a tiny bug where in the roots I went with a router actually

97
00:07:44,540 --> 00:07:48,200
should be a router without checking out different.

98
00:07:48,200 --> 00:07:57,170
Our router router is not a function and the reason for that is because we need to go with a router dot

99
00:07:57,170 --> 00:07:57,770
around.

100
00:07:58,190 --> 00:07:58,910
My apologies.

101
00:07:58,910 --> 00:08:05,520
For some reason I messed up the first set up, so now I can see clearly server is listening on point

102
00:08:05,540 --> 00:08:11,240
three thousand and everything is in good shape and now can finally go to a post man.

