1
00:00:00,390 --> 00:00:06,870
And once we have successfully connected to the database, next, I want to set up two outs for the product

2
00:00:07,410 --> 00:00:09,240
and you'll see why we have two outs.

3
00:00:09,430 --> 00:00:15,480
Essentially the idea is that one of them, the first one is just going to be for manual testing.

4
00:00:16,079 --> 00:00:21,600
And then since I want to keep on practicing on setting up the router will do just that.

5
00:00:22,020 --> 00:00:25,520
And up here, I can notice that I actually have a spelling bug.

6
00:00:26,590 --> 00:00:33,160
Or this should be about and then right after the Homeworld, I'll set up my router and I'll do that

7
00:00:33,160 --> 00:00:38,920
using that use and then I just need to come up with that bass path or route path for the router.

8
00:00:39,130 --> 00:00:45,400
And in my case, like I already mentioned, I'm going to go with API version one and this is going to

9
00:00:45,400 --> 00:00:47,170
be looking for a product.

10
00:00:47,370 --> 00:00:52,780
And like I mentioned, when we were setting up this route, I simply add this API in version one, because

11
00:00:53,110 --> 00:00:59,680
that way it's easier in Posman since we already have that global variable and effectively in here we

12
00:00:59,680 --> 00:01:01,090
want to pass in the router.

13
00:01:01,480 --> 00:01:06,710
But in order for the router to work, of course, we'll have to set up the controllers as well.

14
00:01:07,100 --> 00:01:08,980
Therefore, we'll start in the controllers.

15
00:01:09,010 --> 00:01:16,720
The file is already created for you and the name is product and for the time being simply set up to

16
00:01:16,780 --> 00:01:22,860
functions and we'll just send some dummy data back and to functions are going to be following.

17
00:01:22,870 --> 00:01:28,940
We're going to go with const get all products and the first one I call static.

18
00:01:29,260 --> 00:01:36,980
Now this is going to be async since of course we will use the methods that we have on the Mongo's and

19
00:01:36,980 --> 00:01:37,330
in here.

20
00:01:37,330 --> 00:01:43,660
Let's look for Iraq and of course and line as far as the function body for the time being, simply want

21
00:01:43,660 --> 00:01:49,230
to go with that status and I'll set it equal to two hundred and nine.

22
00:01:49,240 --> 00:01:54,220
As far as the response, I'm going to go JSON online salvagers and I'll pass in the object.

23
00:01:54,370 --> 00:02:01,710
And here there's going to be a message property and we'll just write product testing right now.

24
00:02:01,780 --> 00:02:08,310
Let me copy and paste this and then we just want to remove that static part and we also want to remove

25
00:02:08,320 --> 00:02:09,080
the testing one.

26
00:02:09,430 --> 00:02:13,360
So this is going to be actual root and then of course, we can export this.

27
00:02:13,360 --> 00:02:15,760
So let's go with module exports.

28
00:02:15,970 --> 00:02:17,560
And this is going to be my object.

29
00:02:17,770 --> 00:02:20,680
And here I simply want to pass in both functions.

30
00:02:20,950 --> 00:02:24,850
So get all products and get all product static.

31
00:02:25,150 --> 00:02:26,290
So we set this up.

32
00:02:26,510 --> 00:02:31,150
Then of course we need to navigate to our root zone here.

33
00:02:31,160 --> 00:02:38,620
This is where I'll set up a router and then we'll start by getting the express const press is equal

34
00:02:38,620 --> 00:02:42,700
to will require and then we want to pass in express of course again.

35
00:02:43,090 --> 00:02:45,450
And then once we have that, let's set up the router.

36
00:02:45,460 --> 00:02:52,690
And if you remember the syntax following where we go a router and then we go with express dot and then

37
00:02:52,690 --> 00:02:56,440
with a capital case, we go with the router and then of course we invoke it.

38
00:02:56,890 --> 00:03:02,870
Then I want to import both of these functions from my controllers and all right away, use the structuring.

39
00:03:03,040 --> 00:03:10,210
So go with const and then the name is get all products, of course, and then get all product and all

40
00:03:10,450 --> 00:03:11,200
the static one.

41
00:03:11,540 --> 00:03:13,060
And that is equal to require.

42
00:03:13,570 --> 00:03:18,790
Then we're looking at controllers and then of course the five we're looking for is the product.

43
00:03:19,210 --> 00:03:25,450
And then if you remember, we have multiple options and in this case I'm going to load router out and

44
00:03:25,450 --> 00:03:26,800
then I'll go forward slash.

45
00:03:27,190 --> 00:03:37,720
So essentially this is going to be for that main route here, the API version one and product as far

46
00:03:37,720 --> 00:03:39,190
as which controller I want to use.

47
00:03:39,460 --> 00:03:43,720
I'll use this, get all products and please don't mix them up again.

48
00:03:43,990 --> 00:03:48,100
The controller you want to pass in is get all product.

49
00:03:48,490 --> 00:03:54,490
And as far as the static one, let's copy and paste and then we'll just add that here at the end.

50
00:03:54,760 --> 00:04:00,730
So this is going to be our main path or growth path and then we're going to go with forward slash static.

51
00:04:01,000 --> 00:04:05,800
And this is where we want to pass in that get all product static.

52
00:04:06,370 --> 00:04:10,300
And then once we have this setup in place now, of course, we just need to export this.

53
00:04:10,600 --> 00:04:15,610
So look for module exports and of course, we'll export our hardware.

54
00:04:16,000 --> 00:04:23,380
And once we have set up the routes, then, of course, let us just finally navigate back to the yes,

55
00:04:23,800 --> 00:04:27,490
of course, we do want to import that and come up with some kind of name.

56
00:04:27,820 --> 00:04:33,850
And in my case, I'm going to do that right after the connectivity and we'll just say const and I'll

57
00:04:33,850 --> 00:04:37,930
name this product router not as equal to require.

58
00:04:38,260 --> 00:04:40,180
And then I'm looking in the right folder.

59
00:04:40,870 --> 00:04:46,210
And then more specifically, you want to get the product and then let's keep on scrolling.

60
00:04:46,540 --> 00:04:53,740
And where we have Avodart use for our middleware now of course will pass in our router.

61
00:04:54,040 --> 00:04:57,910
So let's just say here products and router.

62
00:04:58,270 --> 00:05:01,780
And once we save, I'll spin up the server one more time.

63
00:05:02,170 --> 00:05:07,690
And if you want to test this out, let's just navigate back to the browser.

64
00:05:07,930 --> 00:05:09,490
So I think I can close this one.

65
00:05:10,030 --> 00:05:13,810
And at the moment it says route does not exist.

66
00:05:14,140 --> 00:05:16,870
But once we refresh, check it out.

67
00:05:16,870 --> 00:05:19,710
Of course, now we have a message product throughout.

68
00:05:19,870 --> 00:05:20,500
Beautiful.

69
00:05:20,680 --> 00:05:25,390
And that if we want to test all the static one, well, we have product that's.

70
00:05:26,310 --> 00:05:30,960
And once we have all of this in place now, of course, we can move on to our next task.

