Skip to content

Commit

Permalink
Use patch method to send ownership certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
cdccollins committed Dec 19, 2023
1 parent 1544081 commit 2152ad9
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 29 deletions.
10 changes: 7 additions & 3 deletions app/controllers/land_owners_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ def new
end

def create
@land_owner = LandOwner.new(land_owner_params)
@land_owner = LandOwner.new(land_owner_params.except(:change_access_id))

if @land_owner.save
redirect_to planning_application_ownership_certificate_path(@planning_application["id"], @ownership_certificate)
redirect_to planning_application_ownership_certificate_path(
@planning_application["id"],
@ownership_certificate,
change_access_id: land_owner_params[:change_access_id]
)
else
respond_to do |format|
format.html { render :new }
Expand All @@ -31,7 +35,7 @@ def set_certificate

def land_owner_params
params.require(:land_owner)
.permit(:name, :address_1, :address_2, :town, :country, :postcode, :notice_given_at)
.permit(:name, :address_1, :address_2, :town, :country, :postcode, :notice_given_at, :change_access_id)
.to_h.merge(ownership_certificate_id: @ownership_certificate.id)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def update
@ownership_certificate_validation_request = build_validation_request(ownership_certificate_validation_request_params)

if ownership_certificate_validation_request_params[:approved] == "yes"
redirect_to new_planning_application_ownership_certificate_path(params[:planning_application_id])
redirect_to new_planning_application_ownership_certificate_path(params[:planning_application_id], change_access_id: params[:change_access_id])
else
if @ownership_certificate_validation_request.update
respond_to do |format|
Expand Down
28 changes: 20 additions & 8 deletions app/controllers/ownership_certificates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ def show
end

def create
@ownership_certificate = OwnershipCertificate.new(ownership_certificate_params)
@ownership_certificate = OwnershipCertificate.new(ownership_certificate_params.except(:change_access_id))

if @ownership_certificate.save
redirect_to planning_application_ownership_certificate_path(@planning_application["id"], @ownership_certificate)
redirect_to planning_application_ownership_certificate_path(
@planning_application["id"],
@ownership_certificate,
change_access_id: ownership_certificate_params[:change_access_id]
)
else
respond_to do |format|
format.html { render :new }
Expand All @@ -27,12 +31,20 @@ def thank_you
end

def submit
if Bops::OwnershipCertificate.create(
params[:planning_application_id],
data: @ownership_certificate,
land_owners_attributes: @ownership_certificate.land_owners
validation_requests = Apis::Bops::Client.get_validation_requests(@planning_application["id"], params[:change_access_id])
ownership_certificate_validation_request_id = validation_requests["data"]["ownership_certificate_validation_requests"].first["id"]

if Bops::OwnershipCertificateValidationRequest.approve(
ownership_certificate_validation_request_id,
@planning_application["id"],
params[:change_access_id],
params: {
certificate_type: @ownership_certificate.certificate_type,
land_owners_attributes: @ownership_certificate.land_owners
}
)
redirect_to thank_you_planning_application_ownership_certificates_path(@planning_application["id"], @ownership_certificate)

redirect_to planning_application_ownership_certificate_thank_you_path(@planning_application["id"], @ownership_certificate)
else
render :show
end
Expand All @@ -54,7 +66,7 @@ def set_planning_application

def ownership_certificate_params
params.require(:ownership_certificate)
.permit(:know_owners, :number_of_owners, :certificate_type, :notification_of_owners)
.permit(:know_owners, :number_of_owners, :certificate_type, :notification_of_owners, :change_access_id)
.to_h.merge(planning_application_id: @planning_application["id"])
end
end
4 changes: 2 additions & 2 deletions app/models/bops/ownership_certificate_validation_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def find(id, planning_application_id, change_access_id)
Apis::Bops::Client.get_ownership_certificate_validation_request(id, planning_application_id, change_access_id)
end

def approve(id, planning_application_id, change_access_id)
Apis::Bops::Client.patch_approved_ownership_certificate(id, planning_application_id, change_access_id)
def approve(id, planning_application_id, change_access_id, params)
Apis::Bops::Client.patch_approved_ownership_certificate(id, planning_application_id, change_access_id, params)
end

def reject(id, planning_application_id, change_access_id, rejection_reason)
Expand Down
14 changes: 2 additions & 12 deletions app/services/apis/bops/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ def get_ownership_certificate_validation_request(id, planning_application_id, ch
)
end

def patch_approved_ownership_certificate(id, planning_application_id, change_access_id)
def patch_approved_ownership_certificate(id, planning_application_id, change_access_id, params)
request(
http_method: :patch,
endpoint: "planning_applications/#{planning_application_id}/ownership_certificate_validation_requests/#{id}?change_access_id=#{change_access_id}",
params: {
data: {
params: params[:params],
approved: true
}
}.to_json
Expand Down Expand Up @@ -222,17 +223,6 @@ def patch_replacement_document(id, planning_application_id, change_access_id, fi
)
end

def post_ownership_certificate(planning_application_id, certificate_type:, land_owners_attributes:)
request(
http_method: :post,
endpoint: "planning_applications/#{planning_application_id}/ownership_certificates",
params: {
certificate_type:,
land_owners_attributes:
}.to_json
)
end

private

def request(http_method:, endpoint:, params: {}, upload_file: false)
Expand Down
1 change: 1 addition & 0 deletions app/views/land_owners/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<%= form.govuk_text_field :postcode, label: { text: "Postcode" } %>
<%= form.govuk_date_field :notice_given_at, legend: { text: "What date was notice given to this owner?", size: "s" } %>
<%= form.hidden_field :change_access_id, value: params[:change_access_id] %>
<%= form.govuk_submit "Add owner" %>
<%= link_to "Back", planning_application_ownership_certificate_path(@planning_application["id"], @ownership_certificate), class: "govuk-button govuk-button--secondary" %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/ownership_certificates/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</p>
<% end %>
<% end %>
<%= form.hidden_field :change_access_id, value: params[:change_access_id] %>
<%= form.govuk_submit "Continue" %>
<%# <%= link_to "Back", edit_ownership_certificate_validation_request_path(), class: "govuk-button govuk-button--secondary" %> %>
<button type="submit" name="move_back" class="govuk-button govuk-button--secondary" data-disable-with="Back">Back</button>
Expand Down
5 changes: 3 additions & 2 deletions app/views/ownership_certificates/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<% end %>
</tbody>
</table>
<%= link_to "Add another owner", new_planning_application_ownership_certificate_land_owner_path(@planning_application["id"], @ownership_certificate), class: "govuk-button govuk-button--secondary" %>
<%= link_to "Add another owner", new_planning_application_ownership_certificate_land_owner_path(@planning_application["id"], @ownership_certificate, change_access_id: params[:change_access_id]), class: "govuk-button govuk-button--secondary" %>
<% end %>

<h3 class="govuk-heading-s">
Expand All @@ -75,7 +75,8 @@
By submitting this information you are confirming that, to the best of your knowledge,
the details you are providing are correct.
</p>
<%= link_to "Accept and send", planning_application_ownership_certificate_submit_path(@planning_application["id"], @ownership_certificate), method: :post, class: "govuk-button" %>
<%= hidden_field :change_access_id, value: params[:change_access_id] %>
<%= link_to "Accept and send", planning_application_ownership_certificate_submit_path(@planning_application["id"], @ownership_certificate, change_access_id: params[:change_access_id]), method: :post, class: "govuk-button" %>
<%= link_to "Back", new_planning_application_ownership_certificate_path(@planning_application["id"]), class: "govuk-button govuk-button--secondary" %>
</div>
</div>

0 comments on commit 2152ad9

Please sign in to comment.