Sha256: 72a23156fd8f76087c768e28740d9491f69b51137af12068aaa73ff4defbdcde

Contents?: true

Size: 1.98 KB

Versions: 5

Compression:

Stored size: 1.98 KB

Contents

module Spree
  module Api
    module V2
      module Storefront
        module Account
          class AddressesController < ::Spree::Api::V2::ResourceController
            before_action :require_spree_current_user

            def create
              result = create_service.call(user: spree_current_user, address_params: address_params)
              render_result(result)
            end

            def update
              result = update_service.call(address: resource, address_params: address_params)
              render_result(result)
            end

            private

            def collection
              collection_finder.new(scope: scope, params: params).execute
            end

            def model_class
              Spree::Address
            end

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

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

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

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

            def create_service
              Spree::Api::Dependencies.storefront_account_create_address_service.constantize
            end

            def update_service
              Spree::Api::Dependencies.storefront_account_update_address_service.constantize
            end

            def address_params
              params.require(:address).permit(permitted_address_attributes)
            end

            def render_result(result)
              if result.success?
                render_serialized_payload { serialize_resource(result.value) }
              else
                render_error_payload(result.error)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spree_api-4.2.1 app/controllers/spree/api/v2/storefront/account/addresses_controller.rb
spree_api-4.2.0 app/controllers/spree/api/v2/storefront/account/addresses_controller.rb
spree_api-4.2.0.rc5 app/controllers/spree/api/v2/storefront/account/addresses_controller.rb
spree_api-4.2.0.rc4 app/controllers/spree/api/v2/storefront/account/addresses_controller.rb
spree_api-4.2.0.rc3 app/controllers/spree/api/v2/storefront/account/addresses_controller.rb