Class: HhMenu::RestaurantsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- HhMenu::RestaurantsController
- Includes:
- ResponseCacheConcern
- Defined in:
- app/controllers/hh_menu/restaurants_controller.rb
Instance Method Summary collapse
- #add_on ⇒ Object
- #branch ⇒ Object
- #branch_name_lists ⇒ Object
- #branches ⇒ Object
- #detail ⇒ Object
- #index ⇒ Object
- #logo ⇒ Object
- #restaurant_branch_info ⇒ Object
- #restaurant_lists ⇒ Object
- #restaurant_name_lists ⇒ Object
Methods included from ResponseCacheConcern
Instance Method Details
#add_on ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/hh_menu/restaurants_controller.rb', line 28 def add_on restaurant_add_ons = AddOns::Restaurant.where(add_on_id: params[:add_on_id]) if params[:use_name].present? data_restaurants = [] restaurant_add_ons.each do |restaurant_add_on| data_restaurants << { id: restaurant_add_on.restaurant.id, name: restaurant_add_on.restaurant.name_en, } end data = data_restaurants else data = restaurant_add_ons.pluck(:restaurant_id) end render json: data end |
#branch ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/hh_menu/restaurants_controller.rb', line 60 def branch branch = Branch.find_by(id: params[:id]) if branch.present? render json: { id: branch.id, name: branch.name, } else render json: { success: false } end end |
#branch_name_lists ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'app/controllers/hh_menu/restaurants_controller.rb', line 99 def branch_name_lists branches_service = BranchNameListService.new(params) cache_key = branches_service.cache_key my_response_cache(cache_key, :json) do branches_service.call end end |
#branches ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'app/controllers/hh_menu/restaurants_controller.rb', line 72 def branches branches_service = BranchListService.new(params) cache_key = branches_service.cache_key my_response_cache(cache_key, :json) do branches_service.call end end |
#detail ⇒ Object
45 46 47 |
# File 'app/controllers/hh_menu/restaurants_controller.rb', line 45 def detail render json: Restaurant.fetch(params.require(:id)) end |
#index ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/hh_menu/restaurants_controller.rb', line 5 def index if params[:package_type] == 'pp' || params[:package_type] == 'HhPackage::Package::PartyPack' params[:package_type] = 'HhPackage::Package::PartyPack' elsif params[:package_type] == 'ayce' || params[:package_type] == 'HhPackage::Package::Ayce' params[:package_type] = 'HhPackage::Package::Ayce' end restaurant_packages = HhPackage::RestaurantPackage.where(package_id: params[:package_id], package_type: params[:package_type]) if params[:use_name].present? data_restaurants = [] restaurant_packages.each do |restaurant_package| data_restaurants << { id: restaurant_package.restaurant.id, name: restaurant_package.restaurant.name_en, } end data = data_restaurants else data = restaurant_packages.pluck(:restaurant_id) end render json: data end |
#logo ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/hh_menu/restaurants_controller.rb', line 49 def logo restaurant = Restaurant.find_by(id: params[:restaurant_id]) if restaurant.present? logo_url = determine_logo_url(restaurant) render json: logo_url else render json: { success: false } end end |
#restaurant_branch_info ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/controllers/hh_menu/restaurants_controller.rb', line 108 def restaurant_branch_info restaurant_ids = params[:restaurant_ids]&.split(',')&.map(&:strip)&.select do |id| id.match?(/\A\d+\z/) end&.map(&:to_i) || [] if restaurant_ids.empty? render json: [] return end # Fetch restaurants with their branch information restaurants = Restaurant.where(id: restaurant_ids).select(:id, :branch_id) data = restaurants.map do |restaurant| { id: restaurant.id, branch_id: restaurant.branch_id, } end render json: data end |
#restaurant_lists ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'app/controllers/hh_menu/restaurants_controller.rb', line 81 def restaurant_lists restaurants_service = RestaurantListService.new(params) cache_key = restaurants_service my_response_cache(cache_key, :json) do restaurants_service.call end end |
#restaurant_name_lists ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'app/controllers/hh_menu/restaurants_controller.rb', line 90 def restaurant_name_lists restaurants_service = RestaurantNameListService.new(params) cache_key = restaurants_service.cache_key my_response_cache(cache_key, :json) do restaurants_service.call end end |