Class: WidgetsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/widgets_controller.rb

Defined Under Namespace

Classes: GoToRestaurantPage, RestaurantNotFound

Instance Method Summary collapse

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

#bookObject



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
96
97
98
99
100
101
102
# File 'app/controllers/widgets_controller.rb', line 70

def book
  omise_token = params[:reservation][:omise_token].presence || ''
  special_request = "#{params[:reservation][:special_request]} #{params[:reservation][:additional_special_request]}".strip.presence || nil
  res_params = {
    reservation: {
      date: params[:reservation][:date],
      start_time: params[:reservation][:start_time],
      adult: params[:reservation][:adult].presence || params[:reservation][:party_size],
      kids: params[:reservation][:kids],
      special_request: special_request,
      restaurant_id: params[:reservation][:restaurant_id],
    },
    guest_user: {
      name: params[:reservation][:name],
      email: params[:reservation][:email],
      phone: params[:reservation][:phone],
    },
    channel: params[:reservation][:channel].to_i,
    medium: 'Web',
    created_by: :user,
    group_booking: false,
    business_booking: false,
    omise_token: omise_token
  }

  service = ReservationService::Create.new(res_params)

  if service.execute
    render json: { data: ReservationSerializer.new(service.outcome), status: :ok }, status: 200
  else
    render json: { messages: service.error_message_simple, status: :fail }, status: 422
  end
end

#book_tableObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/widgets_controller.rb', line 44

def book_table
  respond_to do |format|
    format.html do
      _setup_widget
      set_seo_tags
      fresh_when [@widget.cache_key, restaurant.cache_key]
    end
    format.json do
      if stale? restaurant.cache_key
        render json: restaurant, serializer: RestaurantWidgetSerializer
      end
    end
  end
end

#book_table_groupObject



59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/widgets_controller.rb', line 59

def book_table_group
  _setup_widget

  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 = restaurant_group.restaurants
  render 'book_table'
end

#check_require_credit_cardObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/controllers/widgets_controller.rb', line 104

def check_require_credit_card
  render(nothing: true, status: 200, content_type: 'text/html') && return if browser.bot?

  @restaurant = Restaurant.find params[:id]
  channel = Channel.find_by uri_name: params.require(:channel)
  party_size = params[:party_size] || (params.require(:adult).to_i + params.require(:kids).to_i)

  if channel && Channel.require_cc?(channel.channel_id) && @restaurant.require_credit_card? &&
      @restaurant.party_require_credit_card?(party_size, channel.cc_charge_type)
    render json: { cc: true, charge: (channel.cached_tag_list.include?(Channel::HOLD_CC) ? 'hold' : 'immediately') }
  else
    render json: { cc: false }
  end
end