WEBVTT

00:03.790 --> 00:05.320
Hey there, everyone that they share.

00:05.320 --> 00:10.180
And from the last video, I remember that I haven't got you into this trouble situation for a long while.

00:10.180 --> 00:14.350
So in this video, we're going to deliberately go into some trouble and we'll see that where the problems

00:14.350 --> 00:14.500
are.

00:14.500 --> 00:17.530
So this is going to be a fun situation and you're going to enjoy this one.

00:17.650 --> 00:23.320
The goal of this, this particular video is simply to grab all the orders by the user who is logged

00:23.320 --> 00:23.470
in.

00:23.470 --> 00:26.740
So basically if I'm logged in, I should be able to find all of my orders.

00:26.740 --> 00:27.610
That's pretty much it.

00:27.610 --> 00:29.590
Let's go ahead and break it down to you.

00:29.770 --> 00:32.290
So let's go ahead and make a copy of this one.

00:33.460 --> 00:35.500
Zip it up and expand this one.

00:35.500 --> 00:36.190
There we go.

00:36.760 --> 00:43.000
And this one is get one order and this is get logged in user order.

00:43.000 --> 00:48.190
So we're going to say get logged in orders.

00:48.970 --> 00:49.720
Orders.

00:49.720 --> 00:50.410
There we go.

00:50.590 --> 00:54.460
So this is the basic and we are going to keep this one as it is now.

00:54.460 --> 00:57.130
All we got to do is how we are going to find this.

00:57.130 --> 01:00.190
Previously this was coming up as the requested parameter ID.

01:00.220 --> 01:02.860
So let's evaluate that how this is going to happen.

01:02.860 --> 01:05.290
Let's go ahead and check it out into the base itself.

01:05.290 --> 01:09.880
So this is my order data and I do have a ability to find out who is logged in.

01:09.880 --> 01:14.680
I can just go ahead and say request dot, user dot, underscore ID and do we have any field which can

01:14.680 --> 01:15.460
actually do this?

01:15.460 --> 01:18.490
Yes, we have a field we can actually filter based on the user.

01:18.490 --> 01:23.950
So if my request dot user dot underscore ID matches with this user, I can easily go ahead and select

01:23.950 --> 01:25.420
only those particular user.

01:25.450 --> 01:30.190
We saw that while designing the manager field that we can find anything based on particular these fields.

01:30.190 --> 01:32.050
So let's go ahead and extract that.

01:32.050 --> 01:36.070
So let's go ahead and say that, hey, I want to go ahead and this time not find my ID.

01:36.070 --> 01:39.640
I just want to go ahead and use find method in the fine method.

01:39.640 --> 01:41.830
I have to say that how do you want to find the user?

01:41.830 --> 01:45.070
So I'll pass you a kind of a wade clause in this.

01:45.070 --> 01:50.560
I'm going to go ahead and say, hey user, how you're going to get the user request a dot user, which

01:50.560 --> 01:51.340
is our middleware.

01:51.340 --> 01:54.250
And in that dot underscore ID, that's pretty much it.

01:54.670 --> 01:55.060
Yeah.

01:55.060 --> 01:56.770
Request dot user dot underscore ID.

01:56.770 --> 01:57.520
So let's go ahead.

01:57.520 --> 02:01.240
And we don't need to populate this field, so let's go ahead and remove this one.

02:01.540 --> 02:06.550
And we're going to say if there is no order, please check the order ID, we'll test this out and we're

02:06.550 --> 02:08.290
going to go ahead and send this one.

02:09.010 --> 02:09.160
Okay.

02:09.340 --> 02:11.950
So it looks okay to me now.

02:11.950 --> 02:16.150
Let's go ahead and create a root and let's create some of the problems and issues for our cell.

02:16.150 --> 02:17.560
Let's go ahead and copy this one.

02:17.950 --> 02:20.620
And this one will go up here just like that.

02:20.620 --> 02:24.790
And now we have to simply say that, hey, whoever is logged in, we should actually get that.

