diff --git a/engines/dfc_provider/app/controllers/dfc_provider/offers_controller.rb b/engines/dfc_provider/app/controllers/dfc_provider/offers_controller.rb new file mode 100644 index 0000000000..6be9f004c4 --- /dev/null +++ b/engines/dfc_provider/app/controllers/dfc_provider/offers_controller.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module DfcProvider + class OffersController < DfcProvider::ApplicationController + before_action :check_enterprise + + def show + subject = DfcBuilder.offer(variant) + render json: DfcIo.export(subject) + end + + private + + def variant + @variant ||= current_enterprise.supplied_variants.find(params[:id]) + end + end +end diff --git a/engines/dfc_provider/config/routes.rb b/engines/dfc_provider/config/routes.rb index 26762340ac..24dba7201a 100644 --- a/engines/dfc_provider/config/routes.rb +++ b/engines/dfc_provider/config/routes.rb @@ -4,6 +4,7 @@ DfcProvider::Engine.routes.draw do resources :addresses, only: [:show] resources :enterprises, only: [:show] do resources :catalog_items, only: [:index, :show, :update] + resources :offers, only: [:show] resources :supplied_products, only: [:create, :show, :update] resources :social_medias, only: [:show] end diff --git a/engines/dfc_provider/spec/requests/offers_spec.rb b/engines/dfc_provider/spec/requests/offers_spec.rb new file mode 100644 index 0000000000..d29146527d --- /dev/null +++ b/engines/dfc_provider/spec/requests/offers_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require_relative "../swagger_helper" + +describe "Offers", type: :request, swagger_doc: "dfc.yaml", rswag_autodoc: true do + let!(:user) { create(:oidc_user) } + let!(:enterprise) { create(:distributor_enterprise, id: 10_000, owner: user) } + let!(:product) { + create( + :product, + id: 90_000, + supplier: enterprise, name: "Pesto", description: "Basil Pesto", + variants: [variant], + ) + } + let(:variant) { build(:base_variant, id: 10_001, unit_value: 1) } + + before { login_as user } + + path "/api/dfc/enterprises/{enterprise_id}/offers/{id}" do + parameter name: :enterprise_id, in: :path, type: :string + parameter name: :id, in: :path, type: :string + + let(:enterprise_id) { enterprise.id } + + get "Show Offer" do + produces "application/json" + + response "200", "success" do + let(:id) { variant.id } + + run_test! + end + end + end +end diff --git a/swagger/dfc.yaml b/swagger/dfc.yaml index cafd36a9ad..b791778324 100644 --- a/swagger/dfc.yaml +++ b/swagger/dfc.yaml @@ -409,6 +409,35 @@ paths: dfc-b:URL: https://facebook.com/user '404': description: not found + "/api/dfc/enterprises/{enterprise_id}/offers/{id}": + parameters: + - name: enterprise_id + in: path + required: true + schema: + type: string + - name: id + in: path + required: true + schema: + type: string + get: + summary: Show Offer + tags: + - Offers + responses: + '200': + description: success + content: + application/json: + examples: + test_example: + value: + "@context": https://www.datafoodconsortium.org + "@id": http://test.host/api/dfc/enterprises/10000/offers/10001 + "@type": dfc-b:Offer + dfc-b:hasPrice: 19.99 + dfc-b:stockLimitation: 5 "/api/dfc/persons/{id}": get: summary: Show person