Class: Admin::RestaurantAvailabilitiesController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ApplicationController
- BaseController
- Admin::RestaurantAvailabilitiesController
- Includes:
- PaginationParamConcern
- Defined in:
- app/controllers/admin/restaurant_availabilities_controller.rb
Overview
typed: ignore frozen_string_literal: true
Constant Summary
Constants inherited from BaseController
BaseController::INTERNAL_SERVER_ERROR_MESSAGE
Instance Attribute Summary collapse
-
#restaurant ⇒ Object
readonly
Returns the value of attribute restaurant.
Instance Method Summary collapse
Methods inherited from BaseController
#destroy_session, #identity_cache_memoization, #sign_in_page, #user_developer_session
Methods included from LogrageCustomLogger
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 included from UpdateLocaleConcern
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 ControllerHelpers
#check_boolean_param, #get_banners, #inventory_params, #reservation_params
Instance Attribute Details
#restaurant ⇒ Object (readonly)
Returns the value of attribute restaurant.
9 10 11 |
# File 'app/controllers/admin/restaurant_availabilities_controller.rb', line 9 def restaurant @restaurant end |
Instance Method Details
#index ⇒ Object
11 12 13 14 15 16 |
# File 'app/controllers/admin/restaurant_availabilities_controller.rb', line 11 def index @restaurants = Restaurant.active.not_expired.ids @hastags = RestaurantTag.where_category('hashtags') @cuisines = RestaurantTag.where_category('cuisine') @locations = RestaurantTag.where_category('location') end |
#search ⇒ Object
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 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/admin/restaurant_availabilities_controller.rb', line 18 def search restaurant = Restaurant.fetch params['restaurant_id'] if params['hashtag_id'].present? hashtag = RestaurantTag.find(params['hashtag_id']) return render json: { status: false } unless hashtag.restaurant_ids.include?(restaurant.id) end if params['loc_id'].present? location = RestaurantTag.find(params['loc_id']) return render json: { status: false } unless location.restaurant_ids.include?(restaurant.id) end if params['cuisine_id'].present? cuisine = RestaurantTag.find(params['cuisine_id']) return render json: { status: false } unless cuisine.restaurant_ids.include?(restaurant.id) end if params['restaurant_name'].present? restaurants = Restaurant.joins(:translations).where('LOWER(restaurant_translations.name) LIKE ?', "%#{params['restaurant_name']}%").group('restaurants.id') return render json: { status: false } unless restaurants.ids.include?(restaurant.id) end if params['service_type'].present? if params['service_type'] == 'dine_in' return render json: { status: false } unless restaurant.is_dine_in? else return render json: { status: false } unless restaurant.is_take_away? end end is_availability_full = params['is_availability_full'] time_zone = restaurant.time_zone inv_checker = InvCheckerFactory.new(restaurant.id, time_zone).create_inv_checker_service if params['service_type'].present? if params['service_type'] == 'dine_in' inv_checker.for_delivery = false inv_checker.for_dine_in = true else inv_checker.for_delivery = true inv_checker.for_dine_in = false end end is_available = case params['pick_date'] when 'with_time' inv_checker.bookable?(date: params['start_date'].to_date, start_time: params['start_time'], adult: params['adults'], kids: params['kids']) when 'single' inv_checker.find_available_single_date(date: params['start_date'], adult: params['adults'], kids: params['kids']) else inv_checker.find_available_dates(start_date: params['start_date'], end_date: params['end_date'], adult: params['adults'], kids: params['kids']) end is_available = case is_available when TrueClass, FalseClass is_available when Hash is_available['availability'] when Array is_available.select { |result| result['availability'] }.present? else raise NotImplementedError end if is_availability_full.to_s == 'false' return render json: { status: false } unless is_available elsif is_available return render json: { status: false } end render json: { status: true, id: restaurant.id, name: restaurant.name, service_type: get_service_type(restaurant), } end |