Class: Spree::Api::V1::UsersController

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



32
33
34
35
36
37
38
39
40
# File 'app/controllers/spree/api/v1/users_controller.rb', line 32

def create
  authorize! :create, Spree.user_class
  @user = Spree.user_class.new(user_params)
  if @user.save
    respond_with(@user, status: 201, default_template: :show)
  else
    invalid_resource!(@user)
  end
end

#destroyObject



51
52
53
54
55
# File 'app/controllers/spree/api/v1/users_controller.rb', line 51

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

#indexObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/spree/api/v1/users_controller.rb', line 7

def index
  @users = Spree.user_class.accessible_by(current_ability, :show)

  if params[:ids]
    @users = @users.where(id: params[:ids])
  elsif params[:q]
    users_with_ship_address = @users.with_address(params[:q][:ship_address_firstname_start])
    users_with_bill_address = @users.with_address(params[:q][:ship_address_firstname_start], :bill_address)

    users_with_addresses_ids = (users_with_ship_address.ids + users_with_bill_address.ids).compact.uniq
    @users = @users.with_email_or_addresses_ids(params[:q][:email_start], users_with_addresses_ids)
  end

  @users = @users.page(params[:page]).per(params[:per_page])
  expires_in 15.minutes, public: true
  headers['Surrogate-Control'] = "max-age=#{15.minutes}"
  respond_with(@users)
end

#newObject



30
# File 'app/controllers/spree/api/v1/users_controller.rb', line 30

def new; end

#showObject



26
27
28
# File 'app/controllers/spree/api/v1/users_controller.rb', line 26

def show
  respond_with(user)
end

#updateObject



42
43
44
45
46
47
48
49
# File 'app/controllers/spree/api/v1/users_controller.rb', line 42

def update
  authorize! :update, user
  if user.update(user_params)
    respond_with(user, status: 200, default_template: :show)
  else
    invalid_resource!(user)
  end
end