Add DFC API EnterpriseGroups#show

This commit is contained in:
Maikel Linke
2023-09-05 15:11:02 +10:00
parent ae72158e87
commit 2d91a61dcb
5 changed files with 69 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
# frozen_string_literal: true
# OFN EnterpriseGroup is represented as DFC Enterprise.
module DfcProvider
class EnterpriseGroupsController < DfcProvider::ApplicationController
def show
group = EnterpriseGroup.find(params[:id])
enterprise = EnterpriseBuilder.enterprise_group(group)
render json: DfcIo.export(enterprise)
end
end
end

View File

@@ -18,4 +18,12 @@ class EnterpriseBuilder < DfcBuilder
e.addLocalization(address)
end
end
def self.enterprise_group(group)
DataFoodConsortium::Connector::Enterprise.new(
urls.enterprise_group_url(group.id),
name: group.name,
description: group.description,
)
end
end

View File

@@ -6,5 +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 :persons, only: [:show]
end

View File

@@ -0,0 +1,23 @@
# frozen_string_literal: true
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) }
before { login_as user }
path "/api/dfc/enterprise_groups/{id}" do
get "Show groups" do
parameter name: :id, in: :path, type: :string
produces "application/json"
response "200", "successful" do
let(:id) { group.id }
run_test!
end
end
end
end

View File

@@ -234,6 +234,31 @@ paths:
"@type": "@id"
dfc-b:stockLimitation: '3'
dfc-b:sku: new-sku
"/api/dfc/enterprise_groups/{id}":
get:
summary: Show groups
parameters:
- name: id
in: path
required: true
schema:
type: string
tags:
- EnterpriseGroups
responses:
'200':
description: successful
content:
application/json:
examples:
test_example:
value:
"@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:hasDescription: this is a group
dfc-b:VATnumber: ''
"/api/dfc/enterprises/{id}":
get:
summary: Show enterprise