mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
API V1, Customer endpoint: region and country as object
This commit is contained in:
@@ -77,7 +77,8 @@ module Api
|
||||
:phone, :latitude, :longitude,
|
||||
:first_name, :last_name,
|
||||
:street_address_1, :street_address_2,
|
||||
:postal_code, :locality, :region, :country,
|
||||
:postal_code, :locality,
|
||||
{ region: [:name, :code], country: [:name, :code] },
|
||||
]
|
||||
).to_h
|
||||
|
||||
@@ -112,11 +113,11 @@ module Api
|
||||
end
|
||||
|
||||
if address[:state_name].present?
|
||||
address[:state] = Spree::State.find_by(name: address[:state_name])
|
||||
address[:state] = Spree::State.find_by(name: address[:state_name][:name])
|
||||
end
|
||||
|
||||
if address[:country].present?
|
||||
address[:country] = Spree::Country.find_by(name: address[:country])
|
||||
address[:country] = Spree::Country.find_by(name: address[:country][:name])
|
||||
end
|
||||
|
||||
attributes["#{to}_attributes"] = address
|
||||
|
||||
@@ -41,8 +41,8 @@ class CustomerSchema < JsonApiSchema
|
||||
street_address_2: "",
|
||||
postal_code: "1234",
|
||||
locality: "Melbourne",
|
||||
region: "Victoria",
|
||||
country: "Australia",
|
||||
region: { code: "Vic", name: "Victoria" },
|
||||
country: { code: "AUS", name: "Australia" },
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -11,8 +11,18 @@ module Api
|
||||
attribute :street_address_2, &:address2
|
||||
attribute :postal_code, &:zipcode
|
||||
attribute :locality, &:city
|
||||
attribute :region, &:state_name
|
||||
attribute :country, ->(object, _) { object.country.name }
|
||||
attribute :region do |object|
|
||||
{
|
||||
name: object.state.name,
|
||||
code: object.state.abbr,
|
||||
}
|
||||
end
|
||||
attribute :country do |object|
|
||||
{
|
||||
name: object.country.name,
|
||||
code: object.country.iso3,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user