Hey, did everyone that they share?
And in this video we're going to work through with how you can work on with the single user.
So imagine something like this.
You are having an admin panel, you are getting a nice, beautiful table.
And in this table you are getting all the list of the users you obviously want to click on one of them.
I want to get all the details about that particular user.
So we are going to define a route for that, which is going to be this one slash admin, slash user
slash ID.
So as soon as it clicks on one particular ID, we will be extracting that ID from the URL itself and
we'll be working on that.
So pretty simple, not really complicated.
So let's go ahead and work on with that.
So I'll just keep this manager at the bottom because this was not actually the part of the flow.
This is just to explain you some of the stuff.
So I'm going to go ahead and copy this one up here.
There we go.
Nice and easy.
And this time I'll say that this is admin admin.
Get one user or get single user however you like to call this one.
So how we are going to work on with this first, I'm going to just remove everything.
It actually clears up a little bit of my brain.
I want to extract single user, so I need to extract the ID from the URL.
How can I go ahead and do that?
I can go ahead and say request dot params dot ID because I'm extracting this from the URL itself.
So this is how I grab it.
How can I extract a single user from the database based on this ID, I can go ahead and simply say user
dot.
A find by ID is great.
Thank you for suggesting.
And there we go.
We can pass on this one.
Now I want to hold this into a variable.
So I'm going to go ahead and say user and this is databases on you get the idea okay so this is all
good.
Now I have that particular user.
All I have to say is just send this user.
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
and will pass on a JSON response just like this.
And of course, success is going to be true.
And we are also going to go ahead and say, send this user.
Now, what if we are not able to extract any user from this params ID or the URL ID?
Then let's go ahead and put up a symbol.
If an LS statement that if there is no user, then go ahead and raise an exception here.
So let's wrap it up in the next and raise a new custom matter.
Although we are not using it much, I need to check it out again.
So customer error will say no user found and we are going to go ahead and raise a simple 401 or 400.
I think 400 is fine.
Yeah, 400 is fine.
Okay.
So this is all what we got now let's go ahead and say admin, get one user.
I'm going to go ahead and yeah, all lowercase is fine.
Now let's go ahead and work on with the route that we want to give.
So I'm going to go into user root.
We can actually go ahead and make a duplicate of this one.
So slash admin, slash user, slash colon ID.
As soon as you make it a colon an ID, then I will be able to extract this into my controller with the
name of ID.
Nice and easy.
Already talked too much on that one.
This is going to be simple.
Get request in which you should be logged in.
Your role should be admin and the method that you will be controlling is admin.
Get one user.
So I need to bring that in.
So let's go ahead and bring that.
So now admin is able to bring in one user.
So this is this is the root.
Okay, nice and easy.
Now it's time to test that also so that I can get information.
So I'm logged in as an admin.
Let's go ahead and quickly log out and I want to log in as an admin.
So let's go ahead and say that I want to log in as an admin, which is two.
So to add AES, send that and let's check in the body that my admin.
Yep.
Role is admin.
Let's go ahead and check on to different roles.
Save as and this is manager one user.
Save that and the URL is slash admin slash user slash.
Then I need to provide one particular user ID in this case.
So luckily I have so many of these user ids in case you don't have any, then go ahead and grab it from
the campus or whatever you like.
I would like to grab the detail of this one itself, so I'm going to go ahead and copy this and I'll
paste it up here at the top, make sure there is no space or anything because anything else inside the
URL is going to just make a mess.
So make sure you are extra cautious on that.
Let's go ahead and send this one.
And now successfully, we are able to grab the details of one user and let's try another one.
Let's go ahead and say, hey, I'm an admin so I can actually grab all the user itself.
Let's go ahead and somebody who is manager.
So this is a user.
This is a manager, so please manage it.
Give me your ID, let's copy this and I can extract paste that in that.
And there we go.
Now we are able to extract the manager and everybody.
Okay, so that sounds cool that we are able to extract one particular user in the next one.
We need to provide this admin a functionality to change the name, email and even the role of any user.
Maybe you want to send a role of manager, admin, sales, whatever he likes to have.
Let's go ahead and catch up in the next video.