api2go icon indicating copy to clipboard operation
api2go copied to clipboard

No need check pagination.isValid() in handleIndex

Open imhuytq opened this issue 8 years ago • 2 comments

In some cases, I want to use only page[number] without page[size]. Currently handleIndex will ignore PaginatedFindAll (Because pagination.isValid() is false) and call to FindAll. If this time my resource does not implement FindAll, then the 404 error.

I think we do not need to call pagination.isValid() in handleIndex, let this be for PaginatedFindAll. So I can customize my API more easily.

What do you think about this?

imhuytq avatar Nov 11 '17 08:11 imhuytq

Depends on the reason of why do you want to omit the page size.

I've been trying to wrap my head around the idea but it kinda always results in some kind of fallback size which the server knows. Since jsonapi wants to give the client full control of the backend, I'd rather not omit it, if that's the case.

If the case is, that for the first page you want to specify the page length, and for further requests omit it, then we should look into supporting cursor based pagination (http://jsonapi.org/format/#fetching-pagination) which we currently don't support but is in my opinion the better solution.

sharpner avatar Nov 11 '17 09:11 sharpner

For example, I have a resource called Profile. When my client requests to /profiles without any page[number] or page[size] parameters, I want the server to return to the client a paginated result and include the links (next, prev, first, last). Currently I will have to manually create the list of links in the FindAll function and insert it into the Response.

I think instead of using pagination.isValid() in handleIndex, we will validate the parameters in PaginatedFindAll, and PaginatedFindAll will return a "PaginationParams" struct like this:

type PaginationParams struct {
	number, size, offset, limit uint64
        total                                    uint
}

Finally, the "paginationQueryParams" struct will use the above data to generate links.

imhuytq avatar Nov 11 '17 10:11 imhuytq