Class: Api::Vendor::V1::Getyourguide::ReservesController

Inherits:
BaseController show all
Includes:
Concerns::ReservationUtils, Concerns::Helpers
Defined in:
app/controllers/api/vendor/v1/getyourguide/reserves_controller.rb

Instance Attribute Summary

Attributes inherited from BaseController

#vendor

Instance Method Summary collapse

Methods inherited from BaseController

#authentication

Methods included from ResponseCacheConcern

#my_response_cache

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

#append_info_to_payload

Methods included from ControllerHelpers

#check_boolean_param, #get_banners, #inventory_params, #reservation_params

Instance Method Details

#cancelObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/api/vendor/v1/getyourguide/reserves_controller.rb', line 54

def cancel
  # Validate required params structure
  params.require(:data)
  params[:data].require(:reservationReference)

  # Build permitted params
  permitted_params = params.permit(data: [:reservationReference])

  reservation = Reservation.find_by(id: permitted_params[:data][:reservationReference])
  return render_invalid_reservation(reservation&.id) if reservation.blank?

  # since temporary reservation is cancelled by worker every 10 minutes
  render_empty_response
end

#createObject



8
9
10
11
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
45
46
47
48
49
50
51
# File 'app/controllers/api/vendor/v1/getyourguide/reserves_controller.rb', line 8

def create
  params.require(:data)
  %i[gygBookingReference productId dateTime bookingItems gygActivityReference].each do |key|
    params[:data].require(key)
  end
  params.require(:data)[:bookingItems].each { |item| %i[category count].each { |k| item.fetch(k) } }

  @permitted_params = params.permit(
    data: [
      :gygBookingReference, :productId, :dateTime, :gygActivityReference,
      { bookingItems: %i[category count] }
    ],
  )

  @vendor_reference_id = permitted_params.dig(:data, :gygBookingReference)
  BUSINESS_LOGGER.set_business_context({ vendor_reference_id: vendor_reference_id,
                                         vendor_name: ApiVendorV1::Constants::GET_YOUR_GUIDE_VENDOR_NAME })
  VendorLogger.log_event(:request, params[:route], payload: params)

  return render_invalid_ticket_category unless valid_category?(permitted_params.dig(:data, :bookingItems, 0,
                                                                                    :category))

  @gyg_product_id = permitted_params.dig(:data, :productId).to_s
  @gyg_option_id = permitted_params.dig(:data, :gygActivityReference)
  return render_invalid_product unless load_restaurant_and_package(gyg_product_id, gyg_option_id)

  datetime = DateTime.parse(permitted_params[:data][:dateTime])
  today = Time.now_in_tz(restaurant.time_zone)
  return render_validation_failure('The requested reservation date is in the past') if datetime < today

  service = ReservationService::InitFactory.build(build_permitted_params(datetime))
  result = service.create_temporary

  if result.success?
    reservation_id = result&.data&.id
    BUSINESS_LOGGER.set_business_context({ reservation_id: reservation_id })
    BUSINESS_LOGGER.info("#{self.class}##{__method__}: tmp. reservation created successfully")
    render_successful_reservation(reservation_id, service)
  else
    render_no_availability(service.error_message_simple)
  end
rescue StandardError => e
  render_no_availability(e.message, backtrace: e.backtrace&.last(5))
end