mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-03 22:06:07 +00:00
Encapsulate DFC-OFN data model bridge
Re-uses existing code and takes knowledge out of the controller.
This commit is contained in:
@@ -34,13 +34,10 @@ module DfcProvider
|
||||
|
||||
return head :bad_request unless supplied_product
|
||||
|
||||
variant.product.update!(
|
||||
description: supplied_product.description,
|
||||
)
|
||||
SuppliedProductBuilder.apply(supplied_product, variant)
|
||||
|
||||
variant.update!(
|
||||
unit_value: supplied_product.quantity.value,
|
||||
)
|
||||
variant.product.save!
|
||||
variant.save!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -26,4 +26,14 @@ class SuppliedProductBuilder < DfcBuilder
|
||||
QuantitativeValueBuilder.apply(supplied_product.quantity, product)
|
||||
end
|
||||
end
|
||||
|
||||
def self.apply(supplied_product, variant)
|
||||
variant.product.assign_attributes(
|
||||
name: supplied_product.name,
|
||||
description: supplied_product.description,
|
||||
)
|
||||
|
||||
QuantitativeValueBuilder.apply(supplied_product.quantity, variant.product)
|
||||
variant.unit_value = variant.product.unit_value
|
||||
end
|
||||
end
|
||||
|
||||
@@ -148,6 +148,7 @@ describe "SuppliedProducts", type: :request, swagger_doc: "dfc-v1.7/swagger.yaml
|
||||
submit_request(example.metadata)
|
||||
variant.reload
|
||||
}.to change { variant.description }.to("DFC-Pesto updated")
|
||||
.and change { variant.name }.to("Pesto novo")
|
||||
.and change { variant.unit_value }.to(17)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user