Class: V2Users::RestaurantsController

Inherits:
BaseController show all
Includes:
AdminHelper, ImageHelper, ManageRestaurantsController
Defined in:
app/controllers/v2_users/restaurants_controller.rb

Overview

Accessible restaurant data by public

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ImageHelper

#fix_image_url

Methods included from ManageRestaurantsController

#create, #cuisines, #owner_get_ready, #sign_up_premium, #tag_groups

Methods included from AdminHelper

#dynamic_pricings_formatter, #link_to_admin_reservations_path_by_id, #link_to_admin_restaurants_path_by_id, #link_to_log, #optional_locales, #optional_locales_with_labels, #staff_signed_in?

Methods inherited from BaseController

#activate_cache?, #current_user_ck, default_url_options, #identity_cache_memoization, #set_csrf_token

Methods included from LogrageCustomLogger

#append_info_to_payload

Methods included from UpdateLocaleConcern

#setup_locale

Methods included from ResponseCacheConcern

#my_response_cache

Methods inherited from ApplicationV2Controller

#identity_cache_memoization

Instance Attribute Details

#restaurantObject (readonly)

Returns the value of attribute restaurant.



11
12
13
# File 'app/controllers/v2_users/restaurants_controller.rb', line 11

def restaurant
  @restaurant
end

Instance Method Details



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
# File 'app/controllers/v2_users/restaurants_controller.rb', line 42

def menus
  etag = CityHash.hash32([restaurant.cache_key, params])
  my_response_cache("#{self.class}:menus:#{etag}", :html) do
    ids = if params[:ids].present?
            params[:ids].respond_to?(:values) ? params[:ids].values : params[:ids]
          elsif params[:id].present?
            params[:id].respond_to?(:values) ? params[:id].values : params[:id]
          elsif params[:package_ids]
            params[:package_ids].respond_to?(:values) ? params[:package_ids].values : params[:package_ids]
          else
            restaurant.restaurant_package_ids
          end

    rest_packs = HhPackage::RestaurantPackage.fetch_multi(Array.wrap(ids))

    raise ActiveRecord::RecordNotFound if rest_packs.blank?

    menu_type = rest_packs.map do |rest_pack|
      rest_pack.fetch_package&.menu_type
    end.compact.uniq.last

    view_name = case menu_type.to_s.to_sym
                when :imenupro
                  @menus = build_imenupro_menus(rest_packs)
                  'menus_imenupro'
                when :img
                  @menus = build_image_menus(rest_packs)
                  'menus_img'
                when :img_and_imenupro
                  if params.key? :imenupro_only
                    @menus = build_imenupro_menus(rest_packs)
                    'menus_imenupro'
                  else
                    @imenupro_menus = build_imenupro_menus(rest_packs)
                    @img_menus = build_image_menus(rest_packs)
                    'menus_img_and_imenupro'
                  end
                else
                  'blank_menu'
                end
    render_to_string(view_name, layout: nil)
  end
end

#preview_menu_from_emailObject

it contains imenu pro iframe 'View Menu' button in confirmation email refers to this page



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/controllers/v2_users/restaurants_controller.rb', line 88

def preview_menu_from_email
  return unless activate_cache? etag: @restaurant.cache_key, last_modified: @restaurant.updated_at

  if @restaurant.active && @restaurant.any_offers?
    @menus = @restaurant.restaurant_packages.map(&:fetch_package).map do |package|
      if package.menu_type.to_s.to_sym == :imenupro
        package.menu_links.map do |link|
          id = link.split('!').last
          { id: id, link: link, type: :imenupro }
        end
      else
        package.package_menus.order_by_rank.map do |menu|
          {
            url: menu.image_url,
            type: :img
          }
        end
      end
    end.flatten
  elsif @restaurant.imenu_pro_link.present?
    @menu = @restaurant.imenu_pro_link
  end
end

#searchObject



34
35
36
# File 'app/controllers/v2_users/restaurants_controller.rb', line 34

def search
  redirect_to_new_ui("restaurants/search")
end

#showObject



38
39
40
# File 'app/controllers/v2_users/restaurants_controller.rb', line 38

def show
  redirect_to_new_ui("restaurants/#{params[:id]}")
end