Skip to content

Commit

Permalink
Move TrainingProviders to Providers module
Browse files Browse the repository at this point in the history
  • Loading branch information
inulty-dfe committed Dec 17, 2024
1 parent 794c328 commit 2bceab5
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions app/controllers/publish/providers/training_providers_controller.rb
Original file line number Diff line number Diff line change
@@ -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

This file was deleted.

28 changes: 0 additions & 28 deletions app/controllers/publish/training_providers/courses_controller.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/controllers/publish/training_providers_controller.rb

This file was deleted.

10 changes: 5 additions & 5 deletions config/routes/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2bceab5

Please sign in to comment.