Merge pull request #12153 from rioug/12150-dfc-add-state-to-address

[DFC] Add state to address
This commit is contained in:
David Cook
2024-02-16 10:30:28 +11:00
committed by GitHub
5 changed files with 29 additions and 2 deletions

View File

@@ -2,12 +2,13 @@
class AddressBuilder < DfcBuilder
def self.address(address)
DataFoodConsortium::Connector::Address.new(
DfcProvider::Address.new(
urls.address_url(address),
street: address.address1,
postalCode: address.zipcode,
city: address.city,
country: address.country.name
country: address.country.name,
region: address.state.name
)
end
end

View File

@@ -8,6 +8,7 @@ require "dfc_provider/engine"
# Custom data types
require "dfc_provider/supplied_product"
require "dfc_provider/address"
module DfcProvider
DataFoodConsortium::Connector::Importer.register_type(SuppliedProduct)

View File

@@ -0,0 +1,17 @@
# frozen_string_literal: true
# Temporary solution to add `region` to Address, to be removed once the DFC connector supports it
module DfcProvider
class Address < DataFoodConsortium::Connector::Address
# @return [String]
attr_accessor :region
def initialize(semantic_id, region: "", **properties)
super(semantic_id, **properties)
@region = region
registerSemanticProperty("dfc-b:region", &method("region")).valueSetter = method("region=")
end
end
end

View File

@@ -8,6 +8,7 @@ describe AddressBuilder do
build(
:address,
id: 1, address1: "Paradise 15", zipcode: "0001", city: "Goosnargh",
state: build(:state, name: "Victoria")
)
}
@@ -33,5 +34,9 @@ describe AddressBuilder do
it "assigns a country" do
expect(result.country).to eq "Australia"
end
it "assigns a region" do
expect(result.region).to eq "Victoria"
end
end
end

View File

@@ -64,6 +64,7 @@ paths:
dfc-b:hasPostalCode: '20170'
dfc-b:hasCity: Herndon
dfc-b:hasCountry: Australia
dfc-b:region: Victoria
'404':
description: not found
"/api/dfc/enterprises/{enterprise_id}/catalog_items":
@@ -339,6 +340,7 @@ paths:
dfc-b:hasPostalCode: '20170'
dfc-b:hasCity: Herndon
dfc-b:hasCountry: Australia
dfc-b:region: Victoria
"/api/dfc/enterprises/{id}":
get:
summary: Show enterprise
@@ -383,6 +385,7 @@ paths:
dfc-b:hasPostalCode: '20170'
dfc-b:hasCity: Herndon
dfc-b:hasCountry: Australia
dfc-b:region: Victoria
- "@id": http://test.host/api/dfc/enterprises/10000/supplied_products/10001
"@type": dfc-b:SuppliedProduct
dfc-b:name: Apple - 1g