From 7e222ad83ea4efc1d6f5e0a9774c67fa39832dbd Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 7 Sep 2023 15:06:53 +1000 Subject: [PATCH] Include address when showing group It may be nice to show more data like social media URLs but the DFC Connector hasn't implemented that yet and it's not specified in the current issue. --- .../enterprise_groups_controller.rb | 4 +++- .../spec/requests/enterprise_groups_spec.rb | 14 +++++++++++-- swagger/dfc.yaml | 20 +++++++++++++------ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/engines/dfc_provider/app/controllers/dfc_provider/enterprise_groups_controller.rb b/engines/dfc_provider/app/controllers/dfc_provider/enterprise_groups_controller.rb index 362b540d1d..55600c1ccd 100644 --- a/engines/dfc_provider/app/controllers/dfc_provider/enterprise_groups_controller.rb +++ b/engines/dfc_provider/app/controllers/dfc_provider/enterprise_groups_controller.rb @@ -15,8 +15,10 @@ module DfcProvider def show group = EnterpriseGroup.find(params[:id]) + address = AddressBuilder.address(group.address) enterprise = EnterpriseBuilder.enterprise_group(group) - render json: DfcIo.export(enterprise) + enterprise.addLocalization(address) + render json: DfcIo.export(enterprise, address) end end end diff --git a/engines/dfc_provider/spec/requests/enterprise_groups_spec.rb b/engines/dfc_provider/spec/requests/enterprise_groups_spec.rb index 3346a62499..cf1d356707 100644 --- a/engines/dfc_provider/spec/requests/enterprise_groups_spec.rb +++ b/engines/dfc_provider/spec/requests/enterprise_groups_spec.rb @@ -7,10 +7,11 @@ describe "EnterpriseGroups", type: :request, swagger_doc: "dfc.yaml", rswag_auto let(:group) { create( :enterprise_group, - id: 60_000, owner: user, name: "Sustainable Farmers", + id: 60_000, owner: user, name: "Sustainable Farmers", address:, enterprises: [enterprise], ) } + let(:address) { create(:address, id: 40_000, address1: "8 Acres Drive") } let(:enterprise) { create(:enterprise, id: 10_000) } before { login_as user } @@ -49,10 +50,19 @@ describe "EnterpriseGroups", type: :request, swagger_doc: "dfc.yaml", rswag_auto let(:id) { group.id } run_test! do - expect(json_response).to include( + graph = json_response["@graph"] + + expect(graph[0]).to include( + "@type" => "dfc-b:Enterprise", "dfc-b:hasName" => "Sustainable Farmers", + "dfc-b:hasAddress" => "http://test.host/api/dfc/addresses/40000", "dfc-b:affiliatedBy" => "http://test.host/api/dfc/enterprises/10000", ) + + expect(graph[1]).to include( + "@type" => "dfc-b:Address", + "dfc-b:hasStreet" => "8 Acres Drive", + ) end end end diff --git a/swagger/dfc.yaml b/swagger/dfc.yaml index 3c24165d27..8927ccfc1d 100644 --- a/swagger/dfc.yaml +++ b/swagger/dfc.yaml @@ -278,12 +278,20 @@ paths: test_example: value: "@context": https://www.datafoodconsortium.org - "@id": http://test.host/api/dfc/enterprise_groups/60000 - "@type": dfc-b:Enterprise - dfc-b:hasName: Sustainable Farmers - dfc-b:hasDescription: this is a group - dfc-b:VATnumber: '' - dfc-b:affiliatedBy: http://test.host/api/dfc/enterprises/10000 + "@graph": + - "@id": http://test.host/api/dfc/enterprise_groups/60000 + "@type": dfc-b:Enterprise + dfc-b:hasAddress: http://test.host/api/dfc/addresses/40000 + dfc-b:hasName: Sustainable Farmers + dfc-b:hasDescription: this is a group + dfc-b:VATnumber: '' + dfc-b:affiliatedBy: http://test.host/api/dfc/enterprises/10000 + - "@id": http://test.host/api/dfc/addresses/40000 + "@type": dfc-b:Address + dfc-b:hasStreet: 8 Acres Drive + dfc-b:hasPostalCode: '20170' + dfc-b:hasCity: Herndon + dfc-b:hasCountry: Australia "/api/dfc/enterprises/{id}": get: summary: Show enterprise