WEBVTT

00:05.120 --> 00:06.560
Hey, did everyone share?

00:06.560 --> 00:10.820
And in this video, we're going to go ahead and see that if somebody gives me this object, ID, this

00:10.820 --> 00:13.670
ID of the order, I need to search this object.

00:13.670 --> 00:20.180
And again, it can come up from the params URL, maybe a query format, maybe a body format.

00:20.180 --> 00:22.970
However you are going to design, the front end guy is going to follow along.

00:22.970 --> 00:26.330
So we expect that this comes up into your URL, let just say.

00:26.330 --> 00:28.910
So let's go ahead and design the method according to that.

00:29.030 --> 00:35.540
So we're going to go ahead and say export and this one is going to be get one order.

00:35.540 --> 00:37.130
And that's exactly what we are doing.

00:37.370 --> 00:43.880
And in fact, I would love to remove this and copy this because this is what I love.

00:43.910 --> 00:44.810
Okay, there we go.

00:44.990 --> 00:47.120
We can actually shrink this one again.

00:47.120 --> 00:51.380
I just I'm just doing it so that I don't have to write this big promise and everything.

00:51.710 --> 00:57.350
Let's remove everything inside this and not everything we can keep this status.

00:57.470 --> 00:58.070
Okay.

00:58.490 --> 01:00.080
So the goal is really simple.

01:00.080 --> 01:05.750
Let's go ahead and find a particular order based on something is coming in the URL.

01:05.750 --> 01:15.680
So all we got to do is order dot find by ID and find by ID will say request dot, params dot and let's

01:15.680 --> 01:18.680
call this one as simply ID and that's pretty much it.

01:18.680 --> 01:21.650
Let's go ahead and say const and this one is going to be order.

01:21.650 --> 01:25.820
And by the way, this is okay.

01:25.880 --> 01:26.380
Yeah.

01:26.900 --> 01:31.730
Just thinking ahead of myself sometime it happens to all the programmers that they try to think a little

01:31.730 --> 01:34.130
bit ahead of the future versions and then they get lost.

01:34.130 --> 01:35.360
It happens to me also.

01:35.750 --> 01:40.130
Okay, so this is all and let's go ahead and check if something is returning or not, because in this

01:40.130 --> 01:44.180
case, the ID in the URL itself can be polluted.

01:44.300 --> 01:50.090
So in this save, if we don't receive any order, let's go ahead and simply return and close this method

01:50.090 --> 01:50.840
right here.

01:51.380 --> 01:52.100
Return.

01:52.370 --> 01:53.240
Let's wrap it up.

01:53.240 --> 01:56.090
In the next, create a new custom error.

01:57.590 --> 01:59.690
Custom error.

02:01.810 --> 02:02.680
There we go.

02:02.810 --> 02:05.470
Didn't we brought in the customer in the first place?

02:05.590 --> 02:06.460
No, we didn't.

02:06.970 --> 02:08.950
So this is the custom error that we got.

02:08.950 --> 02:11.740
And this custom error takes parameter of saying.

02:14.240 --> 02:19.670
Please check order ID and we're going to go ahead and say classic 401.

02:20.180 --> 02:24.230
And in this one, we are going to send the response as ordered back.

02:24.260 --> 02:27.860
This is already going in so it looks like all OC.

02:28.100 --> 02:30.860
Let's go ahead and see that how this is going to work in.

02:31.190 --> 02:33.630
Let's go ahead and export this create order.

02:33.690 --> 02:34.770
Now, this is not create order.

02:34.790 --> 02:37.460
This is get one order.

02:37.550 --> 02:38.630
Save that.

02:39.410 --> 02:40.670
Let's copy this.

02:40.670 --> 02:46.010
Go into the roots and say that I need another root, which is going to be simple.

02:46.010 --> 02:55.610
Get root and user should be logged in and then we are going to just grab this one and let's go ahead

02:55.610 --> 02:59.240
and say a comma here, get one order.

02:59.240 --> 03:01.610
This one will be managed by get one order.

03:01.610 --> 03:07.690
So this is all pretty much it if somebody wants to get that, hey, what is the order that I'm having?

03:07.880 --> 03:10.040
We're going to grab the order here again.

03:10.040 --> 03:13.700
This is something how we are going to get the ID.

03:14.060 --> 03:15.190
I think this is all okay.

03:15.200 --> 03:17.000
Let me just quickly check it one more time.

03:17.000 --> 03:20.480
So in the order controller, we are expecting that in the parameters it will come.

03:20.480 --> 03:21.170
We'll check that.

03:21.170 --> 03:21.410
Okay.

03:21.410 --> 03:22.700
Nice and easy here.

03:22.700 --> 03:26.210
We are saying that slash order slash ID, give me that ID and I will give you back.

03:26.210 --> 03:27.950
You should be logged in to do so.

03:28.610 --> 03:31.760
So it looks like all is okay.

03:32.180 --> 03:33.890
Let's go ahead and test out this route.

03:34.730 --> 03:36.410
So I will go up here.

03:36.440 --> 03:38.210
Let's go ahead and save this one.

03:38.900 --> 03:47.060
And this one is going to be get one order by ID and save that.

03:47.840 --> 03:49.130
Is it a get request?

03:49.160 --> 03:50.690
Yeah, this is a get request.

03:52.110 --> 03:54.970
Let's go ahead and move it to get save that.

03:54.990 --> 04:01.440
And now all we've got to do is make sure we in the previous one when we were creating the order and

04:01.440 --> 04:04.380
again this get order by ID should not be here.

04:04.380 --> 04:05.520
It should be here.

04:06.880 --> 04:07.570
There we go.

04:07.870 --> 04:09.520
So this is the one.

04:09.550 --> 04:09.850
Okay.

