Class: Admin::AdaptivePointsController

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



30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/admin/adaptive_points_controller.rb', line 30

def create
  @adaptive_point = AdaptivePointsRatio.new(adaptive_points_ratio_params)
  if @adaptive_point.save
    data = AdaptivePointsSerializer.new(@adaptive_point)
    render json: { success: true, message: 'AdaptivePointsRatio successfully created.', data: data.as_json }
  else
    render action: 'index'
    format.json { render json: @adaptive_point.errors, status: :unprocessable_entity }
  end
end

#destroyObject



53
54
55
56
57
58
59
60
# File 'app/controllers/admin/adaptive_points_controller.rb', line 53

def destroy
  if @adaptive_point.destroy
    render json: { success: true }
  else
    render json: @adaptive_point.errors.full_messages.to_sentence,
           status: :unprocessable_entity
  end
end

#duplicateObject



62
63
64
65
66
# File 'app/controllers/admin/adaptive_points_controller.rb', line 62

def duplicate
  @adaptive_point.dup.save!
  data = AdaptivePointsSerializer.new(@adaptive_point)
  render json: { success: true, message: 'AdaptivePointsRatio successfully created duplicate.', data: data.as_json }
end

#editObject



41
# File 'app/controllers/admin/adaptive_points_controller.rb', line 41

def edit; end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/admin/adaptive_points_controller.rb', line 5

def index
  respond_to do |format|
    format.html do
      set_meta_tags title: 'Adaptive Points List'
    end

    format.json do
      adaptivepoints = AdaptivePointsRatio.all

      return unless stale_etag? adaptivepoints, template: false

      render json: adaptivepoints,
             meta: {
               total_adaptive_point: AdaptivePointsRatio.count,
             },
             each_serializer: AdaptivePointsSerializer,
             adapter: :json
    end
  end
end

#newObject



26
27
28
# File 'app/controllers/admin/adaptive_points_controller.rb', line 26

def new
  @adaptive_point = AdaptivePointsRatio.new
end

#searchObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/admin/adaptive_points_controller.rb', line 68

def search
  query_params = params.fetch(:adaptive_point, {}).permit(
    :id, :campaign_name, :is_active, :start_date, :end_date, :created_at,
    :campaign_type, :campaign_id, :resto_group_tag
  )

  adaptivepoints = AdaptivePointsRatio.all
  filter_data = AdaptivePointFilter.new(adaptivepoints, query_params)
  @adaptive_points = filter_data.filter
  render json: @adaptive_points.order("is_active DESC, COALESCE(end_date, '9999-12-31') ASC"),
         meta: {
           total_adaptive_point: @adaptive_points.count,
         },
         each_serializer: AdaptivePointsSerializer,
         adapter: :json
end

#updateObject



43
44
45
46
47
48
49
50
51
# File 'app/controllers/admin/adaptive_points_controller.rb', line 43

def update
  if @adaptive_point.update(adaptive_points_ratio_params)
    data = AdaptivePointsSerializer.new(@adaptive_point)
    render json: { success: true, message: 'AdaptivePointsRatio successfully updated.', data: data.as_json }
  else
    render action: 'index'
    format.json { render json: @adaptive_point.errors, status: :unprocessable_entity }
  end
end