WEBVTT

00:03.970 --> 00:07.630
Hey, did everyone that they share and welcome to another section.

00:07.810 --> 00:12.790
So the previous section, we had a lot of discussion about the user model, which is a pretty common

00:12.790 --> 00:15.250
model in every application that you will be building up.

00:15.280 --> 00:20.050
Now, in this section, we're going to talk about another very common model, which is a product model.

00:20.170 --> 00:24.880
Now, before I talk about the product model, here is something that I've created, as I discussed earlier

00:24.880 --> 00:27.040
with you in the section that I won't be showing you that.

00:27.040 --> 00:29.170
How am I actually writing this?

00:29.170 --> 00:30.520
Because this is really basics.

00:30.520 --> 00:34.000
We have already in the chapter two scene that how we can write the documentation.

00:34.030 --> 00:38.500
And also apart from this, this entire swagger documentation will be available to you.

00:38.510 --> 00:41.770
So in case you want to check it out, you can always go ahead and look into this.

00:41.770 --> 00:43.600
That's how this was written and everything.

00:43.960 --> 00:44.650
Discussion part.

00:44.650 --> 00:49.390
We have already done it and whenever I'm getting some free time in between editing the videos and all

00:49.390 --> 00:51.130
of that, that's where I'm writing this.

00:51.130 --> 00:57.520
So just showing you that, yes, I've categorized this into home users, admin and manager and we'll

00:57.520 --> 00:59.620
have a lot more features now.

00:59.620 --> 01:04.980
Just specific to products, some more categories will go into admin and whole bunch of stuff.

01:04.990 --> 01:11.680
So for example, in the post category, we designed a simple URL or a root which say slash admin, slash

01:11.680 --> 01:15.490
user and if it provides an ID, he can edit the ID of the URL.

01:15.490 --> 01:17.860
So these are the fields that he can manipulate.

01:17.890 --> 01:20.950
I have restricted the user from a user admin and manager.

01:20.950 --> 01:24.820
These are the role he can actually apply and all these fields are necessary.

01:24.820 --> 01:29.530
The ID will go in the path, rest will go into the farm data or the body itself.

01:29.560 --> 01:30.940
So really very basic.

01:30.940 --> 01:32.170
Something that we have already seen.

01:32.170 --> 01:34.000
Nothing groundbreaking or nothing magical.

01:34.000 --> 01:36.070
In case you want to see, you can check this out.

01:36.490 --> 01:37.150
Moving on.

01:37.150 --> 01:42.850
So what we're going to do now in the previous one, the previous all section, in fact, a couple of

01:42.850 --> 01:45.370
sections we have talked about in depth about user model.

01:45.370 --> 01:50.620
And that's all you'll be doing is whatever the application here, you will be building up JWT tokens

01:50.620 --> 01:55.300
and password resets and forgot password, maybe verification of the user or something similar.

01:55.300 --> 01:59.890
So that part is all covered up and I'm pretty sure any more functionality that comes to your way, you'll

01:59.890 --> 02:01.690
be absolutely able to mail it down.

02:01.990 --> 02:07.210
Now moving on to the another big major part when you'll be developing any application is the product

02:07.210 --> 02:12.640
itself now, although I call it as the product here, but I in personal life call this one as a card

02:12.640 --> 02:14.460
feature or a card model.

02:14.470 --> 02:16.030
Now, why do I say it as a card?

02:16.030 --> 02:20.230
Because whatever the application you are going to be building up, this is the major card that comes

02:20.230 --> 02:21.190
into the picture.

02:21.190 --> 02:25.690
For example, in case you are working with any shopping application, then all the products actually

02:25.690 --> 02:26.770
come into that card.

02:26.770 --> 02:32.080
So all the pricing details, all the kind of a name of the product photos, everything comes there.

02:32.080 --> 02:35.260
If you order food, that food itself is a card item.

02:35.260 --> 02:40.300
So your pizza, whatever you're ordering up, this is all entirely going up there in every application

02:40.300 --> 02:42.250
you need to figure out what is the product itself.

02:42.250 --> 02:45.760
That is the main thing that you are selling for me at my online website.

02:45.760 --> 02:48.880
The courses are the product itself, so they are the card items.

02:48.880 --> 02:50.950
So that is what I mean to say about that.

02:51.100 --> 02:55.390
Now in these ones, just like in the previous one, we saw that these are the things going on with the

02:55.390 --> 03:00.670
token middleware side of the cache cases of handling images, reset password and all of that.

03:00.670 --> 03:03.700
These are the major features that we work with the user model.

