Class: Spree::Api::V3::Store::MarketsController

Inherits:
BaseController show all
Includes:
HttpCaching
Defined in:
app/controllers/spree/api/v3/store/markets_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

#indexObject

GET /api/v3/store/markets



9
10
11
12
13
14
15
16
17
# File 'app/controllers/spree/api/v3/store/markets_controller.rb', line 9

def index
  markets = current_store.markets.includes(:countries).order(:position)

  return unless cache_collection(markets)

  render json: {
    data: markets.map { |market| serialize_market(market) }
  }
end

#resolveObject

GET /api/v3/store/markets/resolve?country=DE

Raises:

  • (ActiveRecord::RecordNotFound)


29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/spree/api/v3/store/markets_controller.rb', line 29

def resolve
  country_iso = params[:country]&.upcase
  country = Spree::Country.find_by!(iso: country_iso)
  market = current_store.market_for_country(country)

  raise ActiveRecord::RecordNotFound unless market

  return unless cache_resource(market)

  render json: serialize_market(market)
end

#showObject

GET /api/v3/store/markets/:id



20
21
22
23
24
25
26
# File 'app/controllers/spree/api/v3/store/markets_controller.rb', line 20

def show
  market = current_store.markets.includes(:countries).find_by_prefix_id!(params[:id])

  return unless cache_resource(market)

  render json: serialize_market(market)
end