mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add DFC API EnterpriseGroups#show
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
23
engines/dfc_provider/spec/requests/enterprise_groups_spec.rb
Normal file
23
engines/dfc_provider/spec/requests/enterprise_groups_spec.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user