blob: e06d7e48ca3de9894b91cde49707eeff89871ea8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# frozen_string_literal: true
module Gitlab
module Pagination
module Keyset
class CursorBasedRequestContext
DEFAULT_SORT_DIRECTION = :desc
attr_reader :request_context
delegate :params, to: :request_context
def initialize(request_context)
@request_context = request_context
end
def per_page
params[:per_page]
end
def cursor
params[:cursor]
end
def apply_headers(cursor_for_next_page)
Gitlab::Pagination::Keyset::HeaderBuilder
.new(request_context)
.add_next_page_header({ cursor: cursor_for_next_page })
end
def order_by
{ params[:order_by].to_sym => params[:sort]&.to_sym || DEFAULT_SORT_DIRECTION }
end
end
end
end
end
|