Class: RestaurantService::CreateFromApi
- Inherits:
-
ApplicationService
- Object
- ApplicationService
- RestaurantService::CreateFromApi
- Includes:
- ElasticAPM::SpanHelpers
- Defined in:
- app/services/restaurant_service/create_from_api.rb
Constant Summary collapse
- PARKING_ENABLED =
Constants for parking virtual attribute
1- PARKING_DISABLED =
0
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Attributes inherited from ApplicationService
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(params:) ⇒ CreateFromApi
constructor
A new instance of CreateFromApi.
Methods inherited from ApplicationService
Constructor Details
#initialize(params:) ⇒ CreateFromApi
Returns a new instance of CreateFromApi.
13 14 15 |
# File 'app/services/restaurant_service/create_from_api.rb', line 13 def initialize(params:) @params = params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
11 12 13 |
# File 'app/services/restaurant_service/create_from_api.rb', line 11 def params @params end |
Instance Method Details
#execute! ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 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 67 68 69 |
# File 'app/services/restaurant_service/create_from_api.rb', line 17 def execute! restaurant = nil staff = nil ActiveRecord::Base.transaction do restaurant = create_restaurant! (restaurant) # Create staff account automatically from owner credentials # The owner becomes the first staff member with owner role # If staff creation fails, entire transaction (including restaurant) will be rolled back staff = begin create_staff_from_owner!(restaurant) rescue ActiveRecord::RecordInvalid => e # Report staff-specific validation errors with context APMErrorHandler.report(e, context: { restaurant_id: restaurant.id, owner_id: restaurant.owner.id, owner_email: restaurant.owner.email, }) raise ActiveRecord::RecordInvalid.new(e.record), "Staff account creation failed: #{e.}" rescue StandardError => e # Report other staff creation errors APMErrorHandler.report(e, context: { restaurant_id: restaurant.id, owner_id: restaurant.owner.id, owner_email: restaurant.owner.email, }) raise end restaurant.touch end ServiceResult.new( data: { restaurant: restaurant, owner: restaurant.owner, staff: staff, }, message: 'Restaurant created successfully', ) rescue StandardError => e HH_LOGGER.error('Restaurant creation failed', { error: e., params: params, }) APMErrorHandler.report(e, context: { params: params }) ServiceResult.new( errors: [e.], message: "Failed to create restaurant: #{e.}", ) end |