Class: Spree::Api::V3::Admin::Customers::AddressesController

Inherits:
ResourceController show all
Defined in:
app/controllers/spree/api/v3/admin/customers/addresses_controller.rb

Constant Summary

Constants included from ScopedAuthorization

ScopedAuthorization::READ_ACTIONS

Constants inherited from BaseController

BaseController::RATE_LIMIT_RESPONSE

Constants included from Idempotent

Idempotent::IDEMPOTENCY_HEADER, Idempotent::IDEMPOTENCY_TTL, Idempotent::MAX_KEY_LENGTH, Idempotent::MUTATING_METHODS

Constants included from ErrorHandler

ErrorHandler::ERROR_CODES

Constants included from JwtAuthentication

JwtAuthentication::JWT_AUDIENCE_ADMIN, JwtAuthentication::JWT_AUDIENCE_STORE, JwtAuthentication::JWT_ISSUER, JwtAuthentication::USER_TYPE_ADMIN, JwtAuthentication::USER_TYPE_CUSTOMER

Instance Method Summary collapse

Methods inherited from ResourceController

#index, #show

Methods included from Spree::Api::V3::ApiKeyAuthentication

#authenticate_api_key!, #authenticate_secret_key!

Methods included from JwtAuthentication

#authenticate_user, #require_authentication!

Instance Method Details

#createObject

POST /api/v3/admin/customers/:customer_id/addresses



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/spree/api/v3/admin/customers/addresses_controller.rb', line 10

def create
  @resource = @parent.addresses.new(address_attrs)
  authorize_resource!(@resource, :create)

  ApplicationRecord.transaction do
    if @resource.save
      apply_default_flags(@resource)
      render json: serialize_resource(@resource.reload), status: :created
    else
      render_validation_error(@resource.errors)
      raise ActiveRecord::Rollback
    end
  end
end

#destroyObject

DELETE /api/v3/admin/customers/:customer_id/addresses/:id



41
42
43
44
45
# File 'app/controllers/spree/api/v3/admin/customers/addresses_controller.rb', line 41

def destroy
  authorize_resource!(@resource)
  @resource.destroy
  head :no_content
end

#updateObject

PATCH /api/v3/admin/customers/:customer_id/addresses/:id



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/spree/api/v3/admin/customers/addresses_controller.rb', line 26

def update
  authorize_resource!(@resource)

  ApplicationRecord.transaction do
    if @resource.update(address_attrs)
      apply_default_flags(@resource)
      render json: serialize_resource(@resource.reload)
    else
      render_validation_error(@resource.errors)
      raise ActiveRecord::Rollback
    end
  end
end