mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-06 07:29:16 +00:00
List enterprise groups on DFC API
This commit is contained in:
@@ -3,6 +3,16 @@
|
||||
# OFN EnterpriseGroup is represented as DFC Enterprise.
|
||||
module DfcProvider
|
||||
class EnterpriseGroupsController < DfcProvider::ApplicationController
|
||||
def index
|
||||
person = PersonBuilder.person(current_user)
|
||||
groups = current_user.owned_groups
|
||||
enterprises = groups.map do |group|
|
||||
EnterpriseBuilder.enterprise_group(group)
|
||||
end
|
||||
person.affiliatedOrganizations = enterprises
|
||||
render json: DfcIo.export(person, *enterprises)
|
||||
end
|
||||
|
||||
def show
|
||||
group = EnterpriseGroup.find(params[:id])
|
||||
enterprise = EnterpriseBuilder.enterprise_group(group)
|
||||
|
||||
@@ -6,6 +6,6 @@ DfcProvider::Engine.routes.draw do
|
||||
resources :catalog_items, only: [:index, :show, :update]
|
||||
resources :supplied_products, only: [:create, :show, :update]
|
||||
end
|
||||
resources :enterprise_groups, only: [:show]
|
||||
resources :enterprise_groups, only: [:index, :show]
|
||||
resources :persons, only: [:show]
|
||||
end
|
||||
|
||||
@@ -3,17 +3,43 @@
|
||||
require_relative "../swagger_helper"
|
||||
|
||||
describe "EnterpriseGroups", type: :request, swagger_doc: "dfc.yaml", rswag_autodoc: true do
|
||||
let(:user) { create(:oidc_user) }
|
||||
let(:user) { create(:oidc_user, id: 12_345) }
|
||||
let(:group) {
|
||||
create(
|
||||
:enterprise_group,
|
||||
id: 60_000, name: "Sustainable Farmers", enterprises: [enterprise],
|
||||
id: 60_000, owner: user, name: "Sustainable Farmers",
|
||||
enterprises: [enterprise],
|
||||
)
|
||||
}
|
||||
let(:enterprise) { create(:enterprise, id: 10_000) }
|
||||
|
||||
before { login_as user }
|
||||
|
||||
path "/api/dfc/enterprise_groups" do
|
||||
get "List groups" do
|
||||
produces "application/json"
|
||||
|
||||
response "200", "successful" do
|
||||
let!(:groups) { [group] }
|
||||
|
||||
run_test! do
|
||||
graph = json_response["@graph"]
|
||||
|
||||
expect(graph[0]["@type"]).to eq "dfc-b:Person"
|
||||
expect(graph[0]).to include(
|
||||
"dfc-b:affiliates" => "http://test.host/api/dfc/enterprise_groups/60000",
|
||||
)
|
||||
|
||||
expect(graph[1]["@type"]).to eq "dfc-b:Enterprise"
|
||||
expect(graph[1]).to include(
|
||||
"dfc-b:hasName" => "Sustainable Farmers",
|
||||
"dfc-b:affiliatedBy" => "http://test.host/api/dfc/enterprises/10000",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
path "/api/dfc/enterprise_groups/{id}" do
|
||||
get "Show groups" do
|
||||
parameter name: :id, in: :path, type: :string
|
||||
|
||||
@@ -234,6 +234,30 @@ paths:
|
||||
"@type": "@id"
|
||||
dfc-b:stockLimitation: '3'
|
||||
dfc-b:sku: new-sku
|
||||
"/api/dfc/enterprise_groups":
|
||||
get:
|
||||
summary: List groups
|
||||
tags:
|
||||
- EnterpriseGroups
|
||||
responses:
|
||||
'200':
|
||||
description: successful
|
||||
content:
|
||||
application/json:
|
||||
examples:
|
||||
test_example:
|
||||
value:
|
||||
"@context": https://www.datafoodconsortium.org
|
||||
"@graph":
|
||||
- "@id": http://test.host/api/dfc/persons/12345
|
||||
"@type": dfc-b:Person
|
||||
dfc-b:affiliates: http://test.host/api/dfc/enterprise_groups/60000
|
||||
- "@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
|
||||
"/api/dfc/enterprise_groups/{id}":
|
||||
get:
|
||||
summary: Show groups
|
||||
|
||||
Reference in New Issue
Block a user