Class: Spree::Api::V3::Admin::CategoriesController
- Inherits:
-
ResourceController
- Object
- ActionController::API
- BaseController
- ResourceController
- ResourceController
- Spree::Api::V3::Admin::CategoriesController
- Defined in:
- app/controllers/spree/api/v3/admin/categories_controller.rb
Overview
Admin CRUD for categories — the hierarchical product classification
half of today's dual-purpose Taxon. Rule-based / automatic taxons
(the "collection" half moving to Spree::Collection in 6.0) are
excluded from this API entirely (see scope), and none of the
collection-bound attributes (automatic, sort_order, rules) are
readable or writable here.
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
-
#reposition ⇒ Object
PATCH /api/v3/admin/categories/:id/reposition Body: { new_parent_id: 'ctg_…' (omit for top level), new_position: 0 } Moves the category to a new parent (or the top level) and/or index.
Methods inherited from ResourceController
#create, #destroy, #index, #show, #update
Methods included from Spree::Api::V3::ApiKeyAuthentication
#authenticate_api_key!, #authenticate_secret_key!
Methods included from JwtAuthentication
#authenticate_user, #require_authentication!
Instance Method Details
#reposition ⇒ Object
PATCH /api/v3/admin/categories/:id/reposition Body: { new_parent_id: 'ctg_…' (omit for top level), new_position: 0 } Moves the category to a new parent (or the top level) and/or index.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/spree/api/v3/admin/categories_controller.rb', line 17 def reposition category = find_resource :update, category position = integer_param(:new_position) return render_invalid_position if position.nil? # Operate on a base Taxon instance (unscoped): the Category default # i18n scope interferes with awesome_nested_set's lft/rgt reads, so # the move silently no-ops on a scoped instance. node = scope.find(category.id) parent = reposition_parent if parent # move_to_child_with_index positions among the parent's children. node.move_to_child_with_index(scope.find(parent.id), reposition_index(category, position, siblings_of(parent))) else move_to_root_at_index(node, reposition_index(category, position, siblings_of(nil))) end render json: serialize_resource(category.reload) rescue CollectiveIdea::Acts::NestedSet::Move::ImpossibleMove => e render_error( code: ERROR_CODES[:validation_error], message: e., status: :unprocessable_content ) end |