Class: SpreeCmCommissioner::Trips::CreateSingleLeg
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Trips::CreateSingleLeg
- Includes:
- Spree::ServiceModule::Base, SpreeCmCommissioner::Transit::TripHelper
- Defined in:
- app/services/spree_cm_commissioner/trips/create_single_leg.rb
Overview
Service class responsible for creating a single-leg trip in the booking system. Orchestrates the creation of product variant, trip record, stops, calendar, and inventory.
Instance Method Summary collapse
-
#call(vendor:, trip_form:) ⇒ Object
Main service method that validates the trip form and orchestrates creation.
Methods included from SpreeCmCommissioner::Transit::TripHelper
#minutes_since_midnight, #normalize_date, #parse_date, #parse_time
Instance Method Details
#call(vendor:, trip_form:) ⇒ Object
Main service method that validates the trip form and orchestrates creation. Creates variant, trip, calendar, and inventory within a database transaction. Returns success with created objects or failure with error message on exceptions.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/services/spree_cm_commissioner/trips/create_single_leg.rb', line 12 def call(vendor:, trip_form:) return failure(nil, trip_form.errors..to_sentence) unless trip_form.valid_data? ApplicationRecord.transaction do variant = create_variant!(vendor, trip_form) trip = create_trip!(vendor, trip_form, variant) assign_blocks_to_variant!(trip, variant) calendar = setup_calendar!(variant.product, trip_form.service_calendar) generate_inventory!(variant) success(trip: trip, variant: variant, calendar: calendar) end rescue StandardError => e CmAppLogger.error( label: 'SpreeCmCommissioner::Trips::CreateSingleLeg#call', data: { error_class: e.class.name, error_message: e. } ) failure(nil, e.) end |