Show Offers on the DFC API

This commit is contained in:
Maikel Linke
2024-01-11 15:59:30 +11:00
parent 4bac83dd83
commit 8d6ae18fb6
4 changed files with 84 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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