Class: Spree::Api::V3::ResourceController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Spree::Api::V3::ResourceController
- Defined in:
- app/controllers/spree/api/v3/resource_controller.rb
Direct Known Subclasses
Admin::ResourceController, Store::ProductsController, Store::ResourceController
Constant Summary
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/resource.
-
#destroy ⇒ Object
DELETE /api/v3/resource/:id.
-
#index ⇒ Object
GET /api/v3/resource.
-
#show ⇒ Object
GET /api/v3/resource/:id.
-
#update ⇒ Object
PATCH /api/v3/resource/:id.
Methods included from ApiKeyAuthentication
#authenticate_api_key!, #authenticate_secret_key!
Methods included from JwtAuthentication
#authenticate_user, #require_authentication!
Instance Method Details
#create ⇒ Object
POST /api/v3/resource
30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/spree/api/v3/resource_controller.rb', line 30 def create @resource = build_resource (@resource, :create) if @resource.save render json: serialize_resource(@resource), status: :created else render_errors(@resource.errors) end end |
#destroy ⇒ Object
DELETE /api/v3/resource/:id
51 52 53 54 |
# File 'app/controllers/spree/api/v3/resource_controller.rb', line 51 def destroy @resource.destroy head :no_content end |
#index ⇒ Object
GET /api/v3/resource
9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/spree/api/v3/resource_controller.rb', line 9 def index @collection = collection # Apply HTTP caching for guests return unless cache_collection(@collection) render json: { data: serialize_collection(@collection), meta: (@collection) } end |
#show ⇒ Object
GET /api/v3/resource/:id
22 23 24 25 26 27 |
# File 'app/controllers/spree/api/v3/resource_controller.rb', line 22 def show # Apply HTTP caching for guests return unless cache_resource(@resource) render json: serialize_resource(@resource) end |
#update ⇒ Object
PATCH /api/v3/resource/:id
42 43 44 45 46 47 48 |
# File 'app/controllers/spree/api/v3/resource_controller.rb', line 42 def update if @resource.update(permitted_params) render json: serialize_resource(@resource) else render_errors(@resource.errors) end end |