WEBVTT

00:03.730 --> 00:04.570
Hey there, everyone.

00:04.640 --> 00:05.170
Thanks here.

00:05.170 --> 00:07.090
And yes, quite a lot of in-depth talk.

00:07.090 --> 00:11.050
But this talk is really necessary that you understand everything in detail.

00:11.050 --> 00:13.960
And that's what the exact goal of this course to make you pro.

00:14.080 --> 00:16.180
Now let's go ahead and finally export this.

00:16.180 --> 00:18.100
We actually forgot to export this class.

00:18.100 --> 00:20.080
So all we got to do is module dot export.

00:20.080 --> 00:21.400
So let's go ahead and do that.

00:21.400 --> 00:28.570
We're going to go ahead and say module dot exports and we're going to export this where clause where

00:28.570 --> 00:29.020
we go.

00:29.170 --> 00:30.460
That's all what we got to do.

00:30.850 --> 00:33.700
And now we can import this class anywhere we like.

00:33.700 --> 00:36.040
We're going to go into the product controller itself.

00:36.040 --> 00:37.660
We have worked on adding the product.

00:37.660 --> 00:40.810
Now we need to work on how we are going to get all the products.

00:40.810 --> 00:42.970
We haven't adjusted the route on this one.

00:42.970 --> 00:44.290
We will do that in the next video.

00:44.290 --> 00:47.200
But right now let's go ahead and export another method.

00:47.200 --> 00:52.090
So this one is going to simply get all products.

00:52.090 --> 00:56.320
Now technically the name get all product is not to be honest, really correct.

00:56.320 --> 00:58.510
Because you're not getting all the product all the time.

00:58.510 --> 01:02.710
But again, if you don't pass me any query or any pagination or something, I'll give you all the products

01:02.710 --> 01:03.190
here.

01:03.190 --> 01:08.650
But if you do pass me that my helper method is all ready to actually go ahead and import all of that.

01:08.770 --> 01:10.630
So let's go ahead and wrap this up.

01:10.630 --> 01:12.880
So we're going to go ahead and say exactly same.

01:13.480 --> 01:14.800
Give me a big promise.

01:14.800 --> 01:23.380
I'll be using a sync and inside that we'll be having request response and the next, just like always.

01:23.590 --> 01:24.610
And there we go.

01:25.180 --> 01:30.100
Now, in case it would be a normal thing, then I would be saying something like this Hey, we have

01:30.100 --> 01:33.610
all the products, products, products.

01:33.610 --> 01:36.640
And then we this is going to be actually an array.

01:36.640 --> 01:39.100
And all we've got to do is simply use the model.

01:39.100 --> 01:44.770
So we're going to say, hey, product, let's use that and we are going to go ahead and say find.

01:45.400 --> 01:48.790
And inside the find, we don't pass on anything further down the road.

01:48.790 --> 01:58.660
We just say this response dot status that you have received something to 100 and a dot JSON and we can

01:58.660 --> 02:06.100
go ahead and say simply success is going to be true and we go ahead and just throw it on all the products.

02:06.100 --> 02:06.670
That's it.

02:06.670 --> 02:10.240
That is usually the case, but not in this one.

02:10.240 --> 02:13.960
We have to actually go a little bit smarter because the product can be a really long list.

02:13.960 --> 02:16.780
So we need to define a few variables and work on with that.

02:16.780 --> 02:20.620
But again, this is also fine in case you want to just define a separate method for getting all the

02:20.620 --> 02:22.090
products, and that's pretty much it.

02:22.240 --> 02:25.780
Now let's go ahead and define this one and let me walk you through with a couple of more stuff that

02:25.780 --> 02:26.500
you can do.

02:26.530 --> 02:33.670
The first thing is going to be simply result per page so that how many results you want per page, maybe

02:33.670 --> 02:34.900
you want just the two.

02:34.930 --> 02:39.370
Maybe you want to show two products for product, six product or maybe five products.

