Class: Admin::RestaurantGroupsController

Inherits:
BaseController show all
Defined in:
app/controllers/admin/restaurant_groups_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

#createObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/admin/restaurant_groups_controller.rb', line 58

def create
  ActiveRecord::Base.transaction do
    @restaurant_group = RestaurantGroup.new restaurant_group_parameter

    if @restaurant_group.save
      members_updated?
      redirect_to(admin_restaurant_group_path(@restaurant_group))
    else
      flash.now[:alert] = @restaurant_group.errors.full_messages.to_sentence
      render 'new'
    end
  rescue ActiveRecord::Rollback => e
    flash.now[:alert] = e.message
    render 'new'
  end
end

#destroyObject



77
78
79
80
81
82
83
# File 'app/controllers/admin/restaurant_groups_controller.rb', line 77

def destroy
  if @restaurant_group.destroy
    redirect_to admin_restaurant_groups_path, notice: "#{@restaurant_group.name} deleted"
  else
    redirect_to admin_restaurant_groups_path, notice: "Failed delete #{@restaurant_group.name}"
  end
end

#editObject



34
# File 'app/controllers/admin/restaurant_groups_controller.rb', line 34

def edit; end

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/admin/restaurant_groups_controller.rb', line 9

def index
  respond_to do |format|
    format.html
    format.json do
      restaurant_groups = RestaurantGroup.order('id DESC')
      if params[:queries].present?
        q = params[:queries]
        if q[:search].present?
          restaurant_groups = restaurant_groups.where('lower(name) LIKE ?',
                                                      "%#{q[:search].downcase}%")
        end
      end

      per_page = params[:perPage].present? ? params[:perPage].to_i : 100
      @pagy, @restaurant_groups = pagy restaurant_groups, items: per_page
      etag = CityHash.hash32([self.class.to_s, @restaurant_groups.cache_key])
      return unless stale?(etag: etag, template: false)
    end
  end
end

#login_partner_groupObject



90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/admin/restaurant_groups_controller.rb', line 90

def 
  restaurant_group = RestaurantGroup.find(params.require(:restaurant_group_id))
  restaurant_ids = restaurant_group.restaurants.pluck(:id)
  service = StaffService::TemporaryAccess.new(restaurant_ids, restaurant_group)
  service.call
  if service.success?
    render json: { success: true, data: service.result }
  else
    render json: { success: false, message: service.errors.full_messages.uniq.to_sentence }
  end
end

#login_to_group_dashboardObject



85
86
87
88
# File 'app/controllers/admin/restaurant_groups_controller.rb', line 85

def 
   :dashboard_v2_restaurant_group, RestaurantGroup.find(params.require(:restaurant_group_id))
  redirect_to dashboard_v2_group_root_path
end

#newObject



30
31
32
# File 'app/controllers/admin/restaurant_groups_controller.rb', line 30

def new
  @restaurant_group = RestaurantGroup.new
end

#showObject



75
# File 'app/controllers/admin/restaurant_groups_controller.rb', line 75

def show; end

#updateObject



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

def update
  ActiveRecord::Base.transaction do
    @restaurant_group.assign_attributes(restaurant_group_parameter)

    if @restaurant_group.save
      if members_updated?
        redirect_to admin_restaurant_group_path(@restaurant_group),
                    notice: 'Restaurant Group updated successfully'
      else

        raise ActiveRecord::Rollback, @restaurant_group.errors.full_messages.to_sentence
      end
    else
      raise ActiveRecord::Rollback, @restaurant_group.errors.full_messages.to_sentence
    end

  rescue ActiveRecord::Rollback => e
    flash.now[:alert] = e.message
    render 'edit'
  end
end