Class: SpreeCmCommissioner::Integrations::VireakBuntham::Polling::SyncTrips

Inherits:
Object
  • Object
show all
Defined in:
app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_trips.rb

Overview

SyncTrips synchronizes VET schedule data into BookMe+ transit records.

VET’s API provides schedules per origin/destination/date via POST /schedule/listByDate. This service:

1. Resolves the VET location IDs from the Route's origin/destination places
2. Fetches schedules for the given date from the VET API
3. For each schedule:
   a. Syncs VehicleType   (from transportationType)
   b. Syncs Product       (one per schedule)
   c. Syncs Variant       (unique per schedule_id)
   d. Syncs Trip record   (the core transit trip entity)
   e. Creates/updates stock_item from schedule.total_seat
   f. Generates permanent inventory item for the specific date
   g. Syncs SeatLayout    (from POST /seat/layout)
   h. Syncs TripStops     (origin boarding + destination drop-off)
4. Archives stale trip mappings for the date
5. Touches the route mapping's last_synced_at

Key Design Decisions

  • trip.external_ref = schedule.id (VET journey ID, used by client calls downstream)

  • Sync identifier: “#scheduleschedule.id-#on_date” — unique per schedule/date combo

  • Origin/destination places resolved from @location_mappings keyed by VET location UUID

  • SyncStockItem called twice: first with 0 inside transaction, then with actual seat count from SeatLayout after post-transaction seat layout sync

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(integration:, sync_result: nil, route: nil) ⇒ SyncTrips

Returns a new instance of SyncTrips.



33
34
35
36
37
38
39
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_trips.rb', line 33

def initialize(integration:, sync_result: nil, route: nil)
  @integration = integration
  @sync_result = sync_result || SpreeCmCommissioner::Integrations::Base::SyncResult.new
  @route = route
  @vendor = integration.vendor
  @location_mappings = {}
end

Instance Attribute Details

#integrationObject (readonly)

Returns the value of attribute integration.



31
32
33
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_trips.rb', line 31

def integration
  @integration
end

#routeObject (readonly)

Returns the value of attribute route.



31
32
33
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_trips.rb', line 31

def route
  @route
end

#sync_resultObject (readonly)

Returns the value of attribute sync_result.



31
32
33
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_trips.rb', line 31

def sync_result
  @sync_result
end

#vendorObject (readonly)

Returns the value of attribute vendor.



31
32
33
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_trips.rb', line 31

def vendor
  @vendor
end

Instance Method Details

#call(on_date: nil) ⇒ Object

Parameters:

  • on_date (String) (defaults to: nil)

    YYYY-MM-DD



42
43
44
45
46
47
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_trips.rb', line 42

def call(on_date: nil)
  return unless route

  preload_location_mappings!
  sync_items!(on_date)
end