Class: Api::Vendor::V1::GoogleReserve::AvailabilitiesController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ApplicationController
- BaseController
- Api::Vendor::V1::GoogleReserve::AvailabilitiesController
- Includes:
- Concerns::Helpers
- Defined in:
- app/controllers/api/vendor/v1/google_reserve/availabilities_controller.rb
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
-
#batch_availability_lookup ⇒ Object
“room_id”: “28883” } } }, ].
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 Method Details
#batch_availability_lookup ⇒ Object
“room_id”: “28883”
}
}
},
]
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/controllers/api/vendor/v1/google_reserve/availabilities_controller.rb', line 34 def batch_availability_lookup request_data = params.require(:availability).permit( :merchant_id, slot_time: [:availability_tag, :service_id, :start_sec, :duration_sec, { resource_ids: [:party_size, :room_id] }] ) restaurant_id = params[:merchant_id].split('-')[1] @restaurant = Restaurant.find(restaurant_id) inv_service = create_inventory_service(@restaurant) # Calculate start_times once to reuse start_times = calculate_start_times(request_data[:slot_time], @restaurant.time_zone) # party-size and date are pre-selected in E2E so they will be same for all start_times and slugs adult, kids, date = extract_party_size_and_date(request_data[:slot_time], @restaurant.time_zone) # on page refresh, google E2E sends all available room_ids in the request rest_package_ids = extract_unique_room_ids(request_data[:slot_time]) slugs_with_room_ids = validate_rest_packages_and_return_slugs_with_room_ids(rest_package_ids) slugs = extract_slugs(slugs_with_room_ids) # we call inventory service to get availability of all slugs and start_times in one go. inv_data = fetch_inventory_data(inv_service, date, start_times, adult, kids, slugs) # => [{:slug=>"1000-PP-1603948", :start_times=>[{"12:00"=>true}, {"12:15"=>true}, {"12:30"=>true}, {"12:45"=>true}, {"13:00"=>true}, {"13:15"=>true}, {"13:30"=>true}, {"13:45"=>true}, {"14:00"=>true}]}, # {:slug=>"1000-AY-1319935", :start_times=>[{"12:00"=>true}, {"12:15"=>true}, {"12:30"=>true}, {"12:45"=>true}, {"13:00"=>true}, {"13:15"=>true}, {"13:30"=>true}, {"13:45"=>true}, {"14:00"=>true}]}, # {:slug=>"1000-PP-8163330", :start_times=>[{"12:00"=>true}, {"12:15"=>true}, {"12:30"=>true}, {"12:45"=>true}, {"13:00"=>true}, {"13:15"=>true}, {"13:30"=>true}, {"13:45"=>true}, {"14:00"=>true}]}] # Modify inv_data in place by adding room_id add_room_ids_to_inventory_data(inv_data, slugs_with_room_ids) availability_matrix = {} Time.use_zone(@restaurant.time_zone) do inv_data.each do |data| room_id = data[:room_id].to_i availability_matrix[room_id] = {} data[:start_times].each do |time_hash| time_hash.each do |time_str, available| if available start_time = Time.zone.parse("#{date} #{time_str}").utc.to_i availability_matrix[room_id][start_time] = true end end end end end availability_response = request_data[:slot_time].map do |slot| room_id = slot[:resource_ids][:room_id].to_i start_sec = slot[:start_sec].to_i { available: availability_matrix.dig(room_id, start_sec) || false, slot_time: slot, } end response_payload = { slot_time_availability: availability_response } render json: response_payload rescue StandardError => e APMErrorHandler.report("#{self.class}: #{e.}", e: e) render_error_response(request_data[:slot_time]) end |