03:03.730 --> 03:07.240
In the case of product model, the major that we work on is the refs.

03:07.240 --> 03:11.530
For example, you want to inject some another model into this product model.

03:11.530 --> 03:15.100
For example, we'll be injecting user whoever is going to create the model.

03:15.100 --> 03:18.010
So we are going to learn that how we can interact with the model.

03:18.010 --> 03:21.670
This model needs to interact with another model, so we need to have a relation between them.

03:21.670 --> 03:24.100
So how we can do that, that's going to be the one thing.

03:24.250 --> 03:28.390
Another thing that we work on with is the pagination, the search thing or the filter.

03:28.390 --> 03:29.290
So I'll walk you through that.

03:29.290 --> 03:32.080
How you can actually use these search things.

03:32.080 --> 03:37.450
You can use some of the pagination filters, kind of a very common, absolute common thing in the product.

03:37.450 --> 03:41.200
And that's going to be our major journey of understanding throughout this section.

03:41.200 --> 03:44.050
It is really easy compared to the previous one.

03:44.050 --> 03:46.360
What we have seen, it's rather very easy.

03:46.540 --> 03:49.360
Okay, so let's go ahead and do a setup.

03:49.360 --> 03:53.950
I won't be talking much on to the YAML here, so let's go ahead and close all of this.

03:54.850 --> 03:55.360
Okay.

03:55.570 --> 03:59.620
Now, interestingly, we need to have another model, so let's go ahead and create a new file.

03:59.620 --> 04:04.720
We are going to call this one as simply product JS because this model will handle the entirety of the

04:04.720 --> 04:05.330
product.

04:05.350 --> 04:09.670
Now similar to this, we have to create a controller, so let's go ahead and create a new file into

04:09.670 --> 04:10.060
this one.

04:10.060 --> 04:12.400
So this one is going to be simply product.

04:13.170 --> 04:17.940
Product Controller Controller GS.

04:19.430 --> 04:21.350
And here all of the roots will come up.

04:21.350 --> 04:25.790
So whatever the roots we had previously, like we had some roots in the home and stuff.

04:25.790 --> 04:27.410
So we're going to be using something like that.

04:27.410 --> 04:33.440
In fact, what I can do is I can actually copy this and I will put it into product controller.

04:33.440 --> 04:34.880
So let's go ahead and put that.

04:34.880 --> 04:40.760
And this one is going to be just for momentarily as a test product so that we can see everything is

04:40.760 --> 04:42.290
working fine or not.

04:42.710 --> 04:43.940
This tri catch.

04:44.390 --> 04:45.800
Yeah, seems okay.

04:45.860 --> 04:47.090
Nothing too bad.

04:47.090 --> 04:51.170
But actually we don't need this watch, so we're going to go ahead and remove this one.

04:51.350 --> 04:54.080
We don't need any catch functionality.

04:54.080 --> 04:58.550
We just need somebody to say, hey, this is this is a test for product.

04:58.820 --> 05:02.210
So let's go ahead and say this is a test for.

05:04.130 --> 05:07.000
Product save that looks okay.

05:07.010 --> 05:09.830
Now, the next thing that we do is we need to have some roots as well.

05:09.830 --> 05:12.230
So this is going to be the root for product call.

05:12.230 --> 05:17.930
This one is product root or simply product JS however you like, and this is going to have exact same

05:17.930 --> 05:19.370
functionality as for the user.

05:19.370 --> 05:23.180
We have discussed quite a lot about this one in the past, so we're going to go ahead and borrow some

05:23.180 --> 05:24.080
code from here.

05:24.230 --> 05:26.150
So let's go ahead and copy this.

05:26.600 --> 05:29.480
And inside the product root, let's go ahead and paste that.

05:29.600 --> 05:34.700
Now at the very end of it, we need to export this router, so let's go ahead and copy this and export

05:34.700 --> 05:39.290
this one and told you once we set up the things, the next of the things after that remains really,

05:39.290 --> 05:40.160
really easy.

05:40.160 --> 05:43.580
So this is all what we got and this is how we are going to be working on.

05:43.580 --> 05:46.610
We need to import our test product root here as well.

05:46.610 --> 05:51.590
So let's go ahead and add that since we are going to need middleware as well, let's copy this and bring

05:51.590 --> 05:52.970
in the middleware as well.

05:53.990 --> 05:56.330
And after that, we're going to need the test product.

05:56.330 --> 05:59.240
So we're going to say, hey, test product, let's bring that.

05:59.240 --> 06:03.020
So test product is here and now we need to create a simple root.

06:03.020 --> 06:07.280
So let me remove this and let's copy another line and this line looks okay.

06:07.280 --> 06:10.760
Just grab any line or in case you want to write that, that's fine too.

06:11.240 --> 06:20.450
And I'm going to go ahead and make this one as simply test product and it will be governed by the test

06:20.450 --> 06:21.980
product controller.

06:23.030 --> 06:27.800
Okay, so this is it, but this is not the entirety of the stuff we need to just once, for once we

06:27.800 --> 06:28.610
have to touch this.

06:29.030 --> 06:31.790
JS Because this root needs to go there as well.

06:31.880 --> 06:34.940
So if I go ahead and check here, I'm importing all of the roots.

06:34.940 --> 06:36.950
So let's go ahead and bring this one.

06:37.160 --> 06:39.770
Let's go ahead and call this one as simply product.

06:39.980 --> 06:44.450
And this will be coming up from Roots slash product.

06:44.600 --> 06:47.180
And let's go ahead and create a middleware for this one as well.

06:47.180 --> 06:51.530
That, hey, on the same one, the roots are going to be controlled by the product itself.

06:51.530 --> 06:52.430
So there we go.

06:52.460 --> 06:57.290
Now, in theory at least, we have set it up in such a way that we are exporting a controller.

06:57.290 --> 06:58.400
There is a model as well.

06:58.400 --> 07:03.260
We haven't worked on that, but there is a controller which is test product which will be governed on

07:03.260 --> 07:05.180
some route that we have mentioned up here.

07:05.180 --> 07:11.120
And we have abg's configured that the middleware actually sends all these routes if it is there into

07:11.120 --> 07:11.750
these files.

07:11.750 --> 07:17.240
So all we've got to do is let's go ahead and change this one to get and see if the test product route

07:17.240 --> 07:19.910
is there or we can actually go ahead and grab it.

07:19.910 --> 07:21.050
So copy that.

07:21.380 --> 07:22.460
Let's go up here.

07:22.460 --> 07:26.330
And obviously I would love to create a new folder here because we'll be testing up new things.

07:26.330 --> 07:31.850
So let's go ahead and say add a folder and I'm going to call this one folder as simply product.

07:32.660 --> 07:34.400
And let's close all of these.

07:34.400 --> 07:35.300
Some of them are good.

07:35.300 --> 07:37.160
Some of them need to be changed a little bit.

07:37.160 --> 07:41.990
Probably I'll check them later on, but I'm not too much worried because I've already worked quite a

07:41.990 --> 07:43.040
lot on the swagger.

07:43.040 --> 07:44.150
So that is it.

07:44.870 --> 07:45.740
Okay.

07:45.740 --> 07:47.900
And come on, please don't show me this.

07:47.900 --> 07:49.040
I just want to close.

07:51.180 --> 07:52.350
And there we go.

07:53.450 --> 07:56.910
Okay, so let's go ahead and now create a request onto this product.

07:56.910 --> 07:59.090
So let's go ahead and say, hey, I want to add a.

08:00.050 --> 08:01.400
At a request of this product.

08:01.400 --> 08:03.830
First, I'm going to go ahead and save this one.

08:04.370 --> 08:07.100
So this one is going to be test product.

08:07.100 --> 08:07.940
I'm not going to keep it.

08:07.940 --> 08:12.590
I'm just showing you how to how to actually go ahead and add that into the t shirt store, go into the

08:12.590 --> 08:14.900
product and go ahead and save this one.

08:14.900 --> 08:17.810
So now this all the requests are going inside that one.

08:18.020 --> 08:21.560
And all we've got to do is simply go ahead and say, hey, domain.

08:22.610 --> 08:23.150
There we go.

08:23.160 --> 08:24.710
My domain, not domain.

08:25.130 --> 08:28.640
And this one is slash test product.

08:28.820 --> 08:33.230
If I go ahead and send a get request, we are getting that this is a test product route.

08:33.230 --> 08:35.690
So everything is working absolutely fine.

08:35.690 --> 08:38.860
As expected, at least our routes and controllers are there.

08:38.870 --> 08:42.860
In the next video, we're going to work on the models and this is where you are going to see that,

08:42.860 --> 08:47.280
how you can inject existing model into this particular model itself.

08:47.330 --> 08:52.430
This will help you to understand that how we can inject users, maybe you want to add some another models

08:52.430 --> 08:53.510
and want to inject them here.

08:53.510 --> 08:55.610
So it's going to be all in control there.

08:55.610 --> 08:57.710
Let's go ahead and catch up in the next video.
