diff --git a/app/controllers/uprn_address_spike_controller.rb b/app/controllers/uprn_address_spike_controller.rb index 9876dd8b0..4fd2776b6 100644 --- a/app/controllers/uprn_address_spike_controller.rb +++ b/app/controllers/uprn_address_spike_controller.rb @@ -2,21 +2,21 @@ class UprnAddressSpikeController < ApplicationController def show if params[:uprn] || params[:address] - if params[:uprn] + if params[:uprn].present? uprn = params[:uprn] service = UprnClient.new(uprn) service.call if service.error.present? - @error = "no match" + @error = "No match" else @address_returned = UprnDataPresenter.new(service.result) end - elsif params[:address] - address = params[:address] - service = AddressClient.new(address) + elsif params.values_at(:address_line1, :address_line2, :town_or_city, :postcode).any?(&:present?) + @address_given = params.values_at(:address_line1, :address_line2, :town_or_city, :postcode).reject { |item| item == "" }.join(", ") + service = AddressClient.new(@address_given) service.call if service.error.present? - @error = "no match" + @error = "No matches" else @addresses_returned = service.result&.map { |r| AddressDataPresenter.new(r) } end diff --git a/app/views/content/uprn_address_spike.html.erb b/app/views/content/uprn_address_spike.html.erb index df04d176f..9a76ef6cc 100644 --- a/app/views/content/uprn_address_spike.html.erb +++ b/app/views/content/uprn_address_spike.html.erb @@ -1,39 +1,65 @@ -
- - - -<% if params[:uprn] %> -<%= params[:uprn] %>
- <% if @error.present? %> - <%= @error %> - <% elsif @address_returned.present? %> -<%= @address_returned.address_line1 %>
-<%= @address_returned.address_line2 %>
-<%= @address_returned.town_or_city %>
-<%= @address_returned.postcode %>
- <% end %> -<% elsif params[:address] %> -<%= params[:address] %>
- <% if @error.present? %> - <%= @error %> - <% elsif @addresses_returned.present? %> -Address: <%= address_returned.address %>
-UPRN: <%= address_returned.uprn %>
-Confidence: <%= address_returned.match%> (<%= address_returned.match_description %>)
-OR enter an address
+<%= params[:uprn] %>
+ <% if @error.present? %> +<%= @address_returned.address_line1 %>
+<%= @address_returned.address_line2 %>
+<%= @address_returned.town_or_city %>
+<%= @address_returned.postcode %>
+ <% end %> + <% elsif @address_given.present? %> +<%= @address_given %>
+ <% if @error.present? %> +Address: <%= address_returned.address %>
+UPRN: <%= address_returned.uprn %>
+Confidence: <%= address_returned.match%> (<%= address_returned.match_description %>)
+