All right.
And once we're familiar with the fundamentals now, let's see how can yours skip on the limit to set
up deep education and not worry about the dollar jobs, as well as the number of pages?
And first, we need to understand that when it comes to page and limit, we can pass them in and we
will pass in the page from the front end.
But first, since they're both query string parameters, they will be treated as strings.
So first need to turn them into a number.
And we use good old JavaScript for that.
And second, we'll always have the default values.
So if the page is not provided, I'll say that the user is looking for the page number one.
Now that is the same default that we have on the frontend.
So that should be already familiar.
And the same goes with limit, where by default, I'll limit my response to 10 jobs per page.
Yes, if you want, you can set it up on the front and different value.
You can actually change that value so the user changes that power.
But in our case, we'll just stick with this then.
So while testing out in a postman, I'll show you how everything works.
But in general, from the front end, we won't pass the limit.
We'll just go with this default one, and the way we set up the functionality is like this.
Instead of hard coding skip, we go with whatever is the page minus one and nine times the limit.
So let's imagine that we have page number one.
So one minus one is going to be zero zero times, the limit is going to be what it's going to be zero.
So that's page number one shown here.
We'll pass in the zero.
And then since we have this limit of 10, we'll get back our first then items and I'll use my example
where I have 75.
So hopefully that is clear if this is zero.
And then I have the limit of 10.
I'll get back then items.
So now let me showcase not just with the values that we currently have.
So let me go to a job controller.
I'll go with skip zero and nine.
The limit will still be hardcoded as one Senate.
Notice we start with our first company place.
That was my scenario.
And then I have total jobs then, which means that our functionality works.
Now, if I want to get the second page, well, then the page value will be to the limit.
Still be fine.
That's the hardcoded value and not as far as skipping how many items that we're skipping.
We're going to minus one, which is one times the limit, which is 10.
So this value will be what it will be 10 over here.
So we're shipping 10 items, and that's how we jump to the second page because we're still limiting
Martin and one by one.
So we set up the functionality again.
We'll look for a page value by default.
This is one we look for limit.
By default, this is going to be 10.
And in order to calculate skip, we subtract one from whatever is on the page and then multiply by limit,
which in our case is 10.
And then we pass in these two values and skip and limit.
And as a result, we can get certain pages back.
So let's try to set that one up.
Where I'm going to go to jobs controller here, the moment I have hardcoded values.
So it's change that one around them.
First, let's start with that page.
So page, let's go with no, that's passing Eric Query and the page.
If you're wondering, well, why you're grabbing us from the query, why don't you go over here and
just pull out?
Well, you can definitely do so.
But I already have the variable by the name of Page, and I just find this one easier if nothing is
there.
And by default, we're going to be getting with the first page.
Let's copy and paste now.
In this case, I have a limit of 10 or a move that one.
And let's do the same thing over here, where limit is equal to wreck, query and limit.
And I know I said this before, but from our front end we'll actually won't sign it.
If you want to set up that functionality or indefinitely or so and we'll start with eight, then so
that's the default one.
And then let's set up that skip, let's say, page minus one and nine times the limit.
That's the whole logic behind it.
Let's save it, and let's start out where I'm going to go here, where I'm setting up the where certain
parameters I'm going to say page and I want for time being is going to be equal to a one.
And then as far as the element, well, let's go with that then same one, the default.
Then once we send, I'm going to get back, then jobs and notice again.
This is going to be my first one.
I'm not going to show you page by page, but I just want to show that if I'm going to go with page number
eight, I'm only going to get five hours.
Why?
Well, because I have 75 total.
So if we go over here, if we send, check it out.
Now I have only five jobs total.
I got off my showcase that here were the numbers where I go here with eight one eight minus one is seven.
Seven times the limit is 70.
So we're skipping 70 items and we're limiting to 10.
Now, since we get back, only five doesn't really matter, since it's not bigger than the limit.
And if you want to change this around, let's say that we're going to go with page number one and then
we're looking for twenty five.
Now, since the limit is twenty five, now we actually have three pages.
So if we're going to go here with four, you'll notice that we get back nothing.
Correct.
Again, 75 divided by limit of 25 is three pages and then we can go one by one and get those pages one,
two three and then the fourth page.
We already don't have any items.
Hopefully this is square and now we can deal with total jobs as well as number of pages.