Class: Spree::Api::StoresController

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

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  authorize! :create, Store
  @store = Spree::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



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

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

#indexObject



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

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

#showObject



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

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

#updateObject



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

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