From 2f7b1111314a1f889427ef9b7b31ac000d2fd9c3 Mon Sep 17 00:00:00 2001 From: Tyler Coleman Date: Thu, 7 Nov 2024 13:56:51 -0800 Subject: [PATCH] add filters --- .../power_of_attorney/request_controller.rb | 8 +++--- .../manage_representative_service.rb | 26 +++++++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/modules/claims_api/app/controllers/claims_api/v2/veterans/power_of_attorney/request_controller.rb b/modules/claims_api/app/controllers/claims_api/v2/veterans/power_of_attorney/request_controller.rb index 2a3ba88f7f5..6007e6d2739 100644 --- a/modules/claims_api/app/controllers/claims_api/v2/veterans/power_of_attorney/request_controller.rb +++ b/modules/claims_api/app/controllers/claims_api/v2/veterans/power_of_attorney/request_controller.rb @@ -32,7 +32,7 @@ def index service = ManageRepresentativeService.new(external_uid: 'power_of_attorney_request_uid', external_key: 'power_of_attorney_request_key') - res = service.read_poa_request(poa_codes:, page_size:, page_index:) + res = service.read_poa_request(poa_codes:, page_size:, page_index:, filter:) poa_list = res['poaRequestRespondReturnVOList'] @@ -136,7 +136,7 @@ def build_bgs_attributes(form_attributes) def validate_filter!(filter) return nil if filter.blank? - valid_filters = %w[status state city country sensitivityLevel] + valid_filters = %w[status state city country] invalid_filters = filter.keys - valid_filters @@ -158,9 +158,9 @@ def validate_statuses!(statuses) ) end - valid_statuses = %w[new accepted declined] + valid_statuses = ManageRepresentativeService::ALL_STATUSES - if statuses.any? { |status| valid_statuses.exclude?(status.downcase) } + if statuses.any? { |status| valid_statuses.exclude?(status.upcase) } raise ::Common::Exceptions::UnprocessableEntity.new( detail: "Status(es) must be one of: #{valid_statuses.join(', ')}" ) diff --git a/modules/claims_api/lib/bgs_service/manage_representative_service.rb b/modules/claims_api/lib/bgs_service/manage_representative_service.rb index bef13989ac7..e86ac4f14f5 100644 --- a/modules/claims_api/lib/bgs_service/manage_representative_service.rb +++ b/modules/claims_api/lib/bgs_service/manage_representative_service.rb @@ -2,15 +2,22 @@ module ClaimsApi class ManageRepresentativeService < ClaimsApi::LocalBGS + ALL_STATUSES = %w[NEW ACCEPTED DECLINED].freeze + def bean_name 'VDC/ManageRepresentativeService' end - def read_poa_request(poa_codes: [], page_size: nil, page_index: nil) # rubocop:disable Metrics/MethodLength + def read_poa_request(poa_codes: [], page_size: nil, page_index: nil, filter: {}) # rubocop:disable Metrics/MethodLength # Workaround to allow multiple roots in the Nokogiri XML builder # https://stackoverflow.com/a/4907450 doc = Nokogiri::XML::DocumentFragment.parse '' + status_list = filter['status'].presence || ALL_STATUSES + state = filter['state'] + city = filter['city'] + country = filter['country'] + Nokogiri::XML::Builder.with(doc) do |xml| xml.send('data:POACodeList') do poa_codes.each do |poa_code| @@ -18,10 +25,25 @@ def read_poa_request(poa_codes: [], page_size: nil, page_index: nil) # rubocop:d end end xml.send('data:SecondaryStatusList') do - %w[New Pending Accepted Declined].each do |status| + status_list.each do |status| xml.SecondaryStatus status end end + if state + xml.send('data:StateList') do + xml.State state + end + end + if city + xml.send('data:CityList') do + xml.City city + end + end + if country + xml.send('data:CountryList') do + xml.Country country + end + end if page_size || page_index xml.send('data:POARequestParameter') do xml.pageSize page_size if page_size