List enterprises within groups on DFC API

This commit is contained in:
Maikel Linke
2023-09-05 17:04:20 +10:00
parent 2d91a61dcb
commit a03fb01a8c
3 changed files with 26 additions and 4 deletions

View File

@@ -20,10 +20,20 @@ class EnterpriseBuilder < DfcBuilder
end
def self.enterprise_group(group)
members = group.enterprises.map do |member|
urls.enterprise_url(member.id)
end
DataFoodConsortium::Connector::Enterprise.new(
urls.enterprise_group_url(group.id),
name: group.name,
description: group.description,
)
).tap do |enterprise|
# This property has been agreed by the DFC but hasn't made it's way into
# the Connector yet.
enterprise.registerSemanticProperty("dfc-b:affiliatedBy") do
members
end
end
end
end

View File

@@ -4,7 +4,13 @@ require_relative "../swagger_helper"
describe "EnterpriseGroups", type: :request, swagger_doc: "dfc.yaml", rswag_autodoc: true do
let(:user) { create(:oidc_user) }
let(:group) { create(:enterprise_group, id: 60_000) }
let(:group) {
create(
:enterprise_group,
id: 60_000, name: "Sustainable Farmers", enterprises: [enterprise],
)
}
let(:enterprise) { create(:enterprise, id: 10_000) }
before { login_as user }
@@ -16,7 +22,12 @@ describe "EnterpriseGroups", type: :request, swagger_doc: "dfc.yaml", rswag_auto
response "200", "successful" do
let(:id) { group.id }
run_test!
run_test! do
expect(json_response).to include(
"dfc-b:hasName" => "Sustainable Farmers",
"dfc-b:affiliatedBy" => "http://test.host/api/dfc/enterprises/10000",
)
end
end
end
end

View File

@@ -256,9 +256,10 @@ paths:
"@context": https://www.datafoodconsortium.org
"@id": http://test.host/api/dfc/enterprise_groups/60000
"@type": dfc-b:Enterprise
dfc-b:hasName: Enterprise group
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
"/api/dfc/enterprises/{id}":
get:
summary: Show enterprise