WEBVTT

00:03.730 --> 00:05.170
Hey, did everyone that they share?

00:05.170 --> 00:09.940
And in this video we're going to work through with how you can work on with the single user.

00:09.940 --> 00:11.260
So imagine something like this.

00:11.260 --> 00:14.410
You are having an admin panel, you are getting a nice, beautiful table.

00:14.410 --> 00:19.180
And in this table you are getting all the list of the users you obviously want to click on one of them.

00:19.180 --> 00:22.090
I want to get all the details about that particular user.

00:22.090 --> 00:26.410
So we are going to define a route for that, which is going to be this one slash admin, slash user

00:26.410 --> 00:27.400
slash ID.

00:27.430 --> 00:33.010
So as soon as it clicks on one particular ID, we will be extracting that ID from the URL itself and

00:33.010 --> 00:34.150
we'll be working on that.

00:34.360 --> 00:36.850
So pretty simple, not really complicated.

00:36.850 --> 00:38.620
So let's go ahead and work on with that.

00:38.620 --> 00:44.350
So I'll just keep this manager at the bottom because this was not actually the part of the flow.

00:44.350 --> 00:46.390
This is just to explain you some of the stuff.

00:46.390 --> 00:48.970
So I'm going to go ahead and copy this one up here.

00:48.970 --> 00:49.810
There we go.

00:49.810 --> 00:50.770
Nice and easy.

00:50.770 --> 00:55.750
And this time I'll say that this is admin admin.

00:55.810 --> 00:59.740
Get one user or get single user however you like to call this one.

00:59.740 --> 01:04.180
So how we are going to work on with this first, I'm going to just remove everything.

01:04.180 --> 01:06.550
It actually clears up a little bit of my brain.

01:06.790 --> 01:12.160
I want to extract single user, so I need to extract the ID from the URL.

01:12.190 --> 01:13.600
How can I go ahead and do that?

01:13.600 --> 01:21.220
I can go ahead and say request dot params dot ID because I'm extracting this from the URL itself.

01:21.730 --> 01:23.170
So this is how I grab it.

01:23.170 --> 01:29.860
How can I extract a single user from the database based on this ID, I can go ahead and simply say user

01:30.160 --> 01:31.060
dot.

01:31.960 --> 01:34.480
A find by ID is great.

01:34.480 --> 01:35.620
Thank you for suggesting.

01:35.620 --> 01:36.460
And there we go.

01:36.460 --> 01:37.720
We can pass on this one.

01:37.720 --> 01:39.670
Now I want to hold this into a variable.

01:39.670 --> 01:47.140
So I'm going to go ahead and say user and this is databases on you get the idea okay so this is all

01:47.140 --> 01:47.350
good.

01:47.350 --> 01:49.210
Now I have that particular user.

01:49.300 --> 01:52.060
All I have to say is just send this user.

01:52.060 --> 01:58.150
So I'm going to go ahead and say rez dot status and in this case I'm going to raise a status of 200

01:58.150 --> 02:01.990
and will pass on a JSON response just like this.

02:01.990 --> 02:05.800
And of course, success is going to be true.

02:06.010 --> 02:09.460
And we are also going to go ahead and say, send this user.

02:09.460 --> 02:15.580
Now, what if we are not able to extract any user from this params ID or the URL ID?

02:15.610 --> 02:17.410
Then let's go ahead and put up a symbol.

02:17.410 --> 02:23.020
If an LS statement that if there is no user, then go ahead and raise an exception here.

02:23.020 --> 02:27.880
So let's wrap it up in the next and raise a new custom matter.

02:27.880 --> 02:30.850
Although we are not using it much, I need to check it out again.

02:31.000 --> 02:40.960
So customer error will say no user found and we are going to go ahead and raise a simple 401 or 400.

02:41.290 --> 02:42.940
I think 400 is fine.

02:43.240 --> 02:44.470
Yeah, 400 is fine.

02:44.470 --> 02:44.940
Okay.

02:45.370 --> 02:49.570
So this is all what we got now let's go ahead and say admin, get one user.

02:49.570 --> 02:52.360
I'm going to go ahead and yeah, all lowercase is fine.

02:52.510 --> 02:55.510
Now let's go ahead and work on with the route that we want to give.

02:55.510 --> 02:57.280
So I'm going to go into user root.

02:57.280 --> 03:00.040
We can actually go ahead and make a duplicate of this one.

03:00.040 --> 03:03.940
So slash admin, slash user, slash colon ID.

03:03.970 --> 03:09.370
As soon as you make it a colon an ID, then I will be able to extract this into my controller with the

03:09.370 --> 03:10.450
name of ID.

03:10.540 --> 03:11.290
Nice and easy.

03:11.290 --> 03:12.940
Already talked too much on that one.

03:13.120 --> 03:14.350
This is going to be simple.

03:14.350 --> 03:17.140
Get request in which you should be logged in.

03:17.140 --> 03:21.670
Your role should be admin and the method that you will be controlling is admin.

03:21.670 --> 03:22.540
Get one user.

03:22.540 --> 03:23.770
So I need to bring that in.

03:23.770 --> 03:25.450
So let's go ahead and bring that.

03:25.450 --> 03:28.660
So now admin is able to bring in one user.

03:28.660 --> 03:30.660
So this is this is the root.

03:31.240 --> 03:32.200
Okay, nice and easy.

03:32.200 --> 03:35.710
Now it's time to test that also so that I can get information.

03:35.710 --> 03:37.300
So I'm logged in as an admin.

03:37.570 --> 03:41.770
Let's go ahead and quickly log out and I want to log in as an admin.

03:42.160 --> 03:46.120
So let's go ahead and say that I want to log in as an admin, which is two.

03:46.810 --> 03:52.720
So to add AES, send that and let's check in the body that my admin.

03:52.960 --> 03:53.430
Yep.

03:53.440 --> 03:54.250
Role is admin.

03:54.250 --> 03:56.890
Let's go ahead and check on to different roles.

03:57.460 --> 04:04.810
Save as and this is manager one user.

04:06.540 --> 04:14.070
Save that and the URL is slash admin slash user slash.

04:14.070 --> 04:17.550
Then I need to provide one particular user ID in this case.

04:17.550 --> 04:22.830
So luckily I have so many of these user ids in case you don't have any, then go ahead and grab it from

04:22.830 --> 04:24.630
the campus or whatever you like.

04:24.870 --> 04:30.810
I would like to grab the detail of this one itself, so I'm going to go ahead and copy this and I'll

04:30.810 --> 04:36.360
paste it up here at the top, make sure there is no space or anything because anything else inside the

04:36.510 --> 04:38.160
URL is going to just make a mess.

04:38.160 --> 04:40.050
So make sure you are extra cautious on that.

04:40.050 --> 04:41.640
Let's go ahead and send this one.

04:41.640 --> 04:47.460
And now successfully, we are able to grab the details of one user and let's try another one.

04:47.460 --> 04:51.690
Let's go ahead and say, hey, I'm an admin so I can actually grab all the user itself.

04:51.930 --> 04:54.090
Let's go ahead and somebody who is manager.

04:54.750 --> 04:56.250
So this is a user.

04:56.250 --> 04:58.260
This is a manager, so please manage it.

04:58.260 --> 05:04.830
Give me your ID, let's copy this and I can extract paste that in that.

05:04.830 --> 05:05.530
And there we go.

05:05.550 --> 05:07.890
Now we are able to extract the manager and everybody.

05:07.950 --> 05:12.420
Okay, so that sounds cool that we are able to extract one particular user in the next one.

05:12.420 --> 05:17.370
We need to provide this admin a functionality to change the name, email and even the role of any user.

05:17.370 --> 05:21.300
Maybe you want to send a role of manager, admin, sales, whatever he likes to have.

05:21.330 --> 05:23.340
Let's go ahead and catch up in the next video.
