Add DFC API endpoint for listing platforms

Only listing example JSON for now.

This is not part of the official DFC API but it's a DFC-related API and
therefore we put it in the same namespace.

The DFC Permission Module will make authenticated requests to grant
certain platforms certain permissions.
This commit is contained in:
Maikel Linke
2025-05-15 14:23:19 +10:00
parent 25f396c126
commit 60c8f4ee20
5 changed files with 108 additions and 1 deletions

View File

@@ -19,7 +19,7 @@
:plain
<solid-permissioning
data-src="https://data-server.cqcm.startinblox.com/enterprises/1/platforms"
data-src="#{DfcProvider::Engine.routes.url_helpers.enterprise_platforms_path(@enterprise.id)}"
scopes-uri="https://cdn.startinblox.com/owl/dfc/taxonomies/scopes.jsonld"
noRouter>
</solid-permissioning>

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
module DfcProvider
class PlatformsController < DfcProvider::ApplicationController
before_action :check_enterprise
def index
render json: <<~JSON
{"@context":"https://cdn.startinblox.com/owl/context-bis.jsonld","@id":"https://mydataserver.com/enterprises/1/platforms","dfc-t:platforms":{"@list":[{"@id":"https://waterlooregionfood.ca/portal/profile","@type":"dfc-t:Platform","_id":{"$oid":"682afcc4966dbb3aa7464d56"},"description":"A super duper portal for the waterloo region","dfc-t:hasAssignedScopes":{"@list":[{"@id":"https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/ReadEnterprise","@type":"dfc-t:Scope","dfc-t:scope":"ReadEnterprise"},{"@id":"https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/WriteEnterprise","@type":"dfc-t:Scope","dfc-t:scope":"WriteEnterprise"},{"@id":"https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/ReadProducts","@type":"dfc-t:Scope","dfc-t:scope":"ReadProducts"},{"@id":"https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/WriteProducts","@type":"dfc-t:Scope","dfc-t:scope":"WriteProducts"},{"@id":"https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/ReadOrders","@type":"dfc-t:Scope","dfc-t:scope":"ReadOrders"},{"@id":"https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/WriteOrders","@type":"dfc-t:Scope","dfc-t:scope":"WriteOrders"}],"@type":"rdf:List"},"termsandconditions":"https://waterlooregionfood.ca/terms-and-conditions","title":"Waterloo Region Food Portal"},{"@id":"https://anotherplatform.ca/portal/profile","@type":"dfc-t:Platform","_id":{"$oid":"682b2e2b031c28f69cda1645"},"description":"A super duper portal for the waterloo region","dfc-t:hasAssignedScopes":{"@list":[],"@type":"rdf:List"},"termsandconditions":"https://anotherplatform.ca/terms-and-conditions","title":"anotherplatform Portal"}],"@type":"rdf:List"}}
JSON
end
end
end

View File

@@ -5,6 +5,7 @@ DfcProvider::Engine.routes.draw do
resources :enterprises, only: [:show] do
resources :catalog_items, only: [:index, :show, :update]
resources :offers, only: [:show, :update]
resources :platforms, only: [:index]
resources :supplied_products, only: [:create, :show, :update]
resources :social_medias, only: [:show]
end

View File

@@ -0,0 +1,31 @@
# frozen_string_literal: true
require_relative "../swagger_helper"
RSpec.describe "Platforms", swagger_doc: "dfc.yaml" do
let!(:user) { create(:oidc_user) }
let!(:enterprise) do
create(
:distributor_enterprise,
id: 10_000, owner: user, name: "Fred's Farm",
)
end
before { login_as user }
path "/api/dfc/enterprises/{enterprise_id}/platforms" do
parameter name: :enterprise_id, in: :path, type: :string
get "List platforms with scopes" do
produces "application/json"
response "200", "successful" do
let(:enterprise_id) { enterprise.id }
run_test! do
expect(json_response["@id"]).to eq "https://mydataserver.com/enterprises/1/platforms"
end
end
end
end
end

View File

@@ -558,6 +558,68 @@ paths:
"@type": dfc-b:Person
'404':
description: not found
"/api/dfc/enterprises/{enterprise_id}/platforms":
parameters:
- name: enterprise_id
in: path
required: true
schema:
type: string
get:
summary: List platforms with scopes
tags:
- Platforms
responses:
'200':
description: successful
content:
application/json:
examples:
test_example:
value:
"@context": https://cdn.startinblox.com/owl/context-bis.jsonld
"@id": https://mydataserver.com/enterprises/1/platforms
dfc-t:platforms:
"@list":
- "@id": https://waterlooregionfood.ca/portal/profile
"@type": dfc-t:Platform
_id:
"$oid": 682afcc4966dbb3aa7464d56
description: A super duper portal for the waterloo region
dfc-t:hasAssignedScopes:
"@list":
- "@id": https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/ReadEnterprise
"@type": dfc-t:Scope
dfc-t:scope: ReadEnterprise
- "@id": https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/WriteEnterprise
"@type": dfc-t:Scope
dfc-t:scope: WriteEnterprise
- "@id": https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/ReadProducts
"@type": dfc-t:Scope
dfc-t:scope: ReadProducts
- "@id": https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/WriteProducts
"@type": dfc-t:Scope
dfc-t:scope: WriteProducts
- "@id": https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/ReadOrders
"@type": dfc-t:Scope
dfc-t:scope: ReadOrders
- "@id": https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/WriteOrders
"@type": dfc-t:Scope
dfc-t:scope: WriteOrders
"@type": rdf:List
termsandconditions: https://waterlooregionfood.ca/terms-and-conditions
title: Waterloo Region Food Portal
- "@id": https://anotherplatform.ca/portal/profile
"@type": dfc-t:Platform
_id:
"$oid": 682b2e2b031c28f69cda1645
description: A super duper portal for the waterloo region
dfc-t:hasAssignedScopes:
"@list": []
"@type": rdf:List
termsandconditions: https://anotherplatform.ca/terms-and-conditions
title: anotherplatform Portal
"@type": rdf:List
"/api/dfc/product_groups/{id}":
parameters:
- name: enterprise_id