WEBVTT

00:01.920 --> 00:02.450
Okay.

00:02.460 --> 00:06.080
We have our own method here rate movie.

00:06.090 --> 00:09.360
So let's work a little bit more on this method now.

00:09.360 --> 00:17.040
So what we first need to do is we need to get some data for that rating.

00:17.040 --> 00:22.080
So we need to check if something has been passed in the request.

00:22.080 --> 00:26.460
So let's say if we we required a stars, for example.

00:26.460 --> 00:29.010
So if stars.

00:31.300 --> 00:37.480
In request data, then we can do this.

00:39.990 --> 00:44.520
And so we can output that only when we start in request data.

00:44.520 --> 00:50.250
And then else I can do, for example.

00:51.770 --> 00:53.030
Something like this.

00:53.030 --> 00:54.860
So I will have message.

00:56.870 --> 01:10.940
You need to provide stars like that and then status will be Http and then we can use something like

01:10.940 --> 01:12.830
a bad request here.

01:13.820 --> 01:17.420
So what I'm doing now, I will make more space here.

01:18.500 --> 01:24.770
So what I'm doing now is I'm checking if you have stars in the request data and I will show you what

01:24.770 --> 01:26.330
does it exactly mean.

01:26.330 --> 01:32.450
And then if you don't have it, then we'll put you need to provide stars with a bad request.

01:32.450 --> 01:34.070
If you have it, then it will be.

01:34.070 --> 01:34.640
It's working.

01:34.640 --> 01:35.990
So let's test it now.

01:36.350 --> 01:37.820
I will run it again.

01:39.740 --> 01:45.350
And come back to our postman and let's try to do the same method as we've done before.

01:45.830 --> 01:51.860
And you can see here message you need to provide stars and why we are seeing this.

01:52.490 --> 02:05.910
We set here if stars in request data request data is that body that we will send along with our request.

02:05.930 --> 02:10.260
So basically we need to provide stars like that.

02:10.280 --> 02:20.630
So at this point we don't validate this stars anyhow, so we can do whatever here.

02:22.850 --> 02:23.360
Whatever.

02:25.610 --> 02:28.970
Whatever here.

02:28.970 --> 02:34.290
And if I will now send it, you can see the message is working.

02:34.310 --> 02:40.340
The reason we see this message is because we passed the stars to our.

02:40.730 --> 02:43.370
So it's a part of the request data.

02:43.370 --> 02:50.200
So stars now are in the request data so we can output this.

02:50.210 --> 02:58.100
So basically you can see that how we can construct the logic inside our functions so we can decide what

02:58.100 --> 03:04.400
needs to be in the request data and then prohibit user to do something if it's not there.

03:04.400 --> 03:13.310
And also we can have another checks and logic so we can decide if the start is integer, if it's actually

03:13.670 --> 03:16.400
in between 1 and 5 and so on and so on.

03:16.400 --> 03:19.910
So everything can be validated here.

03:19.910 --> 03:25.470
We can do a lot of things with the data, but I will also show you another thing.

03:25.470 --> 03:31.980
So we will have our logic here, but I will try to print something, whatever we will try to use.

03:31.980 --> 03:38.310
You can see here, when we run the server, everything, what we ask the server, it's printed here,

03:38.310 --> 03:43.020
but we can send our own information to that console, to that terminal.

03:43.020 --> 03:44.700
So let's do it now.

03:44.700 --> 03:48.540
So I will do print and let's try to print that.

03:50.800 --> 03:51.550
Here.

03:51.850 --> 03:57.700
If I will print it now, I will go back to the postman and send it once again.

03:58.180 --> 03:59.530
You can see it's working.

03:59.530 --> 04:00.580
Nothing has been changed.

04:00.580 --> 04:01.590
It's 200.

04:01.600 --> 04:05.980
But if I come back here, you can see here that's printed one.

04:05.980 --> 04:09.940
It's the ID that has been passed with this method.

04:09.940 --> 04:14.890
So if I will come back here and remove it from there like that.

04:16.450 --> 04:18.400
It's not working.

04:18.400 --> 04:26.170
So that means this rate movie is, as I said before, it's only working for that specific movie.

04:26.170 --> 04:27.520
So it will be movie one.

04:27.520 --> 04:32.650
That's movie one, and then we will have an access to our pcq-pcc.

04:32.680 --> 04:33.640
It's a primary key.

04:33.850 --> 04:36.460
So basically that's our ID of the movie.

04:36.460 --> 04:41.560
So what we can do is we can select that movie from our database.

04:41.560 --> 04:45.460
So we said movie and then we can do movie.

04:47.650 --> 04:48.520
Objects.

04:51.840 --> 04:54.300
And then we can use get.

04:55.200 --> 05:05.520
So we will try to get the movie based on the PK so we know what is the primary key from that request

05:05.520 --> 05:08.850
because it's part of the URL, and then we select the movie.

05:08.850 --> 05:13.530
So what we have here is we'll have an access to that specific movie.

05:13.530 --> 05:15.750
So let's try to print something.

05:15.750 --> 05:21.180
Now I will print movie title that's just a static text.

05:21.180 --> 05:26.370
And here as a second argument, I will pass movie and then title like that.

05:26.370 --> 05:30.060
So we are selecting our movie from the database.

05:30.060 --> 05:37.560
Movie objects get based on the primary key, which is ID from the URL and then we will print the movie

05:37.590 --> 05:38.310
title.

05:39.210 --> 05:41.310
So let's come back here.

05:41.310 --> 05:42.420
That's been refreshed.

05:43.930 --> 05:46.360
Postman and I will send it again.

05:46.690 --> 05:47.440
This is.

05:47.440 --> 05:48.310
It's working.

05:48.310 --> 05:50.200
So we need to go here.

05:50.200 --> 05:53.230
And you can see here movie title Titanic.

05:53.380 --> 05:55.390
So this is printed.

05:55.660 --> 06:01.360
This is printed here because I have movie title and then movie title here, which is the ID.

06:02.400 --> 06:03.180
One.

06:03.180 --> 06:11.040
So if I will come back here and if I will change this to two to our second movie and send it again.

06:12.440 --> 06:13.280
In our.

06:14.810 --> 06:17.780
Control half movie title Avatar.

06:17.870 --> 06:26.030
So you can see how we can actually select something from our database and how we can manage this.

06:26.030 --> 06:34.010
So we have access to our stars now so we know what is the stars and how the stars will be passed.

06:34.010 --> 06:39.140
With the request data, we will check that first and otherwise you need to provide a stars.

06:39.140 --> 06:40.460
That's what we output.

06:40.700 --> 06:46.610
Next thing we check, what is the movie actual that we target?

06:46.610 --> 06:49.520
So we we have access to this movie.

06:49.550 --> 06:51.200
What else we can do?

06:51.230 --> 07:00.290
We need to also get the user data and I will show you how we can actually access the user data from

07:00.290 --> 07:05.240
the request in the next movie and we will finish that function.
