WEBVTT

00:00.720 --> 00:02.480
Heart, everyone.

00:02.920 --> 00:11.760
In this video, let's create a service for Mac Send request.

00:11.800 --> 00:19.240
Okay, so right now let me build up inside the frame service.

00:21.880 --> 00:23.880
Inside the create method.

00:24.440 --> 00:25.000
Okay.

00:26.880 --> 00:35.640
Let me we can change the name into the send friend request.

00:35.640 --> 00:39.760
But I think I will give it will be the create right here.

00:41.920 --> 00:45.280
Well we need to put the some parameter.

00:47.120 --> 00:51.960
The first will be current user okay.

01:00.530 --> 01:03.610
And the second one will be the receivers.

01:04.290 --> 01:05.690
Uh, Eddie?

01:05.930 --> 01:06.410
Right.

01:08.610 --> 01:11.050
Uh, this is the.

01:13.210 --> 01:15.450
Let me say the sender.

01:15.930 --> 01:17.810
The sender is the current user.

01:18.130 --> 01:21.730
And receiver will be, uh, will be stuck right here.

01:24.330 --> 01:31.770
Let me and let me show you how it can be passed then on the controller.

01:32.050 --> 01:34.610
In here, we have a create method.

01:34.610 --> 01:35.090
Right.

01:35.650 --> 01:38.210
I will change the name of the method a little bit.

01:38.570 --> 01:39.490
We will send.

01:42.570 --> 01:44.970
Write request.

01:45.490 --> 01:45.970
Okay.

01:46.410 --> 01:48.570
Send friend request.

01:49.370 --> 01:54.010
And we don't need any detail right now with a current user.

02:04.470 --> 02:09.630
And now we need the one more param.

02:14.750 --> 02:15.350
We will.

02:17.510 --> 02:19.910
Receive our array.

02:23.270 --> 02:23.990
Over here.

02:24.630 --> 02:25.190
Right.

02:30.430 --> 02:31.190
And right here.

02:31.190 --> 02:34.270
We need to make sure this is a valid.

02:37.870 --> 02:38.830
Object array.

02:45.990 --> 02:46.510
Okay.

02:46.990 --> 02:50.310
And we need to change the URL a bit.

02:50.550 --> 02:54.030
Firstly let's change the controller into the frames.

02:54.590 --> 02:58.590
And what it will have a URL like this frame slash

03:05.000 --> 03:05.400
Or.

03:11.280 --> 03:11.840
And.

03:15.800 --> 03:17.680
This is okay.

03:18.200 --> 03:19.560
This will be something like that.

03:19.560 --> 03:26.480
So for this guy I will put a request and slot receiver array.

03:27.200 --> 03:27.680
Okay.

03:27.880 --> 03:28.960
Something like that.

03:33.160 --> 03:37.360
And inside the create method let write logic okay.

03:38.800 --> 03:46.680
Let me say firstly we want to store the receiver user okay.

03:49.360 --> 03:54.040
In the prevent send a.

03:56.720 --> 03:59.250
Request to yourself.

04:02.090 --> 04:06.090
And prevent duplicate.

04:07.290 --> 04:09.810
The same way.

04:10.490 --> 04:11.530
The same rate.

04:12.050 --> 04:12.530
Okay.

04:13.130 --> 04:14.810
We will talk about us.

04:15.050 --> 04:15.490
Right?

04:17.530 --> 04:20.010
We want to make sure is a useful asset.

04:24.970 --> 04:28.730
We need to ensure that our user service.

04:28.770 --> 04:29.250
Right.

04:29.770 --> 04:30.970
We need to inject us.

04:33.370 --> 04:34.410
Uh, for a reason.

04:34.530 --> 04:37.010
This guy is a different module.

04:37.730 --> 04:39.130
We need to import.

04:42.090 --> 04:44.530
The user module.

04:46.570 --> 04:50.730
And activities that a user module we already explored.

04:51.010 --> 04:51.490
Okay.

04:53.010 --> 05:01.070
And after that go back to the here And let me copy something.

05:03.310 --> 05:09.150
Inside the reaction reactions of it.

05:10.710 --> 05:17.190
Let me copy some constructor because I'm.

05:17.390 --> 05:19.030
I'm not memorized us.

05:21.750 --> 05:22.270
Right.

05:22.470 --> 05:23.230
Request.

05:27.350 --> 05:27.870
One.

05:27.910 --> 05:28.790
Request.

05:28.950 --> 05:29.550
Model.

05:38.590 --> 05:39.110
Right.

05:40.550 --> 05:41.310
Request.

05:52.110 --> 05:52.670
Okay.

05:53.310 --> 05:55.990
And we need to inject the users.

05:59.720 --> 06:00.360
Sorry.

06:05.200 --> 06:05.720
Okay.

06:06.680 --> 06:08.240
And let me find.

06:10.880 --> 06:15.760
User submitted file one and would receive it over here.

06:16.480 --> 06:18.800
Now let's let's say instead of file one right here.

06:18.800 --> 06:21.680
We already checked right here.

06:21.720 --> 06:22.240
Right.

06:22.520 --> 06:25.320
So we we don't need to check over here also.

06:27.560 --> 06:28.160
Let's see.

06:30.760 --> 06:34.640
And we need to prevent send request to yourself.

06:34.960 --> 06:49.680
So what I will do it if the current user.id equal with receiver ID over here we will throw new request

