Sha256: 55b424a4b006ff51298e1b1cbc281a2b1667edd7ce241f6c913a8714c9eab9dd

Contents?: true

Size: 971 Bytes

Versions: 2

Compression:

Stored size: 971 Bytes

Contents

module OpenStax
  module Accounts
    module Dev
      class AccountsSearch

        lev_handler transaction: :no_transaction

        paramify :search do
          attribute :terms, type: String
          attribute :type, type: String
          attribute :page, type: Integer
        end

        uses_routine OpenStax::Accounts::Dev::SearchAccounts,
                     as: :search_accounts,
                     translations: { outputs: {type: :verbatim} }

        protected

        def authorized?
          !Rails.env.production?
        end

        def handle
          case search_params.type
          when 'Name'
            query = "name:#{search_params.terms.gsub(/\s/,',')}"
          when 'Username'
            query = "username:#{search_params.terms.gsub(/\s/,',')}"
          else
            query = search_params.terms || ''
          end
          run(:search_accounts, query, page: search_params.page || 0)
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
openstax_accounts-3.1.1 app/handlers/openstax/accounts/dev/accounts_search.rb
openstax_accounts-3.1.0 app/handlers/openstax/accounts/dev/accounts_search.rb