Add DFC API endpoint for sales data

This commit is contained in:
Maikel Linke
2024-08-28 15:06:11 +10:00
parent af3aed827a
commit 4342d3b912
4 changed files with 53 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
# frozen_string_literal: true
module DfcProvider
# Aggregates anonymised sales data for a research project.
class AffiliateSalesDataController < DfcProvider::ApplicationController
def show
person = PersonBuilder.person(current_user)
render json: DfcIo.export(person)
end
end
end

View File

@@ -12,4 +12,6 @@ DfcProvider::Engine.routes.draw do
resources :affiliated_by, only: [:create, :destroy], module: 'enterprise_groups'
end
resources :persons, only: [:show]
resource :affiliate_sales_data, only: [:show]
end

View File

@@ -0,0 +1,23 @@
# frozen_string_literal: true
require_relative "../swagger_helper"
RSpec.describe "AffiliateSalesData", swagger_doc: "dfc.yaml", rswag_autodoc: true do
let(:user) { create(:oidc_user, id: 10_000) }
before { login_as user }
path "/api/dfc/affiliate_sales_data" do
get "Show sales data of person's affiliate enterprises" do
produces "application/json"
response "200", "successful" do
run_test! do
expect(json_response).to include(
"@id" => "http://test.host/api/dfc/persons/10000",
)
end
end
end
end
end

View File

@@ -69,6 +69,23 @@ paths:
dfc-b:region: Victoria
'404':
description: not found
"/api/dfc/affiliate_sales_data":
get:
summary: Show sales data of person's affiliate enterprises
tags:
- AffiliateSalesData
responses:
'200':
description: successful
content:
application/json:
examples:
test_example:
value:
"@context": https://www.datafoodconsortium.org
"@id": http://test.host/api/dfc/persons/10000
"@type": dfc-b:Person
dfc-b:logo: ''
"/api/dfc/enterprises/{enterprise_id}/catalog_items":
parameters:
- name: enterprise_id