Skip to content

Commit dce0624

Browse files
committed
Add Programmes::BaseController
This adds a controller which can be shared across all the programme controllers to contain common logic.
1 parent fc790a8 commit dce0624

8 files changed

Lines changed: 20 additions & 62 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
class Programmes::BaseController < ApplicationController
4+
before_action :set_programme
5+
6+
layout "full"
7+
8+
private
9+
10+
def set_programme
11+
@programme = policy_scope(Programme).find_by!(type: params[:programme_type])
12+
end
13+
end

app/controllers/programmes/cohorts_controller.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
# frozen_string_literal: true
22

3-
class Programmes::CohortsController < ApplicationController
3+
class Programmes::CohortsController < Programmes::BaseController
44
include Pagy::Backend
55

6-
before_action :set_programme
7-
8-
layout "full"
9-
106
def index
117
birth_academic_years = @programme.birth_academic_years
128

@@ -35,10 +31,6 @@ def show
3531

3632
private
3733

38-
def set_programme
39-
@programme = policy_scope(Programme).find_by!(type: params[:programme_type])
40-
end
41-
4234
def patients_in_organisation
4335
current_user.selected_organisation.patients
4436
end
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
# frozen_string_literal: true
22

3-
class Programmes::OverviewController < ApplicationController
4-
before_action :set_programme
5-
6-
layout "full"
7-
3+
class Programmes::OverviewController < Programmes::BaseController
84
def show
95
patients = policy_scope(Patient).in_programmes([@programme])
106

117
@consents =
128
policy_scope(Consent).where(patient: patients, programme: @programme)
139
end
14-
15-
private
16-
17-
def set_programme
18-
@programme = policy_scope(Programme).find_by!(type: params[:programme_type])
19-
end
2010
end
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# frozen_string_literal: true
22

3-
class Programmes::PatientsController < ApplicationController
3+
class Programmes::PatientsController < Programmes::BaseController
44
include Pagy::Backend
55
include SearchFormConcern
66

7-
before_action :set_programme
87
before_action :set_search_form
98

10-
layout "full"
11-
129
def index
1310
scope =
1411
policy_scope(Patient).includes(:vaccination_statuses).in_programmes(
@@ -20,10 +17,4 @@ def index
2017
patients = @form.apply(scope)
2118
@pagy, @patients = pagy(patients)
2219
end
23-
24-
private
25-
26-
def set_programme
27-
@programme = policy_scope(Programme).find_by!(type: params[:programme_type])
28-
end
2920
end
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# frozen_string_literal: true
22

3-
class Programmes::ReportsController < ApplicationController
4-
before_action :set_programme
5-
3+
class Programmes::ReportsController < Programmes::BaseController
64
def create
75
vaccination_report =
86
VaccinationReport.new(request_session: session, current_user:)
@@ -12,10 +10,4 @@ def create
1210

1311
redirect_to vaccination_report_path(Wicked::FIRST_STEP)
1412
end
15-
16-
private
17-
18-
def set_programme
19-
@programme = policy_scope(Programme).find_by!(type: params[:programme_type])
20-
end
2113
end
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# frozen_string_literal: true
22

3-
class Programmes::SessionsController < ApplicationController
4-
before_action :set_programme
5-
6-
layout "full"
7-
3+
class Programmes::SessionsController < Programmes::BaseController
84
def index
95
@sessions =
106
policy_scope(Session)
@@ -13,10 +9,4 @@ def index
139
.includes(:location, :session_dates)
1410
.order("locations.name")
1511
end
16-
17-
private
18-
19-
def set_programme
20-
@programme = policy_scope(Programme).find_by!(type: params[:programme_type])
21-
end
2212
end
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
# frozen_string_literal: true
22

3-
class Programmes::VaccinationsController < ApplicationController
3+
class Programmes::VaccinationsController < Programmes::BaseController
44
include Pagy::Backend
55

6-
before_action :set_programme
7-
8-
layout "full"
9-
106
def index
117
scope =
128
policy_scope(VaccinationRecord)
@@ -16,10 +12,4 @@ def index
1612

1713
@pagy, @vaccination_records = pagy(scope)
1814
end
19-
20-
private
21-
22-
def set_programme
23-
@programme = policy_scope(Programme).find_by!(type: params[:programme_type])
24-
end
2515
end

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
end
167167

168168
resources :programmes, only: :index, param: :type do
169-
get "consent-form", on: :member
169+
get "consent-form", on: :member, action: :consent_form
170170

171171
scope module: :programmes do
172172
resource :overview, path: "", only: :show, controller: :overview

0 commit comments

Comments
 (0)