vapor-community / pagination

Simple Vapor 3 Pagination
MIT License
64 stars 15 forks source link

Always return 1 as the max number of pages #6

Closed heidipuk closed 6 years ago

heidipuk commented 6 years ago

When running a request using pagination, it always return 1 as the maximum number of pages. I have located the issue to originated in line 33 in Paginated.swift, where the number of pages i calculated;

   let count = Int(ceil(Double(self.total) / Double(self.size)))

It always return 1 since self.total returns the number of entries at the given page, not the total number of returned entries. Testing with a page without any entries, it returns 0 as max page number.

I ran a test with 13 entries in total and 5 entries per page. This should return a total of 3 pages. The following the the meta data from page 2:

// testing for page 2 of 3
"page": {
        "position": {
            "current": 2, //"next" is missing, which is related to the issue with counting the maximum number of pages
            "previous": 1,
            "max": 1   //Return 1 even though there are 3 pages
        },
        "data": {
            "per": 5,
            "total": 5
        }
    }
// Testing for page 4, which is empty
{
    "data": [],
    "page": {
        "position": {
            "current": 4,
            "previous": 3,
            "max": 0
        },
        "data": {
            "per": 5,
            "total": 0
        }
    }
}

The test is run with the following versions Vapor 3.0.2 Fluent 3.0.0-rc.2.4.1 Pagination 1.0.0 and Pagination 1.0.1

anthonycastelli commented 6 years ago

This is now fixed in the 1.0.2 release! 🙂