Skip to content

Nested operation Sorting

Vladislav Trotsenko edited this page Sep 30, 2019 · 2 revisions

Synopsis

Provides JSON API sorting.

HTTP request example: GET /users?sort=name,-age

Code

Before using this nested operation you should set ctx[:available_columns] with ColumnsBuilder:

module Api::V1::Lib::Operation
  class Sorting < ApplicationOperation
    step :sort_params_passed?, Output(:failure) => End(:success)
    step Macro::Contract::Schema(Api::V1::Lib::Contract::SortingPreValidation, name: :uri_query)
    step Contract::Validate(name: :uri_query)
    step :set_validation_dependencies
    step Macro::Contract::Schema(
      Api::V1::Lib::Contract::SortingValidation,
      inject: %i[available_sortable_columns],
      name: :uri_query
    )
    step Contract::Validate(name: :uri_query), id: :sorting_validation
    step :order_options
  end
end

Used nested & macroses

Dependent from

Clone this wiki locally