Sha256: 60f1966db3a389aeeb76ef7d09e63edab505fe77bc9baf45d5b1d88dd6172874

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

module {{namespace_module}}
  module Accounts
    module Destroy
      class Control
        include Shogun::Control
        include Accounts

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

          if @validator.valid?
            @session = Sessions::Model.find_by(id: @normalizer.session)
            @model = Model.find_by(id: @normalizer.id)
            @authorizer = Authorizer.new(requester: @session, resource: @model)

            case
            when @model && @authorizer.allowed?
              @model.destroy
              @presenter = Presenter.new(resource: @model, meta: @normalizer.as_meta)
              @denormalizer = Denormalizer.new(object: @presenter)
              @status = OK
            when @model && @authorizer.denied?
              @status = UNAUTHORIZED
            else
              @status = NOT_FOUND
            end
          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/new/project/lib/namespace/accounts/destroy/control.rb
shogun-6.4.1 scaffold/new/project/lib/namespace/accounts/destroy/control.rb
shogun-6.4.0 scaffold/new/project/lib/namespace/accounts/destroy/control.rb
shogun-6.3.0 scaffold/new/project/lib/namespace/accounts/destroy/control.rb
shogun-6.2.3 scaffold/new/project/lib/namespace/accounts/destroy/control.rb
shogun-6.2.2 scaffold/new/project/lib/namespace/accounts/destroy/control.rb