Include DFC version in API URL

And let the OFN app decide under which name to mount the DFC engine.
It simplifies the code and will make it more flexible to introduce other
versions in the future.
This commit is contained in:
Maikel Linke
2022-11-07 16:38:24 +11:00
committed by David Cook
parent fd274447fe
commit b9a43df7fe
8 changed files with 19 additions and 24 deletions

View File

@@ -8,7 +8,7 @@ Openfoodnetwork::Application.routes.draw do
constraints FeatureToggleConstraint.new(:dfc_provider) do
# Mount DFC API endpoints
mount DfcProvider::Engine, at: '/'
mount DfcProvider::Engine, at: '/dfc-v1.6/'
end
namespace :v0 do

View File

@@ -14,7 +14,7 @@ module DfcProvider
key: 'dfc:offeredThrough'
def id
dfc_provider_routes.dfc_provider_enterprise_catalog_item_url(
dfc_provider_routes.enterprise_catalog_item_url(
enterprise_id: object.product.supplier_id,
id: object.id,
host: host
@@ -41,7 +41,7 @@ module DfcProvider
private
def reference_id
dfc_provider_routes.dfc_provider_enterprise_supplied_product_url(
dfc_provider_routes.enterprise_supplied_product_url(
enterprise_id: object.product.supplier_id,
id: object.id,
host: host

View File

@@ -16,7 +16,7 @@ module DfcProvider
serializer: DfcProvider::CatalogItemSerializer
def id
dfc_provider_routes.dfc_provider_enterprise_url(
dfc_provider_routes.enterprise_url(
id: object.id,
host: host
)

View File

@@ -26,7 +26,7 @@ module DfcProvider
end
def id
dfc_provider_routes.dfc_provider_person_url(
dfc_provider_routes.person_url(
id: object.id,
host: host
)

View File

@@ -17,7 +17,7 @@ module DfcProvider
has_many :physical_characteristics, key: 'dfc:physicalCharacterisctics'
def id
dfc_provider_routes.dfc_provider_enterprise_supplied_product_url(
dfc_provider_routes.enterprise_supplied_product_url(
enterprise_id: object.product.supplier_id,
id: object.id,
host: host

View File

@@ -1,11 +1,9 @@
# frozen_string_literal: true
DfcProvider::Engine.routes.draw do
scope :dfc_provider, as: :dfc_provider, path: '/dfc_provider' do
resources :enterprises, only: [:show] do
resources :catalog_items, only: [:index, :show]
resources :supplied_products, only: [:show]
end
resources :persons, only: [:show]
resources :enterprises, only: [:show] do
resources :catalog_items, only: [:index, :show]
resources :supplied_products, only: [:show]
end
resources :persons, only: [:show]
end

View File

@@ -11,12 +11,11 @@ describe DfcProvider::CatalogItemSerializer do
describe '#id' do
let(:catalog_item_id) {
[
'http://test.host/api/dfc_provider',
'enterprises',
"http://test.host/api/dfc-v1.6/enterprises/",
product.supplier_id,
'catalog_items',
"/catalog_items/",
variant.id
].join('/')
].join
}
it 'returns the expected value' do
@@ -27,12 +26,11 @@ describe DfcProvider::CatalogItemSerializer do
describe '#references' do
let(:supplied_product_id) {
[
'http://test.host/api/dfc_provider',
'enterprises',
"http://test.host/api/dfc-v1.6/enterprises/",
product.supplier_id,
'supplied_products',
"/supplied_products/",
variant.id
].join('/')
].join
}
it 'returns the expected value' do

View File

@@ -11,12 +11,11 @@ describe DfcProvider::SuppliedProductSerializer do
describe '#id' do
let(:supplied_product_id) {
[
'http://test.host/api/dfc_provider',
'enterprises',
"http://test.host/api/dfc-v1.6/enterprises/",
product.supplier_id,
'supplied_products',
"/supplied_products/",
variant.id
].join('/')
].join
}
it 'returns the expected value' do