Class: V0::CoeController
Constant Summary
ApplicationController::VERSION_STATUS
SignIn::Authentication::BEARER_PATTERN
ExceptionHandling::SKIP_SENTRY_EXCEPTION_TYPES
Instance Attribute Summary
#current_user
Instance Method Summary
collapse
#clear_saved_form, #cors_preflight, #pagination_params, #render_job_id, #routing_error, #set_csrf_header
Methods included from Traceable
#set_trace_tags
#set_tags_and_extra_context, #tags_context, #user_context
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
#append_info_to_payload
#access_token, #access_token_authenticate, #authenticate, #authenticate_access_token, #bearer_token, #cookie_access_token, #handle_authenticate_error, #load_user, #load_user_object, #scrub_bearer_token, #validate_request_ip
Methods included from Headers
#set_app_info_headers
#render_errors, #report_mapped_exception, #report_original_exception, #skip_sentry_exception?, #skip_sentry_exception_types
#authenticate, #clear_session, #extend_session!, #load_user, #log_sso_info, #render_unauthorized, #reset_session, #set_api_cookie!, #set_current_user, #set_session_expiration_header, #set_session_object, #sign_in_service_exp_time, #sign_in_service_session, #sso_cookie_content, #sso_logging_info, #validate_inbound_login_params, #validate_session
#authenticate, #validate_audience!
Instance Method Details
#attachments ⇒ Object
97
98
99
|
# File 'app/controllers/v0/coe_controller.rb', line 97
def attachments
params[:files]
end
|
#build_document_data(attachment) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'app/controllers/v0/coe_controller.rb', line 105
def build_document_data(attachment)
file_data = attachment['file']
index = file_data.index(';base64,') || 0
file_data = file_data[index + 8..] if index.positive?
{
'documentType' => attachment['file_type'],
'description' => attachment['document_type'],
'contentsBase64' => file_data,
'fileName' => attachment['file_name']
}
end
|
#document_download ⇒ Object
82
83
84
85
|
# File 'app/controllers/v0/coe_controller.rb', line 82
def document_download
res = lgy_service.get_document(params[:id])
send_data(res.body, type: 'application/pdf', disposition: 'attachment')
end
|
#document_upload ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'app/controllers/v0/coe_controller.rb', line 48
def document_upload
status = 201
attachments.each do |attachment|
file_extension = attachment['file_type']
if %w[jpg jpeg png pdf].include? file_extension.downcase
document_data = build_document_data(attachment)
status = post_document(document_data)
break unless status == 201
end
end
render(json: status, status: status == 201 ? 200 : 500)
end
|
#documents ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
|
# File 'app/controllers/v0/coe_controller.rb', line 36
def documents
documents = lgy_service.get_coe_documents.body
notification_letters = documents.reject { |doc| doc['document_type']&.include?('Veteran Correspondence') }
sorted_notification_letters = notification_letters.sort_by { |doc| doc['create_date'] }.reverse
render json: { data: { attributes: sorted_notification_letters } }, status: :ok
end
|
#download_coe ⇒ Object
14
15
16
17
18
|
# File 'app/controllers/v0/coe_controller.rb', line 14
def download_coe
res = lgy_service.get_coe_file
send_data(res.body, type: 'application/pdf', disposition: 'attachment')
end
|
#filtered_params ⇒ Object
93
94
95
|
# File 'app/controllers/v0/coe_controller.rb', line 93
def filtered_params
params.require(:lgy_coe_claim).permit(:form)
end
|
#lgy_service ⇒ Object
89
90
91
|
# File 'app/controllers/v0/coe_controller.rb', line 89
def lgy_service
@lgy_service ||= LGY::Service.new(edipi: @current_user.edipi, icn: @current_user.icn)
end
|
#post_document(document_data) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'app/controllers/v0/coe_controller.rb', line 65
def post_document(document_data)
response = lgy_service.post_document(payload: document_data)
response.status
rescue Common::Client::Errors::ClientError => e
if [503, 504].include?(e.status)
Rails.logger.info('LGY server unavailable or unresponsive',
{ status: e.status, messsage: e.message, body: e.body })
else
Rails.logger.error('LGY API returned error', { status: e.status, messsage: e.message, body: e.body })
end
e.status
end
|
#stats_key ⇒ Object
101
102
103
|
# File 'app/controllers/v0/coe_controller.rb', line 101
def stats_key
'api.lgy_coe'
end
|
#status ⇒ Object
9
10
11
12
|
# File 'app/controllers/v0/coe_controller.rb', line 9
def status
coe_status = lgy_service.coe_status
render json: { data: { attributes: coe_status } }, status: :ok
end
|
#submit_coe_claim ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/v0/coe_controller.rb', line 20
def submit_coe_claim
claim = SavedClaim::CoeClaim.new(form: filtered_params[:form])
unless claim.save
StatsD.increment("#{stats_key}.failure")
Sentry.set_tags(team: 'vfs-ebenefits') raise Common::Exceptions::ValidationErrors, claim
end
response = claim.send_to_lgy(edipi: current_user.edipi, icn: current_user.icn)
Rails.logger.info "ClaimID=#{claim.confirmation_number} Form=#{claim.class::FORM}"
clear_saved_form(claim.form_id)
render json: { data: { attributes: { reference_number: response, claim: } } }
end
|