Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cities and countries to DFC affiliate sales data endpoint #12964

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@ def initialize(row)
def build_supplier
DataFoodConsortium::Connector::Enterprise.new(
nil,
localizations: [build_address(item[:supplier_postcode])],
localizations: [build_address(
item[:supplier_postcode],
item[:supplier_city],
item[:supplier_country]
)],
suppliedProducts: [build_product],
)
end

def build_distributor
DataFoodConsortium::Connector::Enterprise.new(
nil,
localizations: [build_address(item[:distributor_postcode])],
localizations: [build_address(
item[:distributor_postcode],
item[:distributor_city],
item[:distributor_country]
)],
)
end

Expand Down Expand Up @@ -89,9 +97,11 @@ def build_price
)
end

def build_address(postcode)
def build_address(postcode, city, country)
DataFoodConsortium::Connector::Address.new(
nil,
city:,
country:,
postalCode: postcode,
)
end
Expand Down
16 changes: 15 additions & 1 deletion engines/dfc_provider/app/services/affiliate_sales_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ def tables
JOIN spree_products ON spree_products.id = spree_variants.product_id
JOIN enterprises AS suppliers ON suppliers.id = spree_variants.supplier_id
JOIN spree_addresses AS supplier_addresses ON supplier_addresses.id = suppliers.address_id
JOIN spree_countries AS supplier_countries ON supplier_countries.id = supplier_addresses.country_id
JOIN spree_orders ON spree_orders.id = spree_line_items.order_id
JOIN enterprises AS distributors ON distributors.id = spree_orders.distributor_id
JOIN spree_addresses AS distributor_addresses ON distributor_addresses.id = distributors.address_id
JOIN spree_countries AS distributor_countries ON distributor_countries.id = distributor_addresses.country_id
SQL
end

Expand All @@ -53,7 +55,11 @@ def fields
spree_variants.unit_presentation,
spree_line_items.price,
distributor_addresses.zipcode AS distributor_postcode,
distributor_addresses.city AS distributor_city,
distributor_countries.name AS distributor_country,
supplier_addresses.zipcode AS supplier_postcode,
supplier_addresses.city AS supplier_city,
supplier_countries.name AS supplier_country,

SUM(spree_line_items.quantity) AS quantity_sold
SQL
Expand All @@ -68,7 +74,11 @@ def key_fields
spree_variants.unit_presentation,
spree_line_items.price,
distributor_postcode,
supplier_postcode
supplier_postcode,
distributor_city,
supplier_city,
distributor_country,
supplier_country
SQL
end

Expand All @@ -82,7 +92,11 @@ def labels
unit_presentation
price
distributor_postcode
distributor_city
distributor_country
supplier_postcode
supplier_city
supplier_country
quantity_sold
]
end
Expand Down
16 changes: 14 additions & 2 deletions engines/dfc_provider/spec/services/affiliate_sales_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,17 @@
it "converts an array to a hash" do
row = [
"Apples",
"item", "item", nil, nil,
"item",
"item",
nil,
nil,
15.50,
"3210", "3211",
"3210",
"city1",
"country1",
"3211",
"city2",
"country2",
3,
]
expect(query.label_row(row)).to eq(
Expand All @@ -67,7 +75,11 @@
unit_presentation: nil,
price: 15.50,
distributor_postcode: "3210",
distributor_city: "city1",
distributor_country: "country1",
supplier_postcode: "3211",
supplier_city: "city2",
supplier_country: "country2",
quantity_sold: 3,
}
)
Expand Down
6 changes: 5 additions & 1 deletion swagger/dfc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ paths:
dfc-b:hasAddress:
"@type": dfc-b:Address
dfc-b:hasPostalCode: '20170'
dfc-b:hasCity: Herndon
dfc-b:hasCountry: Australia
dfc-b:supplies:
"@type": dfc-b:SuppliedProduct
dfc-b:name: Tomato
dfc-b:hasQuantity:
"@type": dfc-b:QuantitativeValue
dfc-b:hasUnit: dfc-m:Gram
dfc-b:hasUnit: dfc-m:Piece
dfc-b:value: 1.0
dfc-b:concernedBy:
"@type": dfc-b:OrderLine
Expand All @@ -124,6 +126,8 @@ paths:
dfc-b:hasAddress:
"@type": dfc-b:Address
dfc-b:hasPostalCode: '20170'
dfc-b:hasCity: Herndon
dfc-b:hasCountry: Australia
'400':
description: bad request
"/api/dfc/enterprises/{enterprise_id}/catalog_items":
Expand Down
Loading