Heart, everyone.
In this video, let's create a service for Mac Send request.
Okay, so right now let me build up inside the frame service.
Inside the create method.
Okay.
Let me we can change the name into the send friend request.
But I think I will give it will be the create right here.
Well we need to put the some parameter.
The first will be current user okay.
And the second one will be the receivers.
Uh, Eddie?
Right.
Uh, this is the.
Let me say the sender.
The sender is the current user.
And receiver will be, uh, will be stuck right here.
Let me and let me show you how it can be passed then on the controller.
In here, we have a create method.
Right.
I will change the name of the method a little bit.
We will send.
Write request.
Okay.
Send friend request.
And we don't need any detail right now with a current user.
And now we need the one more param.
We will.
Receive our array.
Over here.
Right.
And right here.
We need to make sure this is a valid.
Object array.
Okay.
And we need to change the URL a bit.
Firstly let's change the controller into the frames.
And what it will have a URL like this frame slash
Or.
And.
This is okay.
This will be something like that.
So for this guy I will put a request and slot receiver array.
Okay.
Something like that.
And inside the create method let write logic okay.
Let me say firstly we want to store the receiver user okay.
In the prevent send a.
Request to yourself.
And prevent duplicate.
The same way.
The same rate.
Okay.
We will talk about us.
Right?
We want to make sure is a useful asset.
We need to ensure that our user service.
Right.
We need to inject us.
Uh, for a reason.
This guy is a different module.
We need to import.
The user module.
And activities that a user module we already explored.
Okay.
And after that go back to the here And let me copy something.
Inside the reaction reactions of it.
Let me copy some constructor because I'm.
I'm not memorized us.
Right.
Request.
One.
Request.
Model.
Right.
Request.
Okay.
And we need to inject the users.
Sorry.
Okay.
And let me find.
User submitted file one and would receive it over here.
Now let's let's say instead of file one right here.
We already checked right here.
Right.
So we we don't need to check over here also.
Let's see.
And we need to prevent send request to yourself.
So what I will do it if the current user.id equal with receiver ID over here we will throw new request
exception.
Cannot send a
Run.
Request to your.
Staff.
Over here.
Right here.
We can take a look at the receiver.
Right here.
Or receiver over here.
Okay.
Dot.
toString.
It's totally the same.
And after we reach out over here, we need to prevent the duplicate.
Okay.
So for that we will find the existing.
Uh, write.
Request.
Okay.
We need to find existing friend request this dot request.
Model the file one.
Right.
We need to find the.
Sender.
We will call the user.
Oh, sorry.
Now let's go and receiver.
And ask.
Okay.
If we already have an existing request we need to throw the error.
So.
The send request.
Already said.
Something like that.
And after we are done with this thing we did so quickly.
That's right.
Now we need to move some stuff over here.
But as.
You.
Progress over until the last and after we already have a friend request we to return friend request
not save.
Okay, so that's for the friend request over here.
Let me test that.
Okay, now I will duplicate entire authentication.
Hello.
And change the folder to friend.
Move it over here and change it to send friend request.
And delete the sign over here.
And let me say.
I will log in with this account.
And, uh.
Right here, right here.
You can say when I sign, I will go to this type.
Right.
And, uh, request.
And receive.
Right.
Here.
And what is the receiver ID?
Let let me slide over here.
When we find one we already checked its update will be true, right?
So for that reason, in this case we go back to the database, go back to the users.
Okay.
And let change is active right here.
So true.
Okay.
But what about if I not uh, Gentle Joe, let's say if I send right here, we don't have anybody.
Right.
Let's say user does not exist, right?
So for that reason, from here, I will check back to Joe's and update.
Okay.
After us, let's make let's say we have our internal server error.
Let me double check.
Cannot read property Only provide a current user.
Okay.
The reason?
Because I forgot this authentication rule.
Okay.
So in order to use the current user Maxwell, we use your first.
Last May set.
However here we already set which sender receiver and some state dot over here.
Okay.
So with the pending let me double check the friend request.
Okay.
So it already, uh, work.
And I think that will be enough for the video.
And I will see you in the next one.