Sha256: be0f5c8a0c4ed0c9d71d0c6081a105dde6f91098ec4120b7b46c80ee0ee0e5a3

Contents?: true

Size: 1.45 KB

Versions: 12

Compression:

Stored size: 1.45 KB

Contents

module Spree
  module Api
    module V2
      module Storefront
        class CountriesController < ::Spree::Api::V2::ResourceController
          private

          def serialize_collection(collection)
            collection_serializer.new(collection).serializable_hash
          end

          def serialize_resource(resource)
            resource_serializer.new(
              resource,
              include: resource_includes,
              fields: sparse_fields,
              params: resource_serializer_params
            ).serializable_hash
          end

          def resource_serializer_params
            {
              include_states: true,
              current_store: current_store
            }
          end

          def resource
            return scope.default 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
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
spree_api-4.2.7 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.2.6 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.2.5 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.2.4 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.2.3.1 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.2.3 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.2.2 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.2.1 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.2.0 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.2.0.rc5 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.2.0.rc4 app/controllers/spree/api/v2/storefront/countries_controller.rb
spree_api-4.2.0.rc3 app/controllers/spree/api/v2/storefront/countries_controller.rb