Class: Spree::Api::V1::StoresController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/v1/stores_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



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

def create
  authorize! :create, Store
  @store = Store.new(store_params)
  @store.code = params[:store][:code]
  if @store.save
    respond_with(@store, status: 201, default_template: :show)
  else
    invalid_resource!(@store)
  end
end

#destroyObject



38
39
40
41
42
# File 'app/controllers/spree/api/v1/stores_controller.rb', line 38

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

#indexObject



7
8
9
10
11
# File 'app/controllers/spree/api/v1/stores_controller.rb', line 7

def index
  authorize! :read, Store
  @stores = Store.accessible_by(current_ability, :read).all
  respond_with(@stores)
end

#showObject



33
34
35
36
# File 'app/controllers/spree/api/v1/stores_controller.rb', line 33

def show
  authorize! :read, @store
  respond_with(@store)
end

#updateObject



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

def update
  authorize! :update, @store
  if @store.update_attributes(store_params)
    respond_with(@store, status: 200, default_template: :show)
  else
    invalid_resource!(@store)
  end
end