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

Inherits:
BaseController 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



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

def create
  authorize_resource!(Spree::Address.new(user_id: @parent.id), :create)

  result = Spree.address_create_service.call(
    address_params: address_attrs,
    user: @parent,
    default_billing: default_billing_flag,
    default_shipping: default_shipping_flag
  )

  if result.success?
    render json: serialize_resource(result.value), status: :created
  else
    render_validation_error(result.value.errors)
  end
end

#destroyObject

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



45
46
47
48
49
# File 'app/controllers/spree/api/v3/admin/customers/addresses_controller.rb', line 45

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

#updateObject

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



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

def update
  authorize_resource!(@resource)

  result = Spree.address_update_service.call(
    address: @resource,
    address_params: address_attrs,
    default_billing: default_billing_flag,
    default_shipping: default_shipping_flag
  )

  if result.success?
    render json: serialize_resource(result.value)
  else
    render_validation_error(result.value.errors)
  end
end