Class: Spree::Api::V2::Storefront::Transit::ItemAvailabilitiesController

Inherits:
ResourceController
  • Object
show all
Includes:
SpreeCmCommissioner::Integrations::InventorySyncCachable
Defined in:
app/controllers/spree/api/v2/storefront/transit/item_availabilities_controller.rb

Instance Method Summary collapse

Methods included from SpreeCmCommissioner::Integrations::InventorySyncCachable

#sync_cache_ttl

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/spree/api/v2/storefront/transit/item_availabilities_controller.rb', line 9

def create
  sync_result = sync_item_availability!

  unless sync_result.success?
    error_message = sync_result.to_h.dig(:error, :message) || 'Sync failed'
    return render_error_payload(error_message, 422)
  end

  item_availability = SpreeCmCommissioner::ItemAvailabilitySync.new(
    id: trip.id,
    last_sync_at: sync_result.last_synced_at
  )
  render_serialized_payload { serialize_resource(item_availability) }
rescue ActiveRecord::RecordNotFound => e
  render_error_payload(e.message, 404)
end