Sha256: ede59bbd20675c4eb5d2ecd6e958e66fca59f350d07fca54c8e60179c4abddc8

Contents?: true

Size: 1014 Bytes

Versions: 43

Compression:

Stored size: 1014 Bytes

Contents

module Spree
  module Api
    module V1
      class StatesController < Spree::Api::BaseController
        skip_before_action :authenticate_user

        def index
          @states = scope.ransack(params[:q]).result.includes(:country)

          if params[:page] || params[:per_page]
            @states = @states.page(params[:page]).per(params[:per_page])
          end

          state = @states.last
          if stale?(state)
            respond_with(@states)
          end
        end

        def show
          @state = scope.find(params[:id])
          respond_with(@state)
        end

        private
          def scope
            if params[:country_id]
              @country = Country.accessible_by(current_ability, :read).find(params[:country_id])
              return @country.states.accessible_by(current_ability, :read).order('name ASC')
            else
              return State.accessible_by(current_ability, :read).order('name ASC')
            end
          end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
spree_api-3.2.9 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.1.14 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.3.6 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.2.8 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.1.13 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.3.5 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.3.4 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.2.7 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.1.12 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.3.3 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.2.6 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.1.11 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.1.10 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.3.2 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.2.5 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.1.9 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.3.1 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.2.4 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.1.8 app/controllers/spree/api/v1/states_controller.rb
spree_api-3.3.0 app/controllers/spree/api/v1/states_controller.rb