Commit 3910c490 authored by Michael Kozono's avatar Michael Kozono

Merge branch 'ab/pagination-consolidate' into 'master'

API Pagination: Move specific methods out of Base

Closes #37447

See merge request gitlab-org/gitlab!23175
parents c1dfca96 e2710d72
......@@ -10,31 +10,6 @@ module Gitlab
def finalize(records)
# Optional: Called with the actual set of records
end
private
def per_page
@per_page ||= params[:per_page]
end
def base_request_uri
@base_request_uri ||= URI.parse(request.url).tap do |uri|
uri.host = Gitlab.config.gitlab.host
uri.port = Gitlab.config.gitlab.port
end
end
def build_page_url(query_params:)
base_request_uri.tap do |uri|
uri.query = query_params
end.to_s
end
def page_href(next_page_params = {})
query_params = params.merge(**next_page_params, per_page: per_page).to_query
build_page_url(query_params: query_params)
end
end
end
end
......@@ -3,7 +3,7 @@
module Gitlab
module Pagination
module Keyset
class Pager
class Pager < Gitlab::Pagination::Base
attr_reader :request
def initialize(request)
......
......@@ -72,6 +72,29 @@ module Gitlab
def data_without_counts?(paginated_data)
paginated_data.is_a?(Kaminari::PaginatableWithoutCount)
end
def base_request_uri
@base_request_uri ||= URI.parse(request.url).tap do |uri|
uri.host = Gitlab.config.gitlab.host
uri.port = Gitlab.config.gitlab.port
end
end
def build_page_url(query_params:)
base_request_uri.tap do |uri|
uri.query = query_params
end.to_s
end
def page_href(next_page_params = {})
query_params = params.merge(**next_page_params, per_page: per_page).to_query
build_page_url(query_params: query_params)
end
def per_page
@per_page ||= params[:per_page]
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment