Replace SuppliedProductSerializer with DFC Connector

And remove the BaseSerializer because this was the last serializer.
This commit is contained in:
Maikel Linke
2023-03-14 16:17:54 +11:00
parent 0b808a4b1e
commit 80edc44ef5
4 changed files with 2 additions and 115 deletions

View File

@@ -7,7 +7,8 @@ module DfcProvider
before_action :check_enterprise
def show
render json: variant, serializer: DfcProvider::SuppliedProductSerializer
product = DfcBuilder.supplied_product(variant)
render json: DfcLoader.connector.export(product)
end
def update

View File

@@ -1,13 +0,0 @@
# frozen_string_literal: true
# Serializer used to render the DFC Address from an OFN User
# into JSON-LD format based on DFC ontology
module DfcProvider
class BaseSerializer < ActiveModel::Serializer
private
def dfc_provider_routes
DfcProvider::Engine.routes.url_helpers
end
end
end

View File

@@ -1,67 +0,0 @@
# frozen_string_literal: true
# Serializer used to render a DFC SuppliedProduct from an OFN Variant
# into JSON-LD format based on DFC ontology
module DfcProvider
class SuppliedProductSerializer < BaseSerializer
attribute :id, key: '@id'
attribute :type, key: '@type'
attribute :unit, key: 'dfc-b:hasUnit'
attribute :quantity, key: 'dfc-b:quantity'
attribute :description, key: 'dfc-b:description'
attribute :total_theoritical_stock, key: 'dfc-b:totalTheoriticalStock'
attribute :brand, key: 'dfc-b:brand'
attribute :claim, key: 'dfc-b:claim'
attribute :image, key: 'dfc-b:image'
attribute :life_time, key: 'lifeTime'
has_many :physical_characteristics, key: 'dfc-b:physicalCharacterisctics'
def id
dfc_provider_routes.enterprise_supplied_product_url(
enterprise_id: object.product.supplier_id,
id: object.id,
)
end
def type
'dfc:SuppliedProduct'
end
def unit
{
'@id' => "/unit/#{unit_name}",
'rdfs:label' => unit_name
}
end
def quantity
object.on_hand
end
def description
object.name
end
def total_theoritical_stock; end
def brand; end
def claim; end
def image
object.images.first&.url(:product)
end
def life_time; end
def physical_characteristics
[]
end
private
def unit_name
object.unit_description.presence || 'piece'
end
end
end

View File

@@ -1,34 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
describe DfcProvider::SuppliedProductSerializer do
let!(:product) { create(:simple_product ) }
let!(:variant) { product.variants.first }
subject { described_class.new(variant) }
describe '#id' do
let(:supplied_product_id) {
[
"http://test.host/api/dfc-v1.6/enterprises/",
product.supplier_id,
"/supplied_products/",
variant.id
].join
}
it 'returns the expected value' do
expect(subject.id).to eq(supplied_product_id)
end
end
describe '#unit' do
it 'returns the rdfs label value' do
expect(subject.unit).to eq(
'@id' => '/unit/piece',
'rdfs:label' => 'piece'
)
end
end
end