Class: SpreeCmCommissioner::Integrations::VireakBuntham::Polling::SyncSeatLayout
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Integrations::VireakBuntham::Polling::SyncSeatLayout
- Defined in:
- app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_seat_layout.rb
Overview
SyncSeatLayout — syncs seat layouts from VET’s POST /seat/layout endpoint.
Flow:
1. Fetch the JSON seat grid via client.get_seat_layout!(journey:, date:).
2. Upsert a VehicleType-level SeatLayout template (shared across all trips
of the same transportation type).
3. If a variant is provided, duplicate the template to trip level and
assign the variant to all sellable blocks.
Position system:
x = HALF_PADDING + col * (BLOCK_SIZE + BLOCK_GAP)
y = HALF_PADDING + row * (BLOCK_SIZE + BLOCK_GAP)
This centers the seat grid within the canvas (PADDING on each side).
Block types:
- :seat for bookable seats
- :text for stair rows and other non-bookable dividers
Constant Summary collapse
- BLOCK_SIZE =
50- BLOCK_GAP =
10- PADDING =
200- HALF_PADDING =
PADDING / 2
Instance Method Summary collapse
- #call(vehicle_type:, schedule:, variant: nil, on_date: nil) ⇒ SpreeCmCommissioner::SeatLayout?
-
#initialize(integration:, sync_result: nil) ⇒ SyncSeatLayout
constructor
A new instance of SyncSeatLayout.
Constructor Details
#initialize(integration:, sync_result: nil) ⇒ SyncSeatLayout
Returns a new instance of SyncSeatLayout.
28 29 30 31 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_seat_layout.rb', line 28 def initialize(integration:, sync_result: nil) @integration = integration @sync_result = sync_result || SpreeCmCommissioner::Integrations::Base::SyncResult.new end |
Instance Method Details
#call(vehicle_type:, schedule:, variant: nil, on_date: nil) ⇒ SpreeCmCommissioner::SeatLayout?
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_seat_layout.rb', line 38 def call(vehicle_type:, schedule:, variant: nil, on_date: nil) return nil if vehicle_type.blank? || schedule.blank? external_seat_layout = fetch_external_seat_layout(schedule, on_date) return nil if external_seat_layout.blank? vehicle_seat_layout = sync_vehicle_type_template!(vehicle_type:, schedule:, external_seat_layout:) sync_trip_layout_if_needed!(vehicle_seat_layout:, variant:) if variant.present? vehicle_seat_layout rescue SpreeCmCommissioner::Integrations::ExternalClientError => e @sync_result.record_error(SpreeCmCommissioner::Integrations::SyncError.new("Failed to sync seat layout: #{e.}")) nil rescue StandardError => e @sync_result.record_error(StandardError.new("[VireakBuntham::SyncSeatLayout] #{e.}")) nil end |