elixirdrops / kerosene

Pagination for Ecto and Pheonix.
https://github.com/elixirdrops/kerosene
MIT License
231 stars 39 forks source link

Requesting page beyond max_page returns entries #54

Closed zumatande closed 5 years ago

zumatande commented 5 years ago

Requesting page 101 when max_page is left unset and therefore defaults to 100 even when number of entries is paginated such that it will not "overflow" page 100 returns entries equal to the number of entries returned in the last page. Returned sets of entries, however, are not the same.

e.g. %Kerosene{ entries: entries # length = 14 max_page: 100, page: 123, # (requested) total_pages: 5, per_page: 20, total_count: 94, }

number of returned entries: 14 (94 rem 20)

Is this a bug or the expected behaviour?

zumatande commented 5 years ago

I see that it's the expected behaviour, closing this.

def get_page(params, total_pages) do
    case params[:page] > params[:max_page] do
      true -> total_pages
      _ -> params[:page]
    end
end