02:24.790 --> 02:30.700
So I'm going to go ahead and say, hey, let's go ahead and say simply order, slash my order.

02:30.700 --> 02:35.170
And this field, obviously, he should be logged in and we are going to go ahead and use this one.

02:35.170 --> 02:37.450
Let's go ahead and save this one and test out that order.

02:37.450 --> 02:38.650
Slash my order.

02:38.710 --> 02:40.570
Does it work or not?

02:40.600 --> 02:43.360
Let's go ahead and save this one.

02:43.600 --> 02:45.910
And this one will go into order.

02:46.090 --> 02:51.700
And I'm going to call this one as get my order and save this one.

02:51.700 --> 02:52.930
So what was the root?

02:52.930 --> 02:57.700
It was slash order, slash my order and a simple get request.

02:58.150 --> 03:01.480
And we haven't actually told that how you're going to get.

03:01.690 --> 03:03.040
We don't need to say any ID.

03:03.370 --> 03:04.060
My bad.

03:04.270 --> 03:10.180
Just for thinking ahead of myself again, let's go ahead and say that this is the root again.

03:12.510 --> 03:13.050
There we go.

03:13.050 --> 03:13.800
Slash order.

03:13.800 --> 03:14.810
Slash my order.

03:14.820 --> 03:16.350
Let's go ahead and send this one.

03:16.350 --> 03:21.030
And we are receiving a simple error that says, hey, cost to object ID failed for the value.

03:21.030 --> 03:22.620
And this is a really classic error.

03:22.620 --> 03:24.360
You're going to see this quite a number of times.

03:24.360 --> 03:26.160
Let me break it to you directly now.

03:26.160 --> 03:26.970
What is happening?

03:26.970 --> 03:30.360
The order of the routes actually matters a lot in this case.

03:30.360 --> 03:32.640
We are saying slash order, slash create.

03:32.640 --> 03:34.800
So that is being handled first.

03:34.830 --> 03:37.290
After that, we say it's slash order slash ID.

03:37.320 --> 03:42.180
So no matter what you say after that or how many doubts you declare after that, it's always going to

03:42.180 --> 03:43.530
evaluate this route first.

03:43.530 --> 03:48.360
So after slash order, it always expected that, hey, you are going to give me an ID and it is teetering

03:48.360 --> 03:49.740
my order as an ID as well.

03:49.740 --> 03:51.150
And that's why it's giving a problem.

03:51.150 --> 03:52.440
This is a very common error.

03:52.470 --> 03:55.740
I've seen a lot of beginners actually do this and this is totally okay.

03:55.740 --> 04:01.530
So what you can do this is you can actually say simply, since this is a simple get request, you can

04:01.530 --> 04:06.540
just go ahead and say, hey, this is a route which says simply my order and this is all going to be

04:06.540 --> 04:07.200
all fine.

04:07.200 --> 04:11.160
In fact, you can go ahead and say simply like orders or get order or something like this.

04:11.160 --> 04:13.950
If I just go ahead and say my order, this is going to fix this one.

04:13.950 --> 04:18.000
So, yes, the designing the route itself takes sometimes a little bit of an effort.

04:18.000 --> 04:22.800
So let's go ahead and simply say my order and let's go ahead and send this one.

04:22.800 --> 04:27.690
And now you are getting the users, whoever the user who is logged in, actually getting all the orders

04:27.690 --> 04:28.020
up here.

04:28.020 --> 04:29.220
So pretty nice and easy.

04:29.220 --> 04:32.760
And you have learned one more thing, which is about how to arrange these orders.

04:32.760 --> 04:36.660
So remember, either expect this order ID at the very end.

04:36.660 --> 04:41.070
So whatever the what are the routes you are expecting, the ID plays them at the very end.

04:41.070 --> 04:42.900
So all the above things are evaluated.

04:42.900 --> 04:46.620
But if you are passing up some IDs or something like this, be very cautious on that.

04:46.620 --> 04:48.870
This is a very classic error, happens quite a lot.

04:48.900 --> 04:50.850
Let's go ahead and catch up in the next video.