04:09.850 --> 04:10.510
Nice and easy.

04:10.510 --> 04:12.670
When we were creating the order itself.

04:14.300 --> 04:17.690
We had the object being received, but again, we don't have it.

04:17.690 --> 04:24.280
Now, let's go ahead and say that this is order slash and can we get the order I.D. from here?

04:24.290 --> 04:25.400
This is the ID exact.

04:25.400 --> 04:27.920
So we expect that all of this data should come in.

04:28.890 --> 04:32.490
Let's go ahead and paste this and send a get request.

04:32.490 --> 04:33.260
And there we go.

04:33.270 --> 04:33.690
Success.

04:33.690 --> 04:33.960
True.

04:33.960 --> 04:35.200
And order is coming in.

04:35.220 --> 04:38.340
Now, I wanted to show you something really interesting here.

04:38.460 --> 04:43.230
Now, notice here the user is coming in as this ID, so which is F one.

04:43.230 --> 04:46.080
So we can actually go back up here and check out that.

04:46.080 --> 04:47.360
Who is the user up here?

04:47.370 --> 04:52.980
So in this case, if I check one, there is a last F one here and I can go into my user model and check

04:52.980 --> 04:54.000
out who plays this one.

04:54.000 --> 05:00.240
So this was placed by two, but maybe sometimes you actually want more information to be coming up as

05:00.240 --> 05:06.000
because the guy who is at the front end might want to check that who is the order or who is the user

05:06.000 --> 05:09.120
who has placed this order, his name and email and all that information.

05:09.120 --> 05:14.760
So he might have to take this request or take this user and have to send another request to our back

05:14.760 --> 05:14.880
end.

05:14.880 --> 05:17.190
We can actually make the life a little bit easier.

05:17.340 --> 05:22.710
So for this one, what we can do is just need to go into the order controller and the place where we

05:22.710 --> 05:23.640
are having this order.

05:23.640 --> 05:26.940
We know that there is something, a situation similar to this.

05:26.940 --> 05:32.400
So what we can do is remove this one and use a method which is populate there we go.

05:32.400 --> 05:34.620
In the populate you just pass on two parameter.

05:34.620 --> 05:38.580
The first one is which field do you want to further down drill down there?

05:38.580 --> 05:43.770
And you can see that we have a lot of such fields available in this in this case, which is the orders.

05:43.770 --> 05:46.590
So all we want to do is drill down this user field here.

05:46.590 --> 05:47.580
So this is the user.

05:47.580 --> 05:52.320
Remember, it's not the model that I'm referring, it's the property of the model that I'm referring

05:52.320 --> 05:52.770
here.

05:52.770 --> 05:53.820
So this is the one.

05:53.820 --> 05:59.700
So I want to drill down for that user and this is reliable that will automatically be evaluated.

05:59.700 --> 06:01.650
And what are the information that you want to grab?

06:01.650 --> 06:02.910
Maybe I want to grab name.

06:02.910 --> 06:04.710
Maybe I want to grab email now.

06:04.710 --> 06:04.980
Yes.

06:04.980 --> 06:09.480
I'm not a big fan of this syntax that you have to pass on the properties separated from the space.

06:09.480 --> 06:12.720
This should be comma or something else, or at least an array.

06:12.960 --> 06:14.130
But this is how it works.

06:14.130 --> 06:17.220
Now, if I go ahead and save this one, you are going to see that.

06:17.220 --> 06:19.260
Let's go ahead and make the same request again.

06:19.260 --> 06:22.590
I send it up and now if I go ahead and check this one.

06:22.590 --> 06:28.830
So notice here, this user field is now expanded and this is now coming up as a name and email.

06:28.860 --> 06:31.050
Now, I'll tell you very interesting stuff about this.

06:31.050 --> 06:33.120
This populate is really, really the simplest feel.

06:33.120 --> 06:37.500
It just allows you to drill down further, expand if you want to get more of the information, maybe

06:37.500 --> 06:40.740
role of the user even you just have to say space and a role.

06:40.740 --> 06:41.340
That's it.

06:41.430 --> 06:46.290
Now in one of my course, earlier course, I asked the user that, hey, go read the documentation of

06:46.290 --> 06:48.420
populate and just let me know how it works.

06:48.420 --> 06:53.580
And to your surprise, a lot of people, more than ten people reached out to me and say that, hey,

06:53.580 --> 06:57.300
you should make a video of the on the populate we are not able to understand.

06:57.300 --> 06:59.250
Let me break it to you very clearly.

06:59.250 --> 07:02.310
I am not able to explain everything in the course.

07:02.310 --> 07:07.320
There is no chance that in any course in the world that you will get all the information sometimes you

07:07.320 --> 07:08.130
need to work.

07:08.130 --> 07:10.500
This is something that the habit should be there.

07:10.500 --> 07:14.430
And most of the international universities, when lecturers and professors give you the assignment,

07:14.430 --> 07:15.840
they don't give you the spoon feeding.

07:15.840 --> 07:19.470
They gives you something which you have to dig up and you have to find it on your own.

07:19.470 --> 07:23.130
These are not assignments that you have to just see the book and write down on the notebook.

07:23.130 --> 07:26.790
This is not how it works, so expect such things from my courses as well.

07:26.820 --> 07:30.420
I will push you towards your limit that you should also explore a little bit.

07:30.420 --> 07:34.830
Learn to read the documentation and there are still so many of the hidden things that you can explore

07:34.830 --> 07:35.850
further down the road.

07:35.850 --> 07:41.400
So really interesting stuff and populate is that's it there is nothing more more into this to explore

07:41.400 --> 07:42.420
further down the road.

07:42.420 --> 07:43.740
So that's it for this one.

07:43.740 --> 07:45.690
Let's go ahead and catch up in the next one.
