Skip to content

Commit

Permalink
Merge branch 'issue-785' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
zmcNotafraid committed Dec 17, 2024
2 parents de51e3d + 508b027 commit fa1ea8c
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions app/lib/fast_jsonapi/pagination_meta_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ class PaginationMetaGenerator
DEFAULT_PAGE = 1
DEFAULT_PER_PAGE = 20

def initialize(request:, records:, page:, page_size:, records_counter: nil, total_count: nil)
def initialize(request:, records:, page:, page_size:, total_pages: nil, records_counter: nil, total_count: nil)
@url = request.base_url + request.path + query_string(request.query_parameters)
@page = page.to_i
@page_size = limit_page_size(records, page_size.to_i)
@records = records
@records_counter = records_counter || records
@total_count = total_count || @records_counter.total_count.to_i
@total_pages = total_pages
@total_pages = total_pages || calculated_total_pages
@hash = { links: {}, meta: { total: @total_count, page_size: @page_size } }
end

def total_pages
def calculated_total_pages
(total_count / @page_size).ceil
end

Expand All @@ -31,10 +31,6 @@ def current_page
records.current_page
end

def last_page?
current_page == total_pages
end

def next_page
current_page + 1 unless last_page? || out_of_range?
end
Expand Down

0 comments on commit fa1ea8c

Please sign in to comment.