From 2bceab57174bac9bce31dab19e5a350d13eb81ca Mon Sep 17 00:00:00 2001 From: Iain McNulty Date: Mon, 16 Dec 2024 16:05:20 +0000 Subject: [PATCH] Move TrainingProviders to Providers module --- .../course_exports_controller.rb | 29 ++++++++++++++++++ .../training_providers/courses_controller.rb | 30 +++++++++++++++++++ .../training_providers_controller.rb | 14 +++++++++ .../course_exports_controller.rb | 27 ----------------- .../training_providers/courses_controller.rb | 28 ----------------- .../publish/training_providers_controller.rb | 12 -------- .../training_providers/courses/index.html.erb | 0 .../training_providers/index.html.erb | 0 config/routes/publish.rb | 10 +++---- 9 files changed, 78 insertions(+), 72 deletions(-) create mode 100644 app/controllers/publish/providers/training_providers/course_exports_controller.rb create mode 100644 app/controllers/publish/providers/training_providers/courses_controller.rb create mode 100644 app/controllers/publish/providers/training_providers_controller.rb delete mode 100644 app/controllers/publish/training_providers/course_exports_controller.rb delete mode 100644 app/controllers/publish/training_providers/courses_controller.rb delete mode 100644 app/controllers/publish/training_providers_controller.rb rename app/views/publish/{ => providers}/training_providers/courses/index.html.erb (100%) rename app/views/publish/{ => providers}/training_providers/index.html.erb (100%) diff --git a/app/controllers/publish/providers/training_providers/course_exports_controller.rb b/app/controllers/publish/providers/training_providers/course_exports_controller.rb new file mode 100644 index 0000000000..c8219585f4 --- /dev/null +++ b/app/controllers/publish/providers/training_providers/course_exports_controller.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Publish + module Providers + module TrainingProviders + class CourseExportsController < PublishController + def index + authorize(provider, :can_list_training_providers?) + + respond_to do |format| + format.csv do + send_data(data_export.data, filename: data_export.filename, disposition: :attachment) + end + end + end + + private + + def courses + @courses ||= provider.current_accredited_courses + end + + def data_export + @data_export ||= Exports::AccreditedCourseList.new(courses:) + end + end + end + end +end diff --git a/app/controllers/publish/providers/training_providers/courses_controller.rb b/app/controllers/publish/providers/training_providers/courses_controller.rb new file mode 100644 index 0000000000..726a964fce --- /dev/null +++ b/app/controllers/publish/providers/training_providers/courses_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Publish + module Providers + module TrainingProviders + class CoursesController < PublishController + def index + authorize(provider, :index?) + + @courses = fetch_courses + end + + private + + def training_provider + @training_provider ||= provider.training_providers.find_by(provider_code: params[:training_provider_code]) + end + + def fetch_courses + training_provider + .courses + .includes(:enrichments, :site_statuses, provider: [:recruitment_cycle]) + .where(accredited_provider_code: provider.provider_code) + .order(:name) + .map(&:decorate) + end + end + end + end +end diff --git a/app/controllers/publish/providers/training_providers_controller.rb b/app/controllers/publish/providers/training_providers_controller.rb new file mode 100644 index 0000000000..b2712c981a --- /dev/null +++ b/app/controllers/publish/providers/training_providers_controller.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Publish + module Providers + class TrainingProvidersController < PublishController + def index + authorize(provider, :can_list_training_providers?) + + @training_providers = provider.training_providers.include_accredited_courses_counts(provider.provider_code).order(:provider_name) + @course_counts = @training_providers.to_h { |p| [p.provider_code, p.accredited_courses_count] } + end + end + end +end diff --git a/app/controllers/publish/training_providers/course_exports_controller.rb b/app/controllers/publish/training_providers/course_exports_controller.rb deleted file mode 100644 index febd9cbcb8..0000000000 --- a/app/controllers/publish/training_providers/course_exports_controller.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module Publish - module TrainingProviders - class CourseExportsController < PublishController - def index - authorize(provider, :can_list_training_providers?) - - respond_to do |format| - format.csv do - send_data(data_export.data, filename: data_export.filename, disposition: :attachment) - end - end - end - - private - - def courses - @courses ||= provider.current_accredited_courses - end - - def data_export - @data_export ||= Exports::AccreditedCourseList.new(courses:) - end - end - end -end diff --git a/app/controllers/publish/training_providers/courses_controller.rb b/app/controllers/publish/training_providers/courses_controller.rb deleted file mode 100644 index dca0d94254..0000000000 --- a/app/controllers/publish/training_providers/courses_controller.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -module Publish - module TrainingProviders - class CoursesController < PublishController - def index - authorize(provider, :index?) - - @courses = fetch_courses - end - - private - - def training_provider - @training_provider ||= provider.training_providers.find_by(provider_code: params[:training_provider_code]) - end - - def fetch_courses - training_provider - .courses - .includes(:enrichments, :site_statuses, provider: [:recruitment_cycle]) - .where(accredited_provider_code: provider.provider_code) - .order(:name) - .map(&:decorate) - end - end - end -end diff --git a/app/controllers/publish/training_providers_controller.rb b/app/controllers/publish/training_providers_controller.rb deleted file mode 100644 index 6a8ae012bd..0000000000 --- a/app/controllers/publish/training_providers_controller.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -module Publish - class TrainingProvidersController < PublishController - def index - authorize(provider, :can_list_training_providers?) - - @training_providers = provider.training_providers.include_accredited_courses_counts(provider.provider_code).order(:provider_name) - @course_counts = @training_providers.to_h { |p| [p.provider_code, p.accredited_courses_count] } - end - end -end diff --git a/app/views/publish/training_providers/courses/index.html.erb b/app/views/publish/providers/training_providers/courses/index.html.erb similarity index 100% rename from app/views/publish/training_providers/courses/index.html.erb rename to app/views/publish/providers/training_providers/courses/index.html.erb diff --git a/app/views/publish/training_providers/index.html.erb b/app/views/publish/providers/training_providers/index.html.erb similarity index 100% rename from app/views/publish/training_providers/index.html.erb rename to app/views/publish/providers/training_providers/index.html.erb diff --git a/config/routes/publish.rb b/config/routes/publish.rb index 6326ea9de6..fa087bb1fa 100644 --- a/config/routes/publish.rb +++ b/config/routes/publish.rb @@ -80,11 +80,6 @@ get '/about', on: :member, to: 'providers#about' put '/about', on: :member, to: 'providers#update' get '/details', on: :member, to: 'providers#details' - get '/training-providers-courses', on: :member, to: 'training_providers/course_exports#index', as: 'download_training_providers_courses' - - resources :training_providers, path: '/training-providers', only: [:index], param: :code do - resources :courses, only: [:index], controller: 'training_providers/courses' - end resource :courses, only: %i[create] do resource :outcome, on: :member, only: %i[new], controller: 'courses/outcome' do @@ -256,6 +251,11 @@ end scope module: :providers do + get '/training-providers-courses', on: :member, to: 'training_providers/course_exports#index', as: 'download_training_providers_courses' + resources :training_providers, path: '/training-providers', only: [:index], param: :code do + resources :courses, module: :training_providers, only: [:index] + end + resources :accredited_providers, param: :accredited_provider_code, only: %i[index new edit create update destroy], path: 'accredited-providers' do member do get :delete