Class: Admin::RwgE2eRestaurantsController

Inherits:
BaseController show all
Defined in:
app/controllers/admin/rwg_e2e_restaurants_controller.rb

Constant Summary

Constants inherited from BaseController

BaseController::INTERNAL_SERVER_ERROR_MESSAGE

Instance Method Summary collapse

Methods inherited from BaseController

#destroy_session, #identity_cache_memoization, #sign_in_page, #user_developer_session

Methods included from LogrageCustomLogger

#append_info_to_payload

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

#setup_locale

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

#indexObject



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
# File 'app/controllers/admin/rwg_e2e_restaurants_controller.rb', line 5

def index
  type = params[:type]

  if type.blank?
    respond_to do |format|
      format.html { render 'index' }
      format.json { render json: { restaurants: [] } }
    end
  else
    restaurants = type == 'active' ? get_active_e2e_restaurants_list : get_inactive_e2e_restaurants_list
    serialized_restaurants = ActiveModelSerializers::SerializableResource.new(
      restaurants, each_serializer: GoogleE2eRestaurantSerializer
    )

    render json: {
      restaurants: serialized_restaurants,
      active_restaurant_e2e_count: count_restaurants(e2e: true, active: true),
      inactive_restaurant_e2e_count: 0,
      opted_out_restaurant_e2e_count: count_restaurants(e2e: true, active: true, agreement_status: :opted_out),
      active_restaurant_count: count_restaurants(e2e: false, active: true),
      opted_out_restaurant_count: count_restaurants(e2e: false, active: true, agreement_status: :opted_out),
      inactive_restaurant_count: 0,
    }
  end
end

#toggle_agreement_statusObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/admin/rwg_e2e_restaurants_controller.rb', line 37

def toggle_agreement_status
  restaurant_id = params[:id].to_i
  google_reserve = GoogleReserve.find_by(restaurant_id: restaurant_id)

  if google_reserve.nil?
    render json: { success: false, error: 'Google Reserve not found' }, status: :not_found
    return
  end

  new_status = google_reserve.active? ? :opted_out : :active
  google_reserve.update!(agreement_status: new_status)

  render json: {
    success: true,
    agreement_status: google_reserve.agreement_status,
    agreement_status_label: google_reserve.agreement_status == 'active' ? 'Enabled' : 'Disabled',
  }
rescue StandardError => e
  render json: { success: false, error: e.message }, status: :unprocessable_entity
end

#updateObject



31
32
33
34
35
# File 'app/controllers/admin/rwg_e2e_restaurants_controller.rb', line 31

def update
  restaurant_ids = params.fetch(:restaurants, {}).fetch(:ids, []).reject(&:blank?).map(&:to_i)
  save_restaurant_lists(restaurant_ids)
  render json: { success: true }
end