Class: Spree::Api::V3::Admin::CustomFieldsController

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

Overview

Custom field values for any parent that includes the custom-fields concern. Mounted via the ‘:custom_fieldable` route concern; the parent class is inferred from whichever `<segment>_id` route param matches a registered owner.

Defined Under Namespace

Classes: ParentLookup

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

#destroy, #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/<parent>/<parent_id>/custom_fields



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

def create
  @resource = @parent.metafields.new(permitted_params)
  authorize_resource!(@resource, :create)

  if @resource.save
    render json: serialize_resource(@resource), status: :created
  else
    render_validation_error(@resource.errors)
  end
end

#updateObject

PATCH /api/v3/admin/<parent>/<parent_id>/custom_fields/:id Only ‘value` is mutable. Switching the linked definition is a delete-and-create — the model rejects it (definition + resource uniqueness) and the type wouldn’t match.



26
27
28
29
30
31
32
33
34
# File 'app/controllers/spree/api/v3/admin/custom_fields_controller.rb', line 26

def update
  authorize_resource!(@resource)

  if @resource.update(update_permitted_params)
    render json: serialize_resource(@resource)
  else
    render_validation_error(@resource.errors)
  end
end