From 4342d3b912dea52945ae71c1528cfabe007b8f10 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 28 Aug 2024 15:06:11 +1000 Subject: [PATCH] Add DFC API endpoint for sales data --- .../affiliate_sales_data_controller.rb | 11 +++++++++ engines/dfc_provider/config/routes.rb | 2 ++ .../requests/affiliate_sales_data_spec.rb | 23 +++++++++++++++++++ swagger/dfc.yaml | 17 ++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 engines/dfc_provider/app/controllers/dfc_provider/affiliate_sales_data_controller.rb create mode 100644 engines/dfc_provider/spec/requests/affiliate_sales_data_spec.rb diff --git a/engines/dfc_provider/app/controllers/dfc_provider/affiliate_sales_data_controller.rb b/engines/dfc_provider/app/controllers/dfc_provider/affiliate_sales_data_controller.rb new file mode 100644 index 0000000000..be26749cbd --- /dev/null +++ b/engines/dfc_provider/app/controllers/dfc_provider/affiliate_sales_data_controller.rb @@ -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 diff --git a/engines/dfc_provider/config/routes.rb b/engines/dfc_provider/config/routes.rb index 5bde8f23ba..8fc0850729 100644 --- a/engines/dfc_provider/config/routes.rb +++ b/engines/dfc_provider/config/routes.rb @@ -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 diff --git a/engines/dfc_provider/spec/requests/affiliate_sales_data_spec.rb b/engines/dfc_provider/spec/requests/affiliate_sales_data_spec.rb new file mode 100644 index 0000000000..08fc18817f --- /dev/null +++ b/engines/dfc_provider/spec/requests/affiliate_sales_data_spec.rb @@ -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 diff --git a/swagger/dfc.yaml b/swagger/dfc.yaml index cc6fa07771..d8d0cd8ed6 100644 --- a/swagger/dfc.yaml +++ b/swagger/dfc.yaml @@ -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