-
Notifications
You must be signed in to change notification settings - Fork 9
Nested operation Pagination
Vladislav Trotsenko edited this page Sep 30, 2019
·
2 revisions
Provides JSON API pagination with offset strategy. Accepts AciveRelation
or Array
as collection. By default returns 25 items per page.
HTTP request example: GET /users?page[number]=1&page[size]=1
PLease note, before using this nested operation you should set ctx[:model] as AciveRelation
or Array
.
module Api::V1::Lib::Operation
class Pagination < ApplicationOperation
step Macro::Contract::Schema(Api::V1::Lib::Contract::PaginationValidation, name: :uri_query)
step Contract::Validate(name: :uri_query), fail_fast: true
step :pagy # sets ctx[:pagy], ctx[:model]
step :valid_page?
fail Macro::AddContractError(name: :uri_query, page: [:number, [I18n.t('errors.pagination_overflow')]])
end
end
Service::Pagy
RubyGarage is a leading software development and consulting company in Eastern Europe. Our main expertise includes Ruby and Ruby on Rails, but we successfully employ other technologies to deliver the best results to our clients. Check out our portfolio for even more exciting works!