Class: Admin::Restaurants::ReservationsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ApplicationController
- BaseController
- Admin::Restaurants::ReservationsController
- Defined in:
- app/controllers/admin/restaurants/reservations_controller.rb
Constant Summary
Constants inherited from BaseController
BaseController::INTERNAL_SERVER_ERROR_MESSAGE
Instance Method Summary collapse
-
#clear_cache ⇒ Object
method clear_cache with POST.
- #index ⇒ Object
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 Method Details
#clear_cache ⇒ Object
method clear_cache with POST
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 |
# File 'app/controllers/admin/restaurants/reservations_controller.rb', line 36 def clear_cache date = params.require(:date).to_date # update inventory total booked seat first, then clear cache @restaurant.inventories.where(date: date).find_each do |inventory| inventory.calc_total_booked_seat inventory.save! end Karafka.producer.produce_sync( topic: EVENTS::INVENTORY::CACHE::TOPIC, payload: { event_type: EVENTS::INVENTORY::CACHE::TYPES::RESET_CACHE, restaurant_id: @restaurant.id, reset_mode: true, restaurant_level: true, dates: [date], triggered_at: Time.current.to_s, # Debug attributes trigger_source: self.class.name, trigger_method: 'clear_cache', trigger_context: { admin_action: true, controller: 'admin/restaurants/reservations', action: 'clear_cache', user_agent: request.user_agent&.truncate(100), ip_address: request.remote_ip, }, }.to_json, ) redirect_back fallback_location: admin_restaurant_reservations_path(@restaurant, date: date), notice: "Cache cleared for #{@restaurant.name} on #{date}" end |
#index ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/admin/restaurants/reservations_controller.rb', line 4 def index # if there is no params[:date], then show calendar UI if params[:date].blank? @reservations = @restaurant.reservations.order(:start_time) title: "Reservations for #{@restaurant.name}" elsif params[:start_time].present? && params[:date].present? @date = date = params[:date].to_date @start_time = start_time = params[:start_time] title: "Reservations by time & date for #{@restaurant.name} on #{date} at #{start_time}" @reservations = @restaurant.reservations.where(active: true, start_time: @start_time, date: date).order(:start_time) # affecting reservations are those that overlap with the given start_time @affecting_reservations = @restaurant.reservations.where(active: true, date: date).where.not(id: @reservations.pluck(:id)). where('start_time < ? AND end_time > ?', @start_time, @start_time). or(@restaurant.reservations.where(active: true, date: date).where.not(id: @reservations.pluck(:id)). where('start_time < ? AND end_time > ?', @start_time, @start_time)) @inventory = @restaurant.inventories.find_by(date: params[:date], start_time: params[:start_time]) elsif params[:date].present? && params[:start_time].blank? title: "Reservations by date for #{@restaurant.name} on #{params[:date]}" # if there is a date, then show reservations for that date @date = Date.parse(params[:date]) @reservations = @restaurant.reservations.where(date: @date, active: true).where(start_time: @date.all_day) else raise NotImplementedError, 'Invalid parameters' end end |