Class: ExternalReservationsController

Inherits:
ApplicationV2Controller show all
Defined in:
app/controllers/external_reservations_controller.rb

Overview

This class should contain all external reservation, but currently there are external booking methods on #ReservationsController

Instance Method Summary collapse

Methods inherited from ApplicationV2Controller

#identity_cache_memoization

Methods included from LogrageCustomLogger

#append_info_to_payload

Instance Method Details

#bookObject

3rd step



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/external_reservations_controller.rb', line 68

def book
  reservation_params = params.require(:reservation)
  params[:channel] = @channel_id
  params[:medium] = 'Web'
  params[:reservation][:adult] = reservation_params[:party_size]
  params[:reservation][:kids] = 0
  params[:created_by] = :user
  params[:guest_user] = {
    name: reservation_params[:name],
    email: reservation_params[:email],
    phone: reservation_params[:phone],
  }

  params[:omise_token] = params[:reservation][:omise_token].presence || ''
  params[:group_booking] = false
  params[:business_booking] = false

  service = ReservationService::Create.new params
  service.omise_token = params[:omise_token]

  if service.execute
    render json: { data: ReservationSerializer.new(service.outcome),
                   landing_page_path: reservation_book_landing_page_url(service.outcome.id),
                   status: :ok }, status: :ok
  else
    render json: { messages: service.error_message_simple, status: :fail }, status: :unprocessable_entity
  end
end

#book_tableObject

2nd step



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
# File 'app/controllers/external_reservations_controller.rb', line 40

def book_table
  redirect_to(root_path) && return if browser.bot?

  # the javascript is not loaded
  if params[:restaurant_id] == 'undefined'
    redirect_back(fallback_location: root_path,
                  alert: 'The page is not loaded fully, please reload/refresh current page.') && return
  end

  @restaurant = Restaurant.fetch params.require(:restaurant_id)

  set_meta_tags noindex: true, nofollow: true,
                title: "Book Table at #{@restaurant.name}"

  @reservation = Reservation.new restaurant_id: @restaurant.id,
                                 date: params.require(:date),
                                 start_time: params.require(:start_time),
                                 party_size: params.require(:party_size)
  @end_time = params[:end_time].presence || HungryHub::Time.parse_to_db(params.require(:start_time),
                                                                        @restaurant.res_duration.to_i.minutes)
rescue ActionController::RedirectBackError
  redirect_to root_path
rescue StandardError => e
  APMErrorHandler.report e
  redirect_to root_path
end

#check_availabilityObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/controllers/external_reservations_controller.rb', line 97

def check_availability
  restaurant = Restaurant.fetch(params.require(:restaurant_id))
  date = Date.strptime(params.require(:date), '%Y-%m-%d')
  start_time = params.require(:start_time)
  party_size = if params[:party_size].present?
                 params.require(:party_size).to_i
               else
                 adult = params.require(:adult)
                 kids = params.require(:kids)
                 adult.to_i + kids.to_i
               end

  inv_checker = InvCheckerFactory.new(restaurant.id, restaurant.time_zone).create_inv_checker_service
  is_available = inv_checker.inventory_bookable?(date: date, start_time: start_time, adult: party_size, kids: 0)

  render json: { is_available: is_available, available_slots: inv_checker.error_message }, status: :ok
rescue NoMethodError, ArgumentError => e
  APMErrorHandler.report e
  render json: { is_available: false, available_slots: '' }, status: :unprocessable_entity
rescue StandardError => e
  APMErrorHandler.report e
  render json: { is_available: false, available_slots: '' }, status: :unprocessable_entity
end

#find_group_tableObject

1st step



28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/external_reservations_controller.rb', line 28

def find_group_table
  restaurant_group = RestaurantGroup.find params.require(:restaurant_group_id)
  set_meta_tags title: "Find Reservation Table at #{restaurant_group.name}",
                description: "Make Reservation at #{restaurant_group.restaurants.map(&:name).join(', ')}"
  @restaurants = {
    data: restaurant_group.restaurants,
    multiple: true,
  }
  render 'find_table'
end