Sha256: dd2b117ffc157af27f8a83393e94c9f8e1dadb34fbf21a2000d87c0a836aa296

Contents?: true

Size: 1.57 KB

Versions: 34

Compression:

Stored size: 1.57 KB

Contents

module Spree
  module Api
    module V2
      module Storefront
        class CountriesController < ::Spree::Api::V2::ResourceController
          before_action :set_default_per_page

          private

          def serialize_collection(collection)
            collection_serializer.new(
              collection,
              collection_options(collection).merge(params: collection_serializer_params)
            ).serializable_hash
          end

          def serializer_params
            super.merge(include_states: true)
          end

          def collection_serializer_params
            serializer_params.merge(include_states: false)
          end

          def resource
            return current_store.default_country if params[:iso] == 'default'

            scope.find_by(iso: params[:iso]&.upcase) ||
              scope.find_by(id: params[:iso]&.upcase) ||
              scope.find_by(iso3: params[:iso]&.upcase)
          end

          def resource_serializer
            Spree::Api::Dependencies.storefront_country_serializer.constantize
          end

          def collection_serializer
            Spree::Api::Dependencies.storefront_country_serializer.constantize
          end

          def collection_finder
            Spree::Api::Dependencies.storefront_country_finder.constantize
          end

          def model_class
            Spree::Country
          end

          # by default we want to return all countries on a single page
          def set_default_per_page
            params[:per_page] ||= Spree::Country.count
          end
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 3 rubygems

Version Path
spree_api-4.10.1 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.10.0 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.9.0 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.8.3 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.8.2 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.7.3 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.6.6 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.5.5 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.3.3 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.4.1 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.5.4 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.6.5 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.7.2 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.7.1 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.6.4 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.7.0 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.6.3 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.6.2 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.6.1 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.6.0 app/controllers/spree/api/v2/storefront/countries_controller.rb