Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

102639 One debt letter endpoint #20921

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file added modules/debts_api/app/assets/images/va_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require 'debts_api/v0/one_debt_letter_service'

module DebtsApi
module V0
class OneDebtLettersController < ApplicationController
service_tag 'debt-resolution'

def download_pdf
service = DebtsApi::V0::OneDebtLetterService.new(current_user)
file_contents = service.get_pdf

send_data file_contents, filename: file_name_for_pdf, type: 'application/pdf', disposition: 'attachment'
end

private

def file_name_for_pdf
"#{current_user.last_name}_#{Time.zone.now.strftime('%Y%m%d_%H%M%S')}_debt_letter.pdf"
end
end
end
end
1 change: 1 addition & 0 deletions modules/debts_api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
post 'calculate_monthly_expenses', to: 'financial_status_reports_calculations#monthly_expenses'
post 'calculate_all_expenses', to: 'financial_status_reports_calculations#all_expenses'
post 'calculate_monthly_income', to: 'financial_status_reports_calculations#monthly_income'
get 'download_one_debt_letter_pdf', to: 'one_debt_letters#download_pdf'
end
end
33 changes: 33 additions & 0 deletions modules/debts_api/lib/debts_api/v0/one_debt_letter_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module DebtsApi
class V0::OneDebtLetterService
def initialize(user)
@user = user
end

def get_pdf
# copays = vbs_service.get_copays
# debts = dmc_service.get_debts

Prawn::Document.new(page_size: 'LETTER') do |pdf|
add_and_format_logo(pdf)
end.render
end

private

def add_and_format_logo(pdf)
logo_path = Rails.root.join('modules', 'debts_api', 'app', 'assets', 'images', 'va_logo.png')
pdf.image logo_path, at: [(pdf.bounds.width / 2) - (250 / 2), pdf.cursor], width: 250
end

# def vbs_service
# MedicalCopays::VBS::Service.build(user: current_user)
# end
#
# def dmc_service
# DebtManagementCenter::DebtsService.new(current_user)
# end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require 'rails_helper'
require 'debts_api/v0/one_debt_letter_service'
RSpec.describe DebtsApi::V0::OneDebtLetterService, type: :service do
describe '#get_pdf' do
let(:user) { build(:user, :loa3) }

it 'returns a pdf' do
service = DebtsApi::V0::OneDebtLetterService.new(user)
pdf = service.get_pdf

expect(pdf).to be_a(String)
expect(pdf).to include('%PDF-1.4')
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'DebtsApi::V0::DigitalDisputes', type: :request do
let(:user) { build(:user, :loa3) }

before do
sign_in_as(user)
end

describe '#download_pdf' do
it 'returns pdf' do
expect(StatsD).to receive(:increment).with(
'api.rack.request',
{ tags: %w[controller:debts_api/v0/one_debt_letters action:download_pdf source_app:not_provided status:200] }
)
get '/debts_api/v0/download_one_debt_letter_pdf'

expect(response).to have_http_status(:ok)
expect(response.headers['Content-Type']).to eq('application/pdf')
end
end
end
Loading