Class: Api::Vendor::V1::GoogleReserve::BookingsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ApplicationController
- BaseController
- Api::Vendor::V1::GoogleReserve::BookingsController
- Includes:
- Concerns::ErrorResponses, Concerns::Helpers
- Defined in:
- app/controllers/api/vendor/v1/google_reserve/bookings_controller.rb
Instance Attribute Summary collapse
-
#reservation ⇒ Object
readonly
Returns the value of attribute reservation.
-
#restaurant ⇒ Object
readonly
Returns the value of attribute restaurant.
-
#restaurant_package ⇒ Object
readonly
Returns the value of attribute restaurant_package.
-
#vendor_reservation ⇒ Object
readonly
Returns the value of attribute vendor_reservation.
Attributes inherited from BaseController
Instance Method Summary collapse
-
#create ⇒ Object
POST /v3/create_booking.
-
#update ⇒ Object
POST /v3/update_booking.
Methods included from ResponseCacheConcern
Methods inherited from ApplicationController
#after_sign_in_path_for, #after_sign_out_path_for, #default_url_options, #identity_cache_memoization, #render_not_found, #routing_error, search_params_key=
Methods included from LogrageCustomLogger
Methods included from ControllerHelpers
#check_boolean_param, #get_banners, #inventory_params, #reservation_params
Instance Attribute Details
#reservation ⇒ Object (readonly)
Returns the value of attribute reservation.
9 10 11 |
# File 'app/controllers/api/vendor/v1/google_reserve/bookings_controller.rb', line 9 def reservation @reservation end |
#restaurant ⇒ Object (readonly)
Returns the value of attribute restaurant.
9 10 11 |
# File 'app/controllers/api/vendor/v1/google_reserve/bookings_controller.rb', line 9 def restaurant @restaurant end |
#restaurant_package ⇒ Object (readonly)
Returns the value of attribute restaurant_package.
9 10 11 |
# File 'app/controllers/api/vendor/v1/google_reserve/bookings_controller.rb', line 9 def restaurant_package @restaurant_package end |
#vendor_reservation ⇒ Object (readonly)
Returns the value of attribute vendor_reservation.
9 10 11 |
# File 'app/controllers/api/vendor/v1/google_reserve/bookings_controller.rb', line 9 def vendor_reservation @vendor_reservation end |
Instance Method Details
#create ⇒ Object
POST /v3/create_booking
12 13 14 15 16 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 |
# File 'app/controllers/api/vendor/v1/google_reserve/bookings_controller.rb', line 12 def create VendorLogger.log_event(:request, params[:route], payload: params) return render_cause_unspecified('Vendor Not Found') if vendor.blank? channel = find_channel_id! return render_cause_unspecified('Channel Not Found') if channel.blank? safe_create_params = create_params room_id = safe_create_params.dig(:slot, :resources, :room_id) @restaurant_package = restaurant.google_reserve_packages.find_by(restaurant_package_id: room_id)&.restaurant_package return render_cause_unspecified('Room Not Found', restaurant.id, nil, room_id) if restaurant_package.blank? res_params = prepare_reservation_sub_params(safe_create_params) adult = res_params[:adult] kids = res_params[:kids] user_params = prepare_user_params(safe_create_params) rp_params = prepare_restaurant_package_params(adult, kids) final_reservation_params = create_reservation_params(channel.channel_id, res_params, user_params, rp_params) service = ReservationService::Create.new(final_reservation_params) if service.execute @reservation = service.outcome store_vendor_data(safe_create_params) render_create_booking_response(safe_create_params) else render_slot_unavailable(service.) end rescue StandardError => e cancel_create_error_reservation if reservation.present? render_slot_unavailable(e., e.backtrace) end |
#update ⇒ Object
POST /v3/update_booking
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/api/vendor/v1/google_reserve/bookings_controller.rb', line 47 def update BUSINESS_LOGGER.set_business_context({ reservation_id: @reservation&.id }) VendorLogger.log_event(:request, params[:route], payload: params) return render_cause_unspecified('Vendor Not Found') if vendor.blank? channel = find_channel_id! return render_cause_unspecified('Channel Not Found') if channel.blank? safe_update_params = update_params if safe_update_params[:status] == ApiVendorV1::Constants::RWG_CANCELED BUSINESS_LOGGER.info('Cancel reservation request') cancel_reservation(safe_update_params) else BUSINESS_LOGGER.info('Update reservation request') update_reservation(safe_update_params) # Sync updated reservation to partner portal begin @reservation.trigger_priority_sync rescue StandardError => e APMErrorHandler.report('Failed to sync Google Reserve update', { reservation_id: @reservation.id, error_message: e., exception: e, }) end end rescue StandardError => e render_slot_unavailable(e., e.backtrace) end |