02:39.370 --> 02:40.240
So it's up to you.

02:40.240 --> 02:43.540
I'll go with the four because it makes sense to have one, two, three, four.

02:43.540 --> 02:44.710
So I'll have a big columns.

02:44.710 --> 02:48.880
Maybe I'm assuming in the front end, two products in one row and two products another row.

02:48.910 --> 02:52.120
Maybe you want to show six, product six makes sense.

02:52.120 --> 02:56.230
So let's go ahead and throw up six products in this one, three in the top row, three in the second

02:56.230 --> 02:56.440
row.

02:56.440 --> 02:57.760
I'm kind of assuming that.

02:58.180 --> 03:03.040
Now, in case you want to find out that how many total products you have got, you don't need to hold

03:03.040 --> 03:06.010
this one and need to calculate like products at length.

03:06.010 --> 03:11.320
Surely that is also a way, but just optionally telling you that there is also a way in this you can

03:11.410 --> 03:12.610
just count the product.

03:12.610 --> 03:18.100
So we're going to say count product or product count, whatever you say, you can go ahead and request

03:18.100 --> 03:21.400
that, hey, I want to again, this is a database stock, so we need to go ahead and await.

03:21.400 --> 03:23.500
In fact, we need to go ahead and talk and wait here.

03:23.500 --> 03:28.240
But we'll change that in a minute so we can go ahead and say, hey, I want to use a product.

03:28.600 --> 03:32.890
And this product has a by default built in method which says count documents.

03:32.890 --> 03:35.110
As soon as you run this, this will give you.

03:35.560 --> 03:39.310
But we are not going to need it just in case you want to have it.

03:39.310 --> 03:42.640
Again, I'm going to comment this out just to make sure that you know about it.

03:42.970 --> 03:43.280
Okay.

03:43.300 --> 03:47.560
What we're going to do here is we are going to import a class where class.

03:47.560 --> 03:49.780
So let's go ahead and say that I want to bring in.

03:49.780 --> 03:52.270
So I'll be saying simply where class.

03:52.270 --> 03:53.530
Let's import that.

03:53.740 --> 03:54.400
There we go.

03:54.430 --> 03:55.000
Nice and easy.

03:55.000 --> 03:55.780
It comes in.

03:55.960 --> 04:00.760
Now, the idea behind having this very clause is to accept that there might be more things that might

04:00.760 --> 04:02.140
be coming into the picture.

04:02.140 --> 04:06.580
So rather, what I'll be doing is I'll be creating a new object from this very class.

04:06.580 --> 04:09.850
So let's cut this out and in fact, remove this one here.

04:10.240 --> 04:14.590
Let's go ahead and say that whatever the products are going to come in, they are going to come in as

04:14.590 --> 04:16.180
this class result.

04:16.300 --> 04:18.970
So this one is very close.

04:18.970 --> 04:20.410
It takes two parameters.

04:20.410 --> 04:22.060
The first one is the base itself.

04:22.060 --> 04:25.510
The base in this case is going to be product dot find.

04:25.510 --> 04:27.160
So it just finds everything.

04:27.160 --> 04:31.390
And further down the road we can just pass on whatever the query user is giving is.

04:31.390 --> 04:34.450
So request dot simply query.

04:35.980 --> 04:36.730
There we go.

04:37.270 --> 04:39.970
Now in case there is no query at all and the request then.

04:39.970 --> 04:45.790
Okay, we just find a pass on the product, find it will give me all the results back and I'll store

04:45.820 --> 04:47.500
that and I'll just throw them out.

04:47.590 --> 04:53.200
Okay, that is nice, but it's not going to do it automatically because in case you remember, if we

04:53.200 --> 04:57.250
are working on to this where clause by default it doesn't do anything.

04:57.250 --> 05:01.810
This is just a constructor, so it's going to throw it back as it is in case the big query doesn't exist.

