Class: Praxis::Extensions::Pagination::PaginationStruct
- Inherits:
-
Struct
- Object
- Struct
- Praxis::Extensions::Pagination::PaginationStruct
- 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
-
#order ⇒ Object
Returns the value of attribute order.
-
#paginator ⇒ Object
Returns the value of attribute paginator.
-
#total_count ⇒ Object
Returns the value of attribute total_count.
Instance Attribute Details
#order ⇒ Object
Returns the value of attribute order
44 45 46 |
# File 'lib/praxis/extensions/pagination.rb', line 44 def order @order end |
#paginator ⇒ Object
Returns the value of attribute paginator
44 45 46 |
# File 'lib/praxis/extensions/pagination.rb', line 44 def paginator @paginator end |
#total_count ⇒ Object
Returns the value of attribute total_count
44 45 46 |
# File 'lib/praxis/extensions/pagination.rb', line 44 def total_count @total_count end |