Sha256: fd4a27c80bea1d57eb8a2780ca83cb09766efd27f8b7952bac42578b87eb5912

Contents?: true

Size: 1011 Bytes

Versions: 6

Compression:

Stored size: 1011 Bytes

Contents

module {{namespace_module}}
  module {{resource_module}}
    module List
      class Control
        include Shogun::Control
        include {{resource_module}}

        def initialize(payload:)
          @normalizer = Normalizer.new(raw: payload.to_hash)
          @validator = Validator.new(data: @normalizer)

          if @validator.valid?
            @models = Model.limit(@normalizer.limit).where(@normalizer.filters).includes(@normalizer.includes)
            @presenters = Shogun::Presenters.new(resources: @models, cast: Presenter, includes: @normalizer.includes, meta: @normalizer.as_meta)
            @denormalizer = Denormalizer.new(object: @presenters, fields: @normalizer.fields)
            @status = OK
          else
            @presenters = Shogun::Presenters.new(resources: @validator.invalids, cast: Errors::Presenter)
            @denormalizer = Errors::Denormalizer.new(object: @presenters)
            @status = UNPROCESSABLE_ENTITY
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shogun-6.4.2 scaffold/generate/resource/list/control.rb
shogun-6.4.1 scaffold/generate/resource/list/control.rb
shogun-6.4.0 scaffold/generate/resource/list/control.rb
shogun-6.3.0 scaffold/generate/resource/list/control.rb
shogun-6.2.3 scaffold/generate/resource/list/control.rb
shogun-6.2.2 scaffold/generate/resource/list/control.rb