05:02.040 --> 05:07.830
Because all these methods the search, the filter and the page, nature or the pager, whatever you

05:07.830 --> 05:14.970
want to call this one page nature is, by the way, a term for these Python based Django framework.

05:14.970 --> 05:17.060
So that's why I call them as page eight or someti.

05:17.070 --> 05:20.200
So all these method actually works on this query itself.

05:20.220 --> 05:22.250
So let's go ahead and work on with that.

05:22.260 --> 05:27.420
So what we're going to say that, hey, once I have passed you on to this one, then I would run the

05:27.420 --> 05:28.470
method onto this one.

05:28.470 --> 05:30.000
So this method will give me that.

05:30.000 --> 05:32.220
Hey, just go ahead and give me a search result.

05:32.310 --> 05:37.380
But there might be a case that you might also have given me some of the filter data as well.

05:37.560 --> 05:40.830
So let's just go ahead and say, hey, you might be running it through the filter.

05:40.830 --> 05:42.270
Let's go ahead and save this one.

05:42.270 --> 05:43.230
And there we go.

05:43.650 --> 05:46.380
So now this class will give me back a result.

05:46.380 --> 05:50.420
All the products will be coming up, so I'll be just sending the products just like that.

05:50.430 --> 05:52.110
Okay, so that is nice.

05:52.110 --> 05:58.380
But the thing is now there might be somebody who who is at the front end might be looking for that,

05:58.380 --> 06:02.550
hey, how many total products you are giving me because I have to set the pagination on the front end

06:02.550 --> 06:03.600
UI as well.

06:03.660 --> 06:08.970
I can give you the list of all the products by using the first method here, but this is the all the

06:08.970 --> 06:09.360
count.

06:09.360 --> 06:10.380
I don't want all the count.

06:10.380 --> 06:15.630
I want the count after the filtration process has been done and there is no shortcut for that one.

06:15.630 --> 06:17.880
We have to give the result of this one.

06:17.880 --> 06:27.060
So we're going to go ahead and say this one as let's call this one as filtered product number.

06:27.060 --> 06:29.690
Maybe just to clarify that what we are actually giving him.

06:30.030 --> 06:35.190
So we're going to go ahead and say products dot length.

06:35.190 --> 06:35.940
There we go.

06:35.940 --> 06:39.120
Now, obviously, this is designed just to we throw it out here.

06:39.120 --> 06:43.260
So we're going to go ahead and say, hey, all these products here are and this is the filter number

06:43.260 --> 06:43.650
of product.

06:43.650 --> 06:46.650
Maybe you want to have this count product or total count as well.

06:46.650 --> 06:47.790
Total product count.

06:48.030 --> 06:50.750
This actually makes sense to have a total product down.

06:50.760 --> 06:54.000
Maybe you want to throw that out what it's doing up here.

06:54.000 --> 06:55.590
Let's go ahead and throw that out also.

06:55.590 --> 06:56.490
So there we go.

06:56.520 --> 06:59.550
We are going to put up a comma and throw that out also on the front end.

06:59.910 --> 07:05.670
Okay, this is nice, but you might be wondering that, hey, why you haven't actually applied this

07:05.670 --> 07:06.300
filter?

07:06.900 --> 07:09.780
You have applied the filter, but why haven't you applied this pagination?

07:09.780 --> 07:11.430
We have worked so much hard on that one.

07:11.430 --> 07:12.990
Let's go ahead and also apply that.

07:12.990 --> 07:13.800
No big deal.

07:14.400 --> 07:17.490
So once this is all done, we have gone through with all these things.

07:17.490 --> 07:20.370
Now let's go ahead and see that how the filter product works on.

07:20.370 --> 07:22.620
So we need to modify a few things based on that.

07:22.920 --> 07:28.380
So further down the road, I'm going to go ahead and say that, hey, let's go ahead and create this

07:28.380 --> 07:30.900
one, the result of this one, which is products.

07:32.870 --> 07:37.100
And now whatever this product is, I can actually run a simple pager on that.

07:38.620 --> 07:40.540
So did I call it as pager?

07:41.810 --> 07:42.170
Yep.

07:42.170 --> 07:43.040
This is pager.

07:44.270 --> 07:49.880
Since this is an object of this class, I can go ahead and actually run this pager directly on this

07:49.880 --> 07:55.280
one because ultimately, end of the day, this is a kind of array obviously, but being created from

07:55.280 --> 07:56.150
this class.

07:56.690 --> 07:59.850
So I can run this one, but this actually expects a parameter.

07:59.870 --> 08:02.480
This is the way how we have designed it result per page.

08:02.480 --> 08:05.380
So that's why exactly the result per page was designed.

08:05.390 --> 08:07.940
So go ahead and copy and paste on this one.

08:07.940 --> 08:10.190
So results per page actually goes in there.

08:10.490 --> 08:11.330
There we go.

08:11.660 --> 08:14.480
Now, what you might have received back from this one.

08:14.480 --> 08:17.210
So right now this has given us us everything.

08:17.210 --> 08:21.440
So we need to store that into some of the value as well.

08:21.470 --> 08:22.790
Let's go ahead and do that.

08:22.790 --> 08:24.820
So this has gone through with the values.

08:24.830 --> 08:28.490
Let's go ahead and store that again into the product so we can actually do it here as well.

08:28.640 --> 08:33.110
But anyways, so we're going to go ahead and say, hey, products, now you need to update it if you

08:33.110 --> 08:40.610
have something into the page itself and we're going to go ahead and say a weight and products.

08:43.530 --> 08:46.170
And we will be extracting the base from it.

08:47.310 --> 08:52.410
Now the reason why we are extracting base from this one and not anything else, because if you go up

08:52.410 --> 08:55.790
into the where clause, remember we are adjusting the base.

08:55.800 --> 09:00.920
The only thing that it is doing is adding a dot limit and dot skip and the proper values on this.

09:00.930 --> 09:06.720
Now in case in case this is looking up too much for you that hey, these lines are actually confusing

09:06.870 --> 09:07.530
to me.

09:07.560 --> 09:12.810
All you can do is you can actually come up here and can simply say, Hey, products.

09:14.110 --> 09:15.010
There we go.

09:15.040 --> 09:21.820
I want to add a limit on to you and I want to add a skip onto you so you can go ahead and provide these

09:21.820 --> 09:22.600
methods.

09:22.600 --> 09:28.120
And again, you have to do the calculation of how many values to escape, how many values limit that

09:28.120 --> 09:31.570
means how many results per page I have to give so you can go ahead and add this one.

09:31.570 --> 09:34.180
This is exactly what is happening in this one method.

09:34.180 --> 09:40.330
So behind the scene in the page at itself, it is just adding a dot limit and skip and whatever the

09:40.330 --> 09:42.520
result is, we are actually awaiting that.

09:42.520 --> 09:47.470
So it is going to go ahead and calculate and run these queries obviously because this product is actually

09:47.470 --> 09:50.170
hold now all the values and the base especially.

09:50.350 --> 09:53.410
So it's going to just go ahead and run the result and store that into this one.

09:53.410 --> 09:55.690
So again, in case this is too much, go ahead and add this.

09:55.690 --> 09:58.570
But I'm pretty sure after this explanation it should be all easier for you.

09:58.990 --> 10:01.330
And end of the day, we are not doing anything else.

10:01.330 --> 10:06.430
We are just throwing up the product's filtered product number and the total count product.

10:06.430 --> 10:08.530
So that sounds okay.

10:08.530 --> 10:09.490
And there we go.

10:09.490 --> 10:14.320
I know this is a little bit of a complex work, but again, this is a pro work and you'll be doing this

10:14.320 --> 10:17.380
one repetitively in many of the model itself.

10:17.380 --> 10:19.540
So let's go ahead and catch up in the next video.
