Sha256: 716da6e00a7c7b7142c1ec1f56e1dd6a256b832058c80a9f99c5e514b1689e47

Contents?: true

Size: 945 Bytes

Versions: 61

Compression:

Stored size: 945 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
          respond_with(@states) if stale?(state)
        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, :show).find(params[:country_id])
            @country.states.accessible_by(current_ability).order('name ASC')
          else
            State.accessible_by(current_ability).order('name ASC')
          end
        end
      end
    end
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
spree_api-4.0.9 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.1.15 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.2.7 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.3.3 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.4.1 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.2.6 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.3.2 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.4.0 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.4.0.rc2 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.3.1 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.4.0.rc1 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.3.0 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.3.0.rc3 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.3.0.rc2 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.3.0.rc1 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.2.5 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.1.14 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.0.8 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.2.4 app/controllers/spree/api/v1/states_controller.rb
spree_api-4.2.3.1 app/controllers/spree/api/v1/states_controller.rb