Class: Spree::Api::V3::Admin::Translations::BatchesController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- BaseController
- Spree::Api::V3::Admin::Translations::BatchesController
- Defined in:
- app/controllers/spree/api/v3/admin/translations/batches_controller.rb
Overview
Atomically upserts translations across MANY records of (possibly) different translatable resource types in a single request. Powers the dashboard's combined editors (e.g. an option type + all its option values saved in one go).
The body is a flat list of independent registry writes — NOT a nested/parent-owns-children payload. Each entry names its own resource_type + resource_id, so the controller stays free of per-model branching.
POST /api/v3/admin/translations/batch Body:
{ "translations": [
{ "resource_type": "option_type", "resource_id": "opt_…",
"values": { "de": { "label": "Größe" } } },
{ "resource_type": "option_value", "resource_id": "optval_…",
"values": { "de": { "label": "Klein" } } }
] }
All entries succeed or none do — a validation failure on any entry rolls back the whole transaction and returns per-entry detail. The orchestration (resolve → upsert → rollback) lives in Spree::Translations::Batch; the controller only handles params, authorization, and rendering.
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
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
-
#create ⇒ Object
POST /api/v3/admin/translations/batch.
Methods included from Spree::Api::V3::ApiKeyAuthentication
#authenticate_api_key!, #authenticate_secret_key!
Methods included from JwtAuthentication
#authenticate_user, #require_authentication!
Instance Method Details
#create ⇒ Object
POST /api/v3/admin/translations/batch
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/spree/api/v3/admin/translations/batches_controller.rb', line 38 def create raw = params[:translations] return render_empty_batch_error unless raw.is_a?(Array) && raw.any? batch = Spree::Translations::Batch.new(batch_params) return unless require_batch_scopes!(batch) records = batch.process! { |record| (:update, record) } render json: { data: records.map { |record| serialize_translations(record) } } rescue Spree::Translations::Batch::EntryError => e render_error( code: ERROR_CODES[:validation_error], message: e., status: :unprocessable_content, details: { translations: { e.index.to_s => [e.] } } ) end |