Class: Workarea::Api::Admin::PromoCodeListsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/workarea/api/admin/promo_code_lists_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user, #sort_direction, #sort_field

Instance Method Details

#bulkObject



283
284
285
286
287
288
289
290
# File 'app/controllers/workarea/api/admin/promo_code_lists_controller.rb', line 283

def bulk
  @bulk = Api::Admin::BulkUpsert.create!(
    klass: Pricing::Discount::CodeList,
    data: params[:promo_code_lists].map(&:to_h)
  )

  head :no_content
end

#createObject



106
107
108
109
110
111
112
113
# File 'app/controllers/workarea/api/admin/promo_code_lists_controller.rb', line 106

def create
  @promo_code_list = Pricing::Discount::CodeList.create!(params[:promo_code_list])
  respond_with(
    { promo_code_list: @promo_code_list },
    { status: :created,
    location: promo_code_list_path(@promo_code_list) }
  )
end

#destroyObject



292
293
294
295
# File 'app/controllers/workarea/api/admin/promo_code_lists_controller.rb', line 292

def destroy
  @promo_code_list.destroy
  head :no_content
end

#indexObject



97
98
99
100
101
102
103
104
# File 'app/controllers/workarea/api/admin/promo_code_lists_controller.rb', line 97

def index
  @promo_code_lists = Pricing::Discount::CodeList
                        .all
                        .order_by(sort_field => sort_direction)
                        .page(params[:page])

  respond_with promo_code_lists: @promo_code_lists
end

#showObject



245
246
247
# File 'app/controllers/workarea/api/admin/promo_code_lists_controller.rb', line 245

def show
  respond_with promo_code_list: @promo_code_list
end

#updateObject



249
250
251
252
# File 'app/controllers/workarea/api/admin/promo_code_lists_controller.rb', line 249

def update
  @promo_code_list.update_attributes!(params[:promo_code_list])
  respond_with promo_code_list: @promo_code_list
end