Class: Spree::Api::V1::StockLocationsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/v1/stock_locations_controller.rb

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Methods inherited from BaseController

#content_type, #permitted_line_item_attributes

Methods included from ControllerSetup

included

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
# File 'app/controllers/spree/api/v1/stock_locations_controller.rb', line 15

def create
  authorize! :create, StockLocation
  @stock_location = StockLocation.new(stock_location_params)
  if @stock_location.save
    respond_with(@stock_location, status: 201, default_template: :show)
  else
    invalid_resource!(@stock_location)
  end
end

#destroyObject



34
35
36
37
38
# File 'app/controllers/spree/api/v1/stock_locations_controller.rb', line 34

def destroy
  authorize! :destroy, stock_location
  stock_location.destroy
  respond_with(stock_location, status: 204)
end

#indexObject



5
6
7
8
9
# File 'app/controllers/spree/api/v1/stock_locations_controller.rb', line 5

def index
  authorize! :read, StockLocation
  @stock_locations = StockLocation.accessible_by(current_ability, :read).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
  respond_with(@stock_locations)
end

#showObject



11
12
13
# File 'app/controllers/spree/api/v1/stock_locations_controller.rb', line 11

def show
  respond_with(stock_location)
end

#updateObject



25
26
27
28
29
30
31
32
# File 'app/controllers/spree/api/v1/stock_locations_controller.rb', line 25

def update
  authorize! :update, stock_location
  if stock_location.update_attributes(stock_location_params)
    respond_with(stock_location, status: 200, default_template: :show)
  else
    invalid_resource!(stock_location)
  end
end