Class: Praxis::Extensions::Pagination::PaginationStruct

Inherits:
Struct
  • Object
show all
Defined in:
lib/praxis/extensions/pagination.rb

Overview

This PaginatedController concern should be added to controllers that have actions that define the pagination and order parameters so that one can call the domain model to craft the query ‘domain_model.craft_pagination_query(base_query, pagination: _pagination)` This will handle all the required logic for paginating, ordering and generating the Link and TotalCount headers.

Here’s a simple example on how to use it for a fake Items controller class Items < V1::Controllers::BaseController

include Praxis::Controller
include Praxis::Extensions::Rendering
implements V1::Endpoints::Items

include Praxis::Extensions::Pagination

def index(filters: nil, pagination: nil, order: nil,  **_args)
  items = current_user.items.all
  domain_model = self.media_type.domain_model
  items = domain_model.craft_pagination_query( query: items, pagination: _pagination)

  display(items)
end

end

This code will properly add the right clauses to the final query based on the pagination strategy and ordering and it will also generate the Link header with the appropriate relationships depending on the paging strategy. When total_count is requested in the pagination a header with TotalCount will also be included.

Instance Attribute Summary collapse

Instance Attribute Details

#orderObject

Returns the value of attribute order

Returns:

  • (Object)

    the current value of order



44
45
46
# File 'lib/praxis/extensions/pagination.rb', line 44

def order
  @order
end

#paginatorObject

Returns the value of attribute paginator

Returns:

  • (Object)

    the current value of paginator



44
45
46
# File 'lib/praxis/extensions/pagination.rb', line 44

def paginator
  @paginator
end

#total_countObject

Returns the value of attribute total_count

Returns:

  • (Object)

    the current value of total_count



44
45
46
# File 'lib/praxis/extensions/pagination.rb', line 44

def total_count
  @total_count
end