Class: Spree::Api::V2::Tenant::IntercityTaxi::DraftOrdersController

Inherits:
BaseController
  • Object
show all
Includes:
Storefront::OrderConcern, SpreeCmCommissioner::AnonymousBookingGuard, SpreeCmCommissioner::OrderConcern
Defined in:
app/controllers/spree/api/v2/tenant/intercity_taxi/draft_orders_controller.rb

Instance Method Summary collapse

Methods included from SpreeCmCommissioner::OrderConcern

#device_id, #find_spree_current_order, #spree_current_order

Methods inherited from BaseController

#current_vendor, #render_serialized_payload, #require_tenant, #scope

Instance Method Details

#createObject



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

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

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

#updateObject



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
62
63
64
65
66
# File 'app/controllers/spree/api/v2/tenant/intercity_taxi/draft_orders_controller.rb', line 30

def update
  result = SpreeCmCommissioner::IntercityTaxiOrder::Update.call(
    order: spree_current_order,
    remark: params[:remark],
    passenger_count: params[:passenger_count],
    pickup_map_place_attributes: params[:pickup_map_place_attributes]&.permit(
      :place_name,
      :lat,
      :lng,
      :oob_confirmed
    ),
    dropoff_map_place_attributes: params[:dropoff_map_place_attributes]&.permit(
      :place_name,
      :lat,
      :lng,
      :oob_confirmed
    ),
    distance_attributes: params[:distance_attributes]&.permit(
      :distance_km,
      { ordered_points: %i[lat lng] },
      :estimated_time_minutes,
      :base_km,
      :detour_pickup_km,
      :detour_dropoff_km,
      :extra_pickup_km,
      :extra_dropoff_km,
      :signed_at,
      :signature
    )
  )

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