Okay.
We have our own method here rate movie.
So let's work a little bit more on this method now.
So what we first need to do is we need to get some data for that rating.
So we need to check if something has been passed in the request.
So let's say if we we required a stars, for example.
So if stars.
In request data, then we can do this.
And so we can output that only when we start in request data.
And then else I can do, for example.
Something like this.
So I will have message.
You need to provide stars like that and then status will be Http and then we can use something like
a bad request here.
So what I'm doing now, I will make more space here.
So what I'm doing now is I'm checking if you have stars in the request data and I will show you what
does it exactly mean.
And then if you don't have it, then we'll put you need to provide stars with a bad request.
If you have it, then it will be.
It's working.
So let's test it now.
I will run it again.
And come back to our postman and let's try to do the same method as we've done before.
And you can see here message you need to provide stars and why we are seeing this.
We set here if stars in request data request data is that body that we will send along with our request.
So basically we need to provide stars like that.
So at this point we don't validate this stars anyhow, so we can do whatever here.
Whatever.
Whatever here.
And if I will now send it, you can see the message is working.
The reason we see this message is because we passed the stars to our.
So it's a part of the request data.
So stars now are in the request data so we can output this.
So basically you can see that how we can construct the logic inside our functions so we can decide what
needs to be in the request data and then prohibit user to do something if it's not there.
And also we can have another checks and logic so we can decide if the start is integer, if it's actually
in between 1 and 5 and so on and so on.
So everything can be validated here.
We can do a lot of things with the data, but I will also show you another thing.
So we will have our logic here, but I will try to print something, whatever we will try to use.
You can see here, when we run the server, everything, what we ask the server, it's printed here,
but we can send our own information to that console, to that terminal.
So let's do it now.
So I will do print and let's try to print that.
Here.
If I will print it now, I will go back to the postman and send it once again.
You can see it's working.
Nothing has been changed.
It's 200.
But if I come back here, you can see here that's printed one.
It's the ID that has been passed with this method.
So if I will come back here and remove it from there like that.
It's not working.
So that means this rate movie is, as I said before, it's only working for that specific movie.
So it will be movie one.
That's movie one, and then we will have an access to our pcq-pcc.
It's a primary key.
So basically that's our ID of the movie.
So what we can do is we can select that movie from our database.
So we said movie and then we can do movie.
Objects.
And then we can use get.
So we will try to get the movie based on the PK so we know what is the primary key from that request
because it's part of the URL, and then we select the movie.
So what we have here is we'll have an access to that specific movie.
So let's try to print something.
Now I will print movie title that's just a static text.
And here as a second argument, I will pass movie and then title like that.
So we are selecting our movie from the database.
Movie objects get based on the primary key, which is ID from the URL and then we will print the movie
title.
So let's come back here.
That's been refreshed.
Postman and I will send it again.
This is.
It's working.
So we need to go here.
And you can see here movie title Titanic.
So this is printed.
This is printed here because I have movie title and then movie title here, which is the ID.
One.
So if I will come back here and if I will change this to two to our second movie and send it again.
In our.
Control half movie title Avatar.
So you can see how we can actually select something from our database and how we can manage this.
So we have access to our stars now so we know what is the stars and how the stars will be passed.
With the request data, we will check that first and otherwise you need to provide a stars.
That's what we output.
Next thing we check, what is the movie actual that we target?
So we we have access to this movie.
What else we can do?
We need to also get the user data and I will show you how we can actually access the user data from
the request in the next movie and we will finish that function.