Class: Spree::Api::V2::Storefront::IntercityTaxi::DraftOrdersController

Inherits:
ResourceController
  • Object
show all
Includes:
OrderConcern, SpreeCmCommissioner::OrderConcern
Defined in:
app/controllers/spree/api/v2/storefront/intercity_taxi/draft_orders_controller.rb

Instance Method Summary collapse

Methods included from SpreeCmCommissioner::OrderConcern

#find_spree_current_order, #spree_current_order

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/spree/api/v2/storefront/intercity_taxi/draft_orders_controller.rb', line 12

def create
  result = SpreeCmCommissioner::IntercityTaxiOrder::Create.call(
    trip_id: params[:trip_id],
    from_date: params[:from_date],
    to_date: params[:to_date],
    user: spree_current_user,
    quantity: params[:quantity]
  )

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

#updateObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/spree/api/v2/storefront/intercity_taxi/draft_orders_controller.rb', line 28

def update
  result = SpreeCmCommissioner::IntercityTaxiOrder::Update.call(
    order: spree_current_order,
    remark: params[:remark],
    pickup_map_place_attributes: params.require(:pickup_map_place_attributes).permit(
      :place_name,
      :lat,
      :lng,
      :oob_confirmed
    ),
    dropoff_map_place_attributes: params.require(:dropoff_map_place_attributes).permit(
      :place_name,
      :lat,
      :lng,
      :oob_confirmed
    ),
    distance_attributes: params.require(:distance_attributes).permit(
      :distance_km,
      :ordered_points,
      :estimated_time_minutes,
      :base_km,
      :detour_pickup_km,
      :detour_dropoff_km,
      :extra_pickup_km,
      :extra_dropoff_km
    )
  )

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