-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into contact-data-migrations
- Loading branch information
Showing
23 changed files
with
286 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module API | ||
module V1 | ||
class AddressesController < BaseController | ||
def index | ||
respond_with_resource(beneficiary.addresses) | ||
end | ||
|
||
def create | ||
validate_request_schema( | ||
with: ::V1::BeneficiaryAddressRequestSchema, | ||
schema_options: { beneficiary: }, | ||
location: ->(resource) { api_v1_beneficiary_address_path(beneficiary, resource) } | ||
) do |permitted_params| | ||
beneficiary.addresses.create!(permitted_params) | ||
end | ||
end | ||
|
||
def show | ||
address = beneficiary.addresses.find(params[:id]) | ||
respond_with_resource(address) | ||
end | ||
|
||
def destroy | ||
address = beneficiary.addresses.find(params[:id]) | ||
address.destroy! | ||
|
||
head :no_content | ||
end | ||
|
||
def beneficiary | ||
@beneficiary ||= current_account.beneficiaries.find(params[:beneficiary_id]) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
class BeneficiaryAddress < ApplicationRecord | ||
extend Enumerize | ||
|
||
enumerize :iso_country_code, in: ISO3166::Country.codes.freeze | ||
|
||
belongs_to :beneficiary, class_name: "Contact" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
app/request_schemas/v1/beneficiary_address_request_schema.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module V1 | ||
class BeneficiaryAddressRequestSchema < JSONAPIRequestSchema | ||
params do | ||
required(:data).value(:hash).schema do | ||
required(:type).filled(:str?, eql?: "address") | ||
required(:attributes).value(:hash).schema do | ||
required(:iso_country_code).filled(Types::UpcaseString, included_in?: Contact.iso_country_code.values) | ||
required(:iso_region_code).filled(:string) | ||
optional(:administrative_division_level_2_code).maybe(:string) | ||
optional(:administrative_division_level_2_name).maybe(:string) | ||
optional(:administrative_division_level_3_code).maybe(:string) | ||
optional(:administrative_division_level_3_name).maybe(:string) | ||
optional(:administrative_division_level_4_code).maybe(:string) | ||
optional(:administrative_division_level_4_name).maybe(:string) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.