Class: Spree::Api::CustomerReturnsController

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

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
# File 'app/controllers/spree/api/customer_returns_controller.rb', line 11

def create
  authorize! :create, CustomerReturn
  @customer_return = CustomerReturn.create(customer_return_params)
  if @customer_return.save
    respond_with(@customer_return, status: 201, default_template: :show)
  else
    invalid_resource!(@customer_return)
  end
end

#indexObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/spree/api/customer_returns_controller.rb', line 21

def index
  authorize! :index, CustomerReturn

  @customer_returns = @order.
    customer_returns.
    accessible_by(current_ability).
    ransack(params[:q]).
    result

  @customer_returns = paginate(@customer_returns)

  respond_with(@customer_returns)
end

#newObject



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

def new
  authorize! :new, CustomerReturn
end

#showObject



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

def show
  authorize! :show, CustomerReturn
  @customer_return = @order.customer_returns.accessible_by(current_ability, :show).find(params[:id])
  respond_with(@customer_return)
end

#updateObject



45
46
47
48
49
50
51
52
53
# File 'app/controllers/spree/api/customer_returns_controller.rb', line 45

def update
  authorize! :update, CustomerReturn
  @customer_return = @order.customer_returns.accessible_by(current_ability, :update).find(params[:id])
  if @customer_return.update(customer_return_params)
    respond_with(@customer_return.reload, default_template: :show)
  else
    invalid_resource!(@customer_return)
  end
end