forked from rubygarage/boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Nested operation Pagination
Vladislav Trotsenko edited this page Oct 21, 2020
·
1 revision
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
endService::Pagy