mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #12153 from rioug/12150-dfc-add-state-to-address
[DFC] Add state to address
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
17
engines/dfc_provider/lib/dfc_provider/address.rb
Normal file
17
engines/dfc_provider/lib/dfc_provider/address.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user