vapor-community / pagination

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

Incorrect page total when filtering db and adding pagination #25

Open Prince2k3 opened 4 years ago

Prince2k3 commented 4 years ago

Describe the bug

Hello!

I'm experiencing an issue with the pagination.

As example when I have code like this

...
.paginate(on: request, response: APIPaginated.self) { builder in
            if let fromDate = fromDate {
                return builder
                .filter(\.userId == userId)
                .filter(\.closed == false)
                .filter(\.createdAt >= fromDate)
                .sort(\.createdAt)
                .all()
            } else {
                return builder
                .filter(\.userId == userId)
                .filter(\.closed == false)
                .sort(\.createdAt)
                .all()
            }
        }

Things work but the total is the wrong total and not based on the filtered total.

Steps To Reproduce Steps to reproduce the behavior:

  1. make a custom paginated response
  2. paginate your data with filters
  3. notice the total is wrong

Expected behavior I expect that when I query and filter the db the total would reflect the total after filtering

Version Information