Skip to content

Commit cad27fc

Browse files
committed
Split VaccinationReportsController
This splits the controller in to two separate controllers that serve different needs. Programmes::ReportsController will exist to first create a vaccination report for a particular programme and the existing controller will continue to serve the wizard and pages related to the vaccination report model.
1 parent 4ef7752 commit cad27fc

4 files changed

Lines changed: 37 additions & 28 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
class Programmes::ReportsController < ApplicationController
4+
before_action :set_programme
5+
6+
def create
7+
vaccination_report =
8+
VaccinationReport.new(request_session: session, current_user:)
9+
10+
vaccination_report.reset!
11+
vaccination_report.update!(programme: @programme)
12+
13+
redirect_to vaccination_report_path(Wicked::FIRST_STEP)
14+
end
15+
16+
private
17+
18+
def set_programme
19+
@programme = policy_scope(Programme).find_by!(type: params[:programme_type])
20+
end
21+
end

app/controllers/vaccination_reports_controller.rb

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
class VaccinationReportsController < ApplicationController
44
before_action :set_vaccination_report
5-
before_action :set_programme, only: %i[show update]
5+
before_action :set_programme
66

77
include WizardControllerConcern
88

9-
skip_after_action :verify_policy_scoped, only: %i[show update download]
9+
skip_after_action :verify_policy_scoped
1010

11-
def create
12-
@programme = policy_scope(Programme).find_by(type: params[:programme_type])
11+
def show
12+
render_wizard
13+
end
1314

14-
@vaccination_report.reset!
15-
@vaccination_report.update!(programme: @programme)
15+
def update
16+
@vaccination_report.assign_attributes(update_params)
1617

17-
redirect_to vaccination_report_path(Wicked::FIRST_STEP)
18+
render_wizard @vaccination_report
1819
end
1920

2021
def download
@@ -28,16 +29,6 @@ def download
2829
end
2930
end
3031

31-
def show
32-
render_wizard
33-
end
34-
35-
def update
36-
@vaccination_report.assign_attributes(update_params)
37-
38-
render_wizard @vaccination_report
39-
end
40-
4132
private
4233

4334
def set_vaccination_report

app/views/programmes/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<%= render AppProgrammeNavigationComponent.new(@programme, active: :overview) %>
1313

14-
<%= govuk_button_to "Download vaccination report", programme_vaccination_reports_path(@programme), secondary: true, class: "nhsuk-u-margin-bottom-5" %>
14+
<%= govuk_button_to "Download vaccination report", programme_reports_path(@programme), secondary: true, class: "nhsuk-u-margin-bottom-5" %>
1515

1616
<%= render AppProgrammeStatsComponent.new(programme: @programme) %>
1717

config/routes.rb

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,6 @@
124124
only: %i[show update],
125125
path: "draft-vaccination-record/:id"
126126

127-
resource :vaccination_report,
128-
only: %i[show update],
129-
path: "draft-vaccination-report/:id" do
130-
get "download", on: :member
131-
end
132-
133127
resources :immunisation_imports,
134128
path: "immunisation-imports",
135129
except: %i[index destroy]
@@ -180,11 +174,8 @@
180174
end
181175

182176
resources :cohorts, only: %i[index show], controller: "programmes/cohorts"
177+
resources :reports, only: :create, controller: "programmes/reports"
183178
resources :vaccinations, only: :index, controller: "programmes/vaccinations"
184-
185-
resources :vaccination_reports,
186-
path: "vaccination-reports",
187-
only: %i[create]
188179
end
189180

190181
resources :school_moves, path: "school-moves", only: %i[index show update]
@@ -299,6 +290,12 @@
299290
get "destroy", action: :confirm_destroy, on: :member, as: "destroy"
300291
end
301292

293+
resource :vaccination_report,
294+
only: %i[show update],
295+
path: "vaccination-report/:id" do
296+
get "download", on: :member
297+
end
298+
302299
resources :vaccines, only: %i[index show] do
303300
resources :batches, only: %i[create edit new update] do
304301
member do

0 commit comments

Comments
 (0)