Skip to content

Commit

Permalink
Add mailer to send requested CSV file
Browse files Browse the repository at this point in the history
  • Loading branch information
Lubosky committed Aug 21, 2024
1 parent 0573e18 commit 3f53336
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/admin/statistics/nominations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ def create
authorize :statistics, :send?

@search = NominationStatsSearch.new(FormAnswer.all).search(permitted_params)

data = generate_csv(@search.results)
file = current_admin.protected_files.create_from_raw_data(data, "nomination-statistics-export.csv")

Admin::Statistics::NominationMailer.notify(current_admin.id, file.id).deliver_now

redirect_to admin_statistics_nominations_path(search: permitted_params), success: "CSV with nomination statistics has been sent to #{current_admin.email}."
end
Expand Down
12 changes: 12 additions & 0 deletions app/mailers/admin/statistics/nomination_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Admin::Statistics::NominationMailer < ApplicationMailer
layout "mailer"

def notify(identifier, file_identifier)
@admin = Admin.find(identifier)
@file = @admin.protected_files.find(file_identifier)

subject = "Nomination statistics export - King's Award for Voluntary Service"

view_mail ENV["GOV_UK_NOTIFY_API_TEMPLATE_ID"], to: @admin.email, subject: subject_with_env_prefix(subject)
end
end
18 changes: 18 additions & 0 deletions app/views/admin/statistics/nomination_mailer/notify.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
p.govuk-body
= "Dear #{@admin.first_name},"

p.govuk-body
' You requested an export of nomination statistics.

p.govuk-body
' Please find this report on the link below:

p.govuk-body
= link_to admin_protected_file_url(@file), admin_protected_file_url(@file)

p.govuk-body
' Kind Regards,

br

' The King's Awards Office

0 comments on commit 3f53336

Please sign in to comment.