Sha256: c7329ebb3d4ac5eef98602ac586d99ec63a4bf64b49ec9bb59afee5a544b4105

Contents?: true

Size: 1.59 KB

Versions: 29

Compression:

Stored size: 1.59 KB

Contents

module Spree
  module Api
    module V2
      module Platform
        class LineItemsController < ResourceController
          def create
            order = current_store.orders.find(permitted_resource_params[:order_id])

            result = create_service.call(order: order, line_item_attributes: permitted_resource_params)

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

          def update
            result = update_service.call(line_item: resource, line_item_attributes: permitted_resource_params)

            if result.success?
              render_serialized_payload { serialize_resource(result.value) }
            else
              render_error_payload(resource.errors)
            end
          end

          def destroy
            result = destroy_service.call(line_item: resource)

            if result.success?
              head 204
            else
              render_error_payload(result.error)
            end
          end

          private

          def model_class
            Spree::LineItem
          end

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

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

          def destroy_service
            Spree::Api::Dependencies.platform_line_item_destroy_service.constantize
          end
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 3 rubygems

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