Skip to content

Commit

Permalink
Training partnerships controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
inulty-dfe committed Jan 22, 2025
1 parent 7f34da6 commit bade972
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module Publish
module Providers
module TrainingPartnerships
class CourseExportsController < ApplicationController
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 TrainingPartnerships
class CoursesController < ApplicationController
def index
authorize(provider, :index?)

@courses = fetch_courses
end

private

def training_provider
@training_provider ||= provider.training_partners.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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Publish
module Providers
class TrainingPartnershipsController < ApplicationController
def index
authorize(provider, :can_list_training_providers?)

@training_providers = provider.training_partners.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

0 comments on commit bade972

Please sign in to comment.