Skip to content

Commit

Permalink
[ARP-86023] ARP IPF: Leverage IPF convenience methods only.
Browse files Browse the repository at this point in the history
  • Loading branch information
nihil2501 committed Sep 5, 2024
1 parent 5e792a7 commit 89953a7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,5 @@ def verify_pilot_enabled_for_user
raise Common::Exceptions::Forbidden, detail: message
end
end

def in_progress_forms_for_user
InProgressForm.submission_pending.where(user_uuid: @current_user.uuid)
end

def form_for_user(form_id)
return unless @current_user

in_progress_forms_for_user.find_by(form_id:)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ module V0
# Form21aController handles the submission of Form 21a to the accreditation service.
# It parses the request body, submits the form via AccreditationService, and processes the response.
class Form21aController < ApplicationController
FORM_ID = '21a'

before_action :parse_request_body, only: [:submit]

# Parses the request body and submits the form.
# Renders the appropriate response based on the service's outcome.
def submit
response = AccreditationService.submit_form21a(parsed_request_body)

form_for_user('21a')&.destroy if response.success?
InProgressForm.form_for_user(FORM_ID, @current_user)&.destroy if response.success?
render_ogc_service_response(response)
rescue => e
Rails.logger.error("Form21aController: Unexpected error occurred - #{e.message}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module AccreditedRepresentativePortal
module V0
class InProgressFormsController < ApplicationController
def update
form = InProgressForm.where(form_id:, user_uuid: @current_user.uuid).first_or_initialize
form = in_progress_form || new_form_for_user(form_id, @current_user)
form.update!(form_data: params[:formData], metadata: params[:metadata])

render json: form, key_transform: :unaltered
Expand All @@ -23,10 +23,28 @@ def destroy

private

def in_progress_form
return @in_progress_form if defined?(@in_progress_form)
# NOTE: The in-progress form module can upstream this convenience that
# allows the caller to not know about the details of legacy foreign key
# relations. It is totally analogous to the query convenience
# `form_for_user` that they expose.
def new_form_for_user(form_id, user)
form =
InProgressForm.new(
form_id:,
user_uuid: user.uuid,
user_account: user.user_account
)

form.real_user_uuid = user.uuid
form
end

@in_progress_form = form_for_user(form_id)
def in_progress_form
@in_progress_form ||=
InProgressForm.form_for_user(
form_id,
@current_user
)
end

def form_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def show
private

def in_progress_forms
in_progress_forms_for_user.map do |form|
InProgressForm.for_user(@current_user).map do |form|
{
form: form.form_id,
metadata: form.metadata,
Expand Down

0 comments on commit 89953a7

Please sign in to comment.