From 18565f4a85c46c366c82d0fabe8d717e2635d1cf Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Mon, 14 Aug 2023 15:51:04 +1000 Subject: [PATCH 1/9] Add all the enterpise attributes supported by DFC connector --- .../app/services/enterprise_builder.rb | 13 +++++++------ .../spec/services/enterprise_builder_spec.rb | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/engines/dfc_provider/app/services/enterprise_builder.rb b/engines/dfc_provider/app/services/enterprise_builder.rb index a8327d97da..742d8d8f4f 100644 --- a/engines/dfc_provider/app/services/enterprise_builder.rb +++ b/engines/dfc_provider/app/services/enterprise_builder.rb @@ -7,11 +7,12 @@ class EnterpriseBuilder < DfcBuilder supplied_products = catalog_items.map(&:product) DataFoodConsortium::Connector::Enterprise.new( - enterprise.name - ).tap do |e| - e.semanticId = urls.enterprise_url(enterprise.id) - e.suppliedProducts = supplied_products - e.catalogItems = catalog_items - end + urls.enterprise_url(enterprise.id), + name: enterprise.name, + description: enterprise.description, + vatNumber: enterprise.abn, + suppliedProducts: supplied_products, + catalogItems: catalog_items + ) end end diff --git a/engines/dfc_provider/spec/services/enterprise_builder_spec.rb b/engines/dfc_provider/spec/services/enterprise_builder_spec.rb index d6c7c2f3c8..18186ed431 100644 --- a/engines/dfc_provider/spec/services/enterprise_builder_spec.rb +++ b/engines/dfc_provider/spec/services/enterprise_builder_spec.rb @@ -16,6 +16,24 @@ describe EnterpriseBuilder do ) end + it "assigns a name" do + result = builder.enterprise(enterprise) + + expect(result.name).to eq(enterprise.name) + end + + it "assigns a description" do + result = builder.enterprise(enterprise) + + expect(result.description).to eq(enterprise.description) + end + + it "assigns a VAT Number (ABN in australia)" do + result = builder.enterprise(enterprise) + + expect(result.vatNumber).to eq(enterprise.abn) + end + it "assignes products" do result = builder.enterprise(enterprise) From 5d05c3c0f1d79e1e5ec86a07803ac8a93fbf41db Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Mon, 21 Aug 2023 15:57:03 +1000 Subject: [PATCH 2/9] DRY DFC enterprise spec --- .../spec/services/enterprise_builder_spec.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/engines/dfc_provider/spec/services/enterprise_builder_spec.rb b/engines/dfc_provider/spec/services/enterprise_builder_spec.rb index 18186ed431..cc5b780f5f 100644 --- a/engines/dfc_provider/spec/services/enterprise_builder_spec.rb +++ b/engines/dfc_provider/spec/services/enterprise_builder_spec.rb @@ -8,35 +8,27 @@ describe EnterpriseBuilder do let(:variant) { create(:product, name: "Apple").variants.first } describe ".enterprise" do - it "assigns a semantic id" do - result = builder.enterprise(enterprise) + let(:result) { builder.enterprise(enterprise) } + it "assigns a semantic id" do expect(result.semanticId).to eq( "http://test.host/api/dfc-v1.7/enterprises/#{enterprise.id}" ) end it "assigns a name" do - result = builder.enterprise(enterprise) - expect(result.name).to eq(enterprise.name) end it "assigns a description" do - result = builder.enterprise(enterprise) - expect(result.description).to eq(enterprise.description) end it "assigns a VAT Number (ABN in australia)" do - result = builder.enterprise(enterprise) - expect(result.vatNumber).to eq(enterprise.abn) end it "assignes products" do - result = builder.enterprise(enterprise) - expect(result.suppliedProducts.count).to eq 1 expect(result.suppliedProducts[0].name).to eq "Apple" end From 244b9abd21be8c7071e4850042b391ca85215331 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Mon, 21 Aug 2023 16:19:45 +1000 Subject: [PATCH 3/9] Spec with given data included in examples And use in-memory data where possible to speed up specs. --- .../spec/services/enterprise_builder_spec.rb | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/engines/dfc_provider/spec/services/enterprise_builder_spec.rb b/engines/dfc_provider/spec/services/enterprise_builder_spec.rb index cc5b780f5f..e2e7e694f7 100644 --- a/engines/dfc_provider/spec/services/enterprise_builder_spec.rb +++ b/engines/dfc_provider/spec/services/enterprise_builder_spec.rb @@ -4,31 +4,41 @@ require DfcProvider::Engine.root.join("spec/spec_helper") describe EnterpriseBuilder do subject(:builder) { described_class } - let(:enterprise) { variant.product.supplier } - let(:variant) { create(:product, name: "Apple").variants.first } + let(:enterprise) { + build( + :enterprise, + id: 10_000, name: "Fabi's Farm", + description: "The place where stuff grows", abn: "123 456 789 0", + ) + } + let(:variant) { + create(:product, supplier: enterprise, name: "Apple").variants.first + } describe ".enterprise" do let(:result) { builder.enterprise(enterprise) } it "assigns a semantic id" do expect(result.semanticId).to eq( - "http://test.host/api/dfc-v1.7/enterprises/#{enterprise.id}" + "http://test.host/api/dfc-v1.7/enterprises/10000" ) end it "assigns a name" do - expect(result.name).to eq(enterprise.name) + expect(result.name).to eq "Fabi's Farm" end it "assigns a description" do - expect(result.description).to eq(enterprise.description) + expect(result.description).to eq "The place where stuff grows" end it "assigns a VAT Number (ABN in australia)" do - expect(result.vatNumber).to eq(enterprise.abn) + expect(result.vatNumber).to eq "123 456 789 0" end it "assignes products" do + expect(variant).to be_persisted + expect(result.suppliedProducts.count).to eq 1 expect(result.suppliedProducts[0].name).to eq "Apple" end From f5fb76012873b304bac8ec798764f5a370fcc36b Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Mon, 14 Aug 2023 15:52:08 +1000 Subject: [PATCH 4/9] Update Enterprise request spec Check all the attributes supported by the DFC connector --- .../dfc_provider/spec/requests/catalog_items_spec.rb | 7 ++++++- .../dfc_provider/spec/requests/enterprises_spec.rb | 11 ++++++++++- swagger/dfc-v1.7/swagger.yaml | 11 +++++------ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/engines/dfc_provider/spec/requests/catalog_items_spec.rb b/engines/dfc_provider/spec/requests/catalog_items_spec.rb index 4cbefae553..268ba783eb 100644 --- a/engines/dfc_provider/spec/requests/catalog_items_spec.rb +++ b/engines/dfc_provider/spec/requests/catalog_items_spec.rb @@ -5,7 +5,12 @@ require DfcProvider::Engine.root.join("spec/swagger_helper") describe "CatalogItems", type: :request, swagger_doc: "dfc-v1.7/swagger.yaml", rswag_autodoc: true do let(:user) { create(:oidc_user, id: 12_345) } - let(:enterprise) { create(:distributor_enterprise, id: 10_000, owner: user) } + let(:enterprise) { + create( + :distributor_enterprise, + id: 10_000, owner: user, name: "Fred's Farm", description: "Beautiful", + ) + } let(:product) { create( :base_product, diff --git a/engines/dfc_provider/spec/requests/enterprises_spec.rb b/engines/dfc_provider/spec/requests/enterprises_spec.rb index 0d2f5eade7..a7eaccb4e1 100644 --- a/engines/dfc_provider/spec/requests/enterprises_spec.rb +++ b/engines/dfc_provider/spec/requests/enterprises_spec.rb @@ -4,7 +4,13 @@ require DfcProvider::Engine.root.join("spec/swagger_helper") describe "Enterprises", type: :request, swagger_doc: "dfc-v1.7/swagger.yaml", rswag_autodoc: true do let!(:user) { create(:oidc_user) } - let!(:enterprise) { create(:distributor_enterprise, id: 10_000, owner: user) } + let!(:enterprise) do + create( + :distributor_enterprise, + id: 10_000, owner: user, abn: "123 456", name: "Fred's Farm", + description: "This is an awesome enterprise", + ) + end let!(:product) { create( :base_product, @@ -36,6 +42,9 @@ describe "Enterprises", type: :request, swagger_doc: "dfc-v1.7/swagger.yaml", rs let(:id) { enterprise.id } run_test! do + expect(response.body).to include "Fred's Farm" + expect(response.body).to include "This is an awesome enterprise" + expect(response.body).to include "123 456" expect(response.body).to include "Apple" end end diff --git a/swagger/dfc-v1.7/swagger.yaml b/swagger/dfc-v1.7/swagger.yaml index 827b4d7906..72260b02e9 100644 --- a/swagger/dfc-v1.7/swagger.yaml +++ b/swagger/dfc-v1.7/swagger.yaml @@ -64,9 +64,8 @@ paths: dfc-b:affiliates: http://test.host/api/dfc-v1.7/enterprises/10000 - "@id": http://test.host/api/dfc-v1.7/enterprises/10000 "@type": dfc-b:Enterprise - dfc-b:hasName: '' - dfc-b:hasDescription: '' - dfc-b:VATnumber: '' + dfc-b:hasName: Fred's Farm + dfc-b:hasDescription: Beautiful dfc-b:supplies: http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001 dfc-b:manages: http://test.host/api/dfc-v1.7/enterprises/10000/catalog_items/10001 - "@id": http://test.host/api/dfc-v1.7/enterprises/10000/catalog_items/10001 @@ -221,9 +220,9 @@ paths: "@graph": - "@id": http://test.host/api/dfc-v1.7/enterprises/10000 "@type": dfc-b:Enterprise - dfc-b:hasName: '' - dfc-b:hasDescription: '' - dfc-b:VATnumber: '' + dfc-b:hasName: Fred's Farm + dfc-b:hasDescription: This is an awesome enterprise + dfc-b:VATnumber: 123 456 dfc-b:supplies: http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001 dfc-b:manages: http://test.host/api/dfc-v1.7/enterprises/10000/catalog_items/10001 - "@id": http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001 From 86bb77ab9fe6112c6ab9597b21db6da686615733 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Tue, 15 Aug 2023 14:14:33 +1000 Subject: [PATCH 5/9] Add AddressBuilder It will let us include address in the various DFC API endpoint --- .../app/services/address_builder.rb | 14 +++++++ .../spec/services/address_builder_spec.rb | 37 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 engines/dfc_provider/app/services/address_builder.rb create mode 100644 engines/dfc_provider/spec/services/address_builder_spec.rb diff --git a/engines/dfc_provider/app/services/address_builder.rb b/engines/dfc_provider/app/services/address_builder.rb new file mode 100644 index 0000000000..331d742a7e --- /dev/null +++ b/engines/dfc_provider/app/services/address_builder.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class AddressBuilder < DfcBuilder + def self.address(address) + # TODO add url helper/address contoller so we can do urls.address_url(address.id) + DataFoodConsortium::Connector::Address.new( + "http://test.host/api/dfc-v1.7/address/#{address.id}", + street: address.address1, + postalCode: address.zipcode, + city: address.city, + country: address.country.name + ) + end +end diff --git a/engines/dfc_provider/spec/services/address_builder_spec.rb b/engines/dfc_provider/spec/services/address_builder_spec.rb new file mode 100644 index 0000000000..5beac2aba2 --- /dev/null +++ b/engines/dfc_provider/spec/services/address_builder_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require DfcProvider::Engine.root.join("spec/spec_helper") + +describe AddressBuilder do + subject(:result) { described_class.address(address) } + let(:address) { + build( + :address, + id: 1, address1: "Paradise 15", zipcode: "0001", city: "Goosnargh", + ) + } + + describe ".address" do + it "assigns a semantic id" do + expect(result.semanticId).to eq( + "http://test.host/api/dfc-v1.7/address/1" + ) + end + + it "assigns a street" do + expect(result.street).to eq "Paradise 15" + end + + it "assigns a postal code" do + expect(result.postalCode).to eq "0001" + end + + it "assigns a city" do + expect(result.city).to eq "Goosnargh" + end + + it "assigns a country" do + expect(result.country).to eq "Australia" + end + end +end From a8d15154a27d06a3c1b78eebe50599ef2cda1896 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Fri, 18 Aug 2023 11:57:34 +1000 Subject: [PATCH 6/9] Link address to enterprise + spec --- engines/dfc_provider/app/services/enterprise_builder.rb | 5 ++++- engines/dfc_provider/spec/requests/catalog_items_spec.rb | 1 + engines/dfc_provider/spec/requests/enterprises_spec.rb | 1 + .../dfc_provider/spec/services/enterprise_builder_spec.rb | 8 +++++++- swagger/dfc-v1.7/swagger.yaml | 2 ++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/engines/dfc_provider/app/services/enterprise_builder.rb b/engines/dfc_provider/app/services/enterprise_builder.rb index 742d8d8f4f..3ac8d0c4fc 100644 --- a/engines/dfc_provider/app/services/enterprise_builder.rb +++ b/engines/dfc_provider/app/services/enterprise_builder.rb @@ -5,6 +5,7 @@ class EnterpriseBuilder < DfcBuilder variants = VariantFetcher.new(enterprise).scope.to_a catalog_items = variants.map(&method(:catalog_item)) supplied_products = catalog_items.map(&:product) + address = AddressBuilder.address(enterprise.address) DataFoodConsortium::Connector::Enterprise.new( urls.enterprise_url(enterprise.id), @@ -13,6 +14,8 @@ class EnterpriseBuilder < DfcBuilder vatNumber: enterprise.abn, suppliedProducts: supplied_products, catalogItems: catalog_items - ) + ).tap do |e| + e.addLocalization(address) + end end end diff --git a/engines/dfc_provider/spec/requests/catalog_items_spec.rb b/engines/dfc_provider/spec/requests/catalog_items_spec.rb index 268ba783eb..2d78ab765a 100644 --- a/engines/dfc_provider/spec/requests/catalog_items_spec.rb +++ b/engines/dfc_provider/spec/requests/catalog_items_spec.rb @@ -9,6 +9,7 @@ describe "CatalogItems", type: :request, swagger_doc: "dfc-v1.7/swagger.yaml", create( :distributor_enterprise, id: 10_000, owner: user, name: "Fred's Farm", description: "Beautiful", + address: build(:address, id: 40_000), ) } let(:product) { diff --git a/engines/dfc_provider/spec/requests/enterprises_spec.rb b/engines/dfc_provider/spec/requests/enterprises_spec.rb index a7eaccb4e1..107a3d7347 100644 --- a/engines/dfc_provider/spec/requests/enterprises_spec.rb +++ b/engines/dfc_provider/spec/requests/enterprises_spec.rb @@ -9,6 +9,7 @@ describe "Enterprises", type: :request, swagger_doc: "dfc-v1.7/swagger.yaml", rs :distributor_enterprise, id: 10_000, owner: user, abn: "123 456", name: "Fred's Farm", description: "This is an awesome enterprise", + address: build(:address, id: 40_000), ) end let!(:product) { diff --git a/engines/dfc_provider/spec/services/enterprise_builder_spec.rb b/engines/dfc_provider/spec/services/enterprise_builder_spec.rb index e2e7e694f7..932e066212 100644 --- a/engines/dfc_provider/spec/services/enterprise_builder_spec.rb +++ b/engines/dfc_provider/spec/services/enterprise_builder_spec.rb @@ -9,6 +9,7 @@ describe EnterpriseBuilder do :enterprise, id: 10_000, name: "Fabi's Farm", description: "The place where stuff grows", abn: "123 456 789 0", + address: build(:address, city: "Melbourne"), ) } let(:variant) { @@ -36,11 +37,16 @@ describe EnterpriseBuilder do expect(result.vatNumber).to eq "123 456 789 0" end - it "assignes products" do + it "assigns products" do expect(variant).to be_persisted expect(result.suppliedProducts.count).to eq 1 expect(result.suppliedProducts[0].name).to eq "Apple" end + + it "assigns an address" do + expect(result.localizations.count).to eq 1 + expect(result.localizations[0].city).to eq "Melbourne" + end end end diff --git a/swagger/dfc-v1.7/swagger.yaml b/swagger/dfc-v1.7/swagger.yaml index 72260b02e9..66299f0456 100644 --- a/swagger/dfc-v1.7/swagger.yaml +++ b/swagger/dfc-v1.7/swagger.yaml @@ -64,6 +64,7 @@ paths: dfc-b:affiliates: http://test.host/api/dfc-v1.7/enterprises/10000 - "@id": http://test.host/api/dfc-v1.7/enterprises/10000 "@type": dfc-b:Enterprise + dfc-b:hasAddress: http://test.host/api/dfc-v1.7/address/40000 dfc-b:hasName: Fred's Farm dfc-b:hasDescription: Beautiful dfc-b:supplies: http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001 @@ -220,6 +221,7 @@ paths: "@graph": - "@id": http://test.host/api/dfc-v1.7/enterprises/10000 "@type": dfc-b:Enterprise + dfc-b:hasAddress: http://test.host/api/dfc-v1.7/address/40000 dfc-b:hasName: Fred's Farm dfc-b:hasDescription: This is an awesome enterprise dfc-b:VATnumber: 123 456 From 20b09b53523a5a9e4bf05af17e488aa7328acbed Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 24 Aug 2023 15:52:21 +1000 Subject: [PATCH 7/9] Add DFC Address API endpoint --- .../dfc_provider/addresses_controller.rb | 61 +++++++++++++++++++ .../app/services/address_builder.rb | 3 +- engines/dfc_provider/config/routes.rb | 1 + .../spec/requests/addresses_spec.rb | 41 +++++++++++++ .../spec/services/address_builder_spec.rb | 2 +- .../spec/services/enterprise_builder_spec.rb | 2 +- swagger/dfc-v1.7/swagger.yaml | 30 ++++++++- 7 files changed, 134 insertions(+), 6 deletions(-) create mode 100644 engines/dfc_provider/app/controllers/dfc_provider/addresses_controller.rb create mode 100644 engines/dfc_provider/spec/requests/addresses_spec.rb diff --git a/engines/dfc_provider/app/controllers/dfc_provider/addresses_controller.rb b/engines/dfc_provider/app/controllers/dfc_provider/addresses_controller.rb new file mode 100644 index 0000000000..f03acfb2f0 --- /dev/null +++ b/engines/dfc_provider/app/controllers/dfc_provider/addresses_controller.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +# Controller used to provide the CatalogItem API for the DFC application +module DfcProvider + class AddressesController < DfcProvider::ApplicationController + def show + address = Spree::Address.find(params.require(:id)) + + return not_found unless authorized(address) + + dfc_address = AddressBuilder.address(address) + render json: DfcIo.export(dfc_address) + end + + private + + # Does the current user have access to this address? + # + # It's possible to guess address ids and therefore we need to prevent the + # collection of sensitive customer data. + # + # We may want to extend the list of authorised addresses once the DFC API + # references them. To start with, we would only need enterprise addresses + # but I included a few more options to show how this will probably evolve. + # + # Currently not checked models: + # + # - Spree::Card + # - Spree::Order + # - Spree::Shipment + # - Subscription + def authorized(address) + current_user.ship_address_id == address.id || + current_user.bill_address_id == address.id || + [ + customer_address(address), + public_enterprise_group_address(address), + public_enterprise_address(address), + managed_enterprise_address(address), + ].any?(&:exists?) + end + + def customer_address(address) + current_user.customers.where(bill_address: address).or( + current_user.customers.where(ship_address: address) + ) + end + + def public_enterprise_group_address(address) + EnterpriseGroup.where(address:) + end + + def public_enterprise_address(address) + Enterprise.activated.visible.is_distributor.where(address:) + end + + def managed_enterprise_address(address) + current_user.enterprises.where(address:) + end + end +end diff --git a/engines/dfc_provider/app/services/address_builder.rb b/engines/dfc_provider/app/services/address_builder.rb index 331d742a7e..7b89d2a073 100644 --- a/engines/dfc_provider/app/services/address_builder.rb +++ b/engines/dfc_provider/app/services/address_builder.rb @@ -2,9 +2,8 @@ class AddressBuilder < DfcBuilder def self.address(address) - # TODO add url helper/address contoller so we can do urls.address_url(address.id) DataFoodConsortium::Connector::Address.new( - "http://test.host/api/dfc-v1.7/address/#{address.id}", + urls.address_url(address), street: address.address1, postalCode: address.zipcode, city: address.city, diff --git a/engines/dfc_provider/config/routes.rb b/engines/dfc_provider/config/routes.rb index a016a9f5b9..4064a83fca 100644 --- a/engines/dfc_provider/config/routes.rb +++ b/engines/dfc_provider/config/routes.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true DfcProvider::Engine.routes.draw do + resources :addresses, only: [:show] resources :enterprises, only: [:show] do resources :catalog_items, only: [:index, :show, :update] resources :supplied_products, only: [:create, :show, :update] diff --git a/engines/dfc_provider/spec/requests/addresses_spec.rb b/engines/dfc_provider/spec/requests/addresses_spec.rb new file mode 100644 index 0000000000..7798dcd282 --- /dev/null +++ b/engines/dfc_provider/spec/requests/addresses_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require DfcProvider::Engine.root.join("spec/swagger_helper") + +describe "Addresses", type: :request, swagger_doc: "dfc-v1.7/swagger.yaml", rswag_autodoc: true do + let(:user) { create(:oidc_user) } + let(:address) { create(:address, id: 40_000) } + let(:result) { json_response } + + before { login_as user } + + path "/api/dfc-v1.7/addresses/{id}" do + get "Show address" do + parameter name: :id, in: :path, type: :string + produces "application/json" + + response "200", "successful" do + let(:id) { address.id } + + before { create(:enterprise, owner: user, address:) } + + run_test! do + expect(result["@id"]).to eq "http://test.host/api/dfc-v1.7/addresses/40000" + expect(result["@type"]).to eq "dfc-b:Address" + end + end + + response "404", "not found" do + context "when the address doesn't exist" do + let(:id) { 0 } + run_test! + end + + context "when the address doesn't belong to you" do + let(:id) { address.id } + run_test! + end + end + end + end +end diff --git a/engines/dfc_provider/spec/services/address_builder_spec.rb b/engines/dfc_provider/spec/services/address_builder_spec.rb index 5beac2aba2..473f9c86fd 100644 --- a/engines/dfc_provider/spec/services/address_builder_spec.rb +++ b/engines/dfc_provider/spec/services/address_builder_spec.rb @@ -14,7 +14,7 @@ describe AddressBuilder do describe ".address" do it "assigns a semantic id" do expect(result.semanticId).to eq( - "http://test.host/api/dfc-v1.7/address/1" + "http://test.host/api/dfc-v1.7/addresses/1" ) end diff --git a/engines/dfc_provider/spec/services/enterprise_builder_spec.rb b/engines/dfc_provider/spec/services/enterprise_builder_spec.rb index 932e066212..ac4bfb1ade 100644 --- a/engines/dfc_provider/spec/services/enterprise_builder_spec.rb +++ b/engines/dfc_provider/spec/services/enterprise_builder_spec.rb @@ -9,7 +9,7 @@ describe EnterpriseBuilder do :enterprise, id: 10_000, name: "Fabi's Farm", description: "The place where stuff grows", abn: "123 456 789 0", - address: build(:address, city: "Melbourne"), + address: build(:address, id: 40_000, city: "Melbourne"), ) } let(:variant) { diff --git a/swagger/dfc-v1.7/swagger.yaml b/swagger/dfc-v1.7/swagger.yaml index 66299f0456..34b927363e 100644 --- a/swagger/dfc-v1.7/swagger.yaml +++ b/swagger/dfc-v1.7/swagger.yaml @@ -38,6 +38,32 @@ security: - ofn_api_token: [] - ofn_session: [] paths: + "/api/dfc-v1.7/addresses/{id}": + get: + summary: Show address + parameters: + - name: id + in: path + required: true + schema: + type: string + responses: + '200': + description: successful + content: + application/json: + examples: + test_example: + value: + "@context": https://www.datafoodconsortium.org + "@id": http://test.host/api/dfc-v1.7/addresses/40000 + "@type": dfc-b:Address + dfc-b:hasStreet: 10 Lovely Street + dfc-b:hasPostalCode: '20170' + dfc-b:hasCity: Herndon + dfc-b:hasCountry: Australia + '404': + description: not found "/api/dfc-v1.7/enterprises/{enterprise_id}/catalog_items": parameters: - name: enterprise_id @@ -64,7 +90,7 @@ paths: dfc-b:affiliates: http://test.host/api/dfc-v1.7/enterprises/10000 - "@id": http://test.host/api/dfc-v1.7/enterprises/10000 "@type": dfc-b:Enterprise - dfc-b:hasAddress: http://test.host/api/dfc-v1.7/address/40000 + dfc-b:hasAddress: http://test.host/api/dfc-v1.7/addresses/40000 dfc-b:hasName: Fred's Farm dfc-b:hasDescription: Beautiful dfc-b:supplies: http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001 @@ -221,7 +247,7 @@ paths: "@graph": - "@id": http://test.host/api/dfc-v1.7/enterprises/10000 "@type": dfc-b:Enterprise - dfc-b:hasAddress: http://test.host/api/dfc-v1.7/address/40000 + dfc-b:hasAddress: http://test.host/api/dfc-v1.7/addresses/40000 dfc-b:hasName: Fred's Farm dfc-b:hasDescription: This is an awesome enterprise dfc-b:VATnumber: 123 456 From 1c3574ce79c43d83407c0dcaf0c79ef17ff5e4da Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 24 Aug 2023 16:51:36 +1000 Subject: [PATCH 8/9] Include address in DFC Enterprise endpoint --- .../app/controllers/dfc_provider/enterprises_controller.rb | 1 + engines/dfc_provider/spec/requests/enterprises_spec.rb | 3 ++- swagger/dfc-v1.7/swagger.yaml | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/engines/dfc_provider/app/controllers/dfc_provider/enterprises_controller.rb b/engines/dfc_provider/app/controllers/dfc_provider/enterprises_controller.rb index a80aa6602a..74cb1b0ccd 100644 --- a/engines/dfc_provider/app/controllers/dfc_provider/enterprises_controller.rb +++ b/engines/dfc_provider/app/controllers/dfc_provider/enterprises_controller.rb @@ -9,6 +9,7 @@ module DfcProvider enterprise = EnterpriseBuilder.enterprise(current_enterprise) render json: DfcIo.export( enterprise, + *enterprise.localizations, *enterprise.suppliedProducts, *enterprise.catalogItems, ) diff --git a/engines/dfc_provider/spec/requests/enterprises_spec.rb b/engines/dfc_provider/spec/requests/enterprises_spec.rb index 107a3d7347..7d73617d8c 100644 --- a/engines/dfc_provider/spec/requests/enterprises_spec.rb +++ b/engines/dfc_provider/spec/requests/enterprises_spec.rb @@ -9,7 +9,7 @@ describe "Enterprises", type: :request, swagger_doc: "dfc-v1.7/swagger.yaml", rs :distributor_enterprise, id: 10_000, owner: user, abn: "123 456", name: "Fred's Farm", description: "This is an awesome enterprise", - address: build(:address, id: 40_000), + address: build(:address, id: 40_000, address1: "42 Doveton Street"), ) end let!(:product) { @@ -47,6 +47,7 @@ describe "Enterprises", type: :request, swagger_doc: "dfc-v1.7/swagger.yaml", rs expect(response.body).to include "This is an awesome enterprise" expect(response.body).to include "123 456" expect(response.body).to include "Apple" + expect(response.body).to include "42 Doveton Street" end end end diff --git a/swagger/dfc-v1.7/swagger.yaml b/swagger/dfc-v1.7/swagger.yaml index 34b927363e..9ca116cf4f 100644 --- a/swagger/dfc-v1.7/swagger.yaml +++ b/swagger/dfc-v1.7/swagger.yaml @@ -253,6 +253,12 @@ paths: dfc-b:VATnumber: 123 456 dfc-b:supplies: http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001 dfc-b:manages: http://test.host/api/dfc-v1.7/enterprises/10000/catalog_items/10001 + - "@id": http://test.host/api/dfc-v1.7/addresses/40000 + "@type": dfc-b:Address + dfc-b:hasStreet: 42 Doveton Street + dfc-b:hasPostalCode: '20170' + dfc-b:hasCity: Herndon + dfc-b:hasCountry: Australia - "@id": http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001 "@type": dfc-b:SuppliedProduct dfc-b:name: Apple From 56f4eca79e93a5e2485b728f4a8ee7456f09f626 Mon Sep 17 00:00:00 2001 From: Maikel Date: Fri, 25 Aug 2023 11:31:00 +1000 Subject: [PATCH 9/9] Update engines/dfc_provider/app/controllers/dfc_provider/addresses_controller.rb Fix type in comment Co-authored-by: David Cook --- .../app/controllers/dfc_provider/addresses_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/dfc_provider/app/controllers/dfc_provider/addresses_controller.rb b/engines/dfc_provider/app/controllers/dfc_provider/addresses_controller.rb index f03acfb2f0..04c04f0bae 100644 --- a/engines/dfc_provider/app/controllers/dfc_provider/addresses_controller.rb +++ b/engines/dfc_provider/app/controllers/dfc_provider/addresses_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Controller used to provide the CatalogItem API for the DFC application +# Controller used to provide the Address API for the DFC application module DfcProvider class AddressesController < DfcProvider::ApplicationController def show