Add prototype of pipelines serializer with pagination
This commit is contained in:
parent
7870614fb9
commit
f55fcef3db
|
@ -18,6 +18,7 @@ class Projects::PipelinesController < Projects::ApplicationController
|
|||
render json: {
|
||||
pipelines: PipelineSerializer
|
||||
.new(project: @project, user: @current_user)
|
||||
.with_pagination(request, response)
|
||||
.represent(@pipelines),
|
||||
updated_at: Time.now.utc,
|
||||
count: {
|
||||
|
|
|
@ -1,3 +1,37 @@
|
|||
class PipelineSerializer < BaseSerializer
|
||||
entity PipelineEntity
|
||||
include API::Helpers::Pagination
|
||||
Struct.new('Pagination', :request, :response)
|
||||
|
||||
def with_pagination(request, response)
|
||||
tap { @pagination = Struct::Pagination.new(request, response) }
|
||||
end
|
||||
|
||||
def paginate?
|
||||
defined?(@pagination)
|
||||
end
|
||||
|
||||
def represent(resource, opts = {})
|
||||
if paginate?
|
||||
super(paginate(resource), opts)
|
||||
else
|
||||
super(resource, opts)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Methods needed by `API::Helpers::Pagination`
|
||||
#
|
||||
def params
|
||||
@pagination.request.query_parameters
|
||||
end
|
||||
|
||||
def request
|
||||
@pagination.request
|
||||
end
|
||||
|
||||
def header(header, value)
|
||||
@pagination.response.headers[header] = value
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue