Class: Spree::Api::V2::Storefront::Transit::DraftOrdersController
- Inherits:
-
ResourceController
- Object
- ResourceController
- Spree::Api::V2::Storefront::Transit::DraftOrdersController
- Defined in:
- app/controllers/spree/api/v2/storefront/transit/draft_orders_controller.rb
Instance Method Summary collapse
- #build_legs(direction, legs_params) ⇒ Object
-
#create ⇒ Object
Creates a draft transit order.
-
#resource_serializer ⇒ Object
override.
Instance Method Details
#build_legs(direction, legs_params) ⇒ Object
33 34 35 |
# File 'app/controllers/spree/api/v2/storefront/transit/draft_orders_controller.rb', line 33 def build_legs(direction, legs_params) SpreeCmCommissioner::Transit::LegsBuilderService.new(direction: direction, legs_params: legs_params).call end |
#create ⇒ Object
Creates a draft transit order. Endpoint: POST /api/v2/storefront/transit/draft_orders Params:
-
outbound_date: Date of outbound transit (optional)
-
inbound_date: Date of inbound transit (optional)
-
outbound_legs: Array of outbound leg details (required)
-
inbound_legs: Array of inbound leg details (optional)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/spree/api/v2/storefront/transit/draft_orders_controller.rb', line 14 def create @outbound_legs = params[:outbound_legs].is_a?(Array) && params[:outbound_legs].any? ? build_legs(:outbound, params[:outbound_legs]) : [] @inbound_legs = params[:inbound_legs].is_a?(Array) && params[:inbound_legs].any? ? build_legs(:inbound, params[:inbound_legs]) : [] context = SpreeCmCommissioner::Transit::DraftOrderCreator.call( outbound_date: params[:outbound_date]&.to_date, inbound_date: params[:inbound_date]&.to_date, outbound_legs: @outbound_legs, inbound_legs: @inbound_legs, user: spree_current_user ) if context.success? render_serialized_payload { serialize_resource(context.order) } else render_error_payload(context.) end end |