06:49.680 --> 06:50.360
exception.

06:52.440 --> 06:55.800
Cannot send a

06:59.300 --> 06:59.940
Run.

07:00.260 --> 07:03.060
Request to your.

07:06.700 --> 07:07.380
Staff.

07:09.820 --> 07:10.500
Over here.

07:12.180 --> 07:12.820
Right here.

07:12.820 --> 07:15.540
We can take a look at the receiver.

07:16.060 --> 07:16.780
Right here.

07:16.820 --> 07:19.100
Or receiver over here.

07:19.740 --> 07:20.300
Okay.

07:20.500 --> 07:20.780
Dot.

07:20.820 --> 07:21.900
toString.

07:22.180 --> 07:24.020
It's totally the same.

07:27.780 --> 07:32.980
And after we reach out over here, we need to prevent the duplicate.

07:34.540 --> 07:34.900
Okay.

07:34.940 --> 07:37.740
So for that we will find the existing.

07:39.380 --> 07:41.540
Uh, write.

07:44.180 --> 07:44.980
Request.

07:45.260 --> 07:45.660
Okay.

07:45.660 --> 07:53.780
We need to find existing friend request this dot request.

07:53.820 --> 07:55.700
Model the file one.

07:57.390 --> 07:57.910
Right.

07:59.870 --> 08:01.950
We need to find the.

08:05.030 --> 08:05.910
Sender.

08:06.670 --> 08:08.150
We will call the user.

08:09.790 --> 08:10.510
Oh, sorry.

08:13.230 --> 08:17.030
Now let's go and receiver.

08:22.510 --> 08:24.470
And ask.

08:26.590 --> 08:27.070
Okay.

08:27.350 --> 08:34.230
If we already have an existing request we need to throw the error.

08:34.270 --> 08:34.670
So.

08:45.750 --> 08:47.630
The send request.

08:50.910 --> 08:52.790
Already said.

08:54.830 --> 08:55.790
Something like that.

09:09.160 --> 09:15.720
And after we are done with this thing we did so quickly.

09:15.960 --> 09:16.720
That's right.

09:36.400 --> 09:39.080
Now we need to move some stuff over here.

09:39.680 --> 09:40.480
But as.

09:45.880 --> 09:46.400
You.

09:54.760 --> 10:06.500
Progress over until the last and after we already have a friend request we to return friend request

10:06.500 --> 10:07.300
not save.

10:07.860 --> 10:18.020
Okay, so that's for the friend request over here.

10:19.700 --> 10:20.900
Let me test that.

10:26.980 --> 10:32.300
Okay, now I will duplicate entire authentication.

10:36.100 --> 10:36.660
Hello.

10:37.900 --> 10:40.500
And change the folder to friend.

10:45.060 --> 10:53.660
Move it over here and change it to send friend request.

10:58.390 --> 11:00.910
And delete the sign over here.

11:02.630 --> 11:04.430
And let me say.

11:06.910 --> 11:08.950
I will log in with this account.

11:18.950 --> 11:19.870
And, uh.

11:22.670 --> 11:26.110
Right here, right here.

11:26.150 --> 11:35.190
You can say when I sign, I will go to this type.

11:36.470 --> 11:37.270
Right.

11:38.510 --> 11:40.830
And, uh, request.

11:43.230 --> 11:44.470
And receive.

11:44.950 --> 11:45.390
Right.

11:50.470 --> 11:50.830
Here.

11:51.150 --> 11:52.950
And what is the receiver ID?

11:53.870 --> 11:56.600
Let let me slide over here.

11:57.160 --> 12:01.360
When we find one we already checked its update will be true, right?

12:01.400 --> 12:06.960
So for that reason, in this case we go back to the database, go back to the users.

12:10.200 --> 12:10.800
Okay.

12:11.320 --> 12:13.760
And let change is active right here.

12:14.360 --> 12:15.640
So true.

12:16.320 --> 12:16.800
Okay.

12:17.160 --> 12:30.440
But what about if I not uh, Gentle Joe, let's say if I send right here, we don't have anybody.

12:30.480 --> 12:30.920
Right.

12:31.240 --> 12:34.720
Let's say user does not exist, right?

12:35.480 --> 12:40.320
So for that reason, from here, I will check back to Joe's and update.

12:43.720 --> 12:44.240
Okay.

12:44.440 --> 12:49.920
After us, let's make let's say we have our internal server error.

12:50.120 --> 12:51.600
Let me double check.

12:52.160 --> 12:59.380
Cannot read property Only provide a current user.

12:59.540 --> 13:00.100
Okay.

13:00.620 --> 13:01.180
The reason?

13:01.180 --> 13:06.620
Because I forgot this authentication rule.

13:07.260 --> 13:07.700
Okay.

13:07.980 --> 13:13.900
So in order to use the current user Maxwell, we use your first.

13:18.140 --> 13:19.940
Last May set.

13:21.460 --> 13:27.220
However here we already set which sender receiver and some state dot over here.

13:30.260 --> 13:30.740
Okay.

13:30.940 --> 13:36.860
So with the pending let me double check the friend request.

13:42.300 --> 13:42.820
Okay.

13:42.820 --> 13:46.740
So it already, uh, work.

13:48.140 --> 13:51.500
And I think that will be enough for the video.

13:51.980 --> 13:54.020
And I will see you in the next one.
