Class: Spree::Api::V3::ResourceController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/v3/resource_controller.rb

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

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 included from ApiKeyAuthentication

#authenticate_api_key!, #authenticate_secret_key!

Methods included from JwtAuthentication

#authenticate_user, #require_authentication!

Instance Method Details

#createObject

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
  authorize_resource!(@resource, :create)

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

#destroyObject

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

#indexObject

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_meta(@collection)
  }
end

#showObject

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

#updateObject

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