diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 436557d183..49cbcf7ad5 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -139,6 +139,60 @@ def alerts @alerts = current_user&.admin? ? @course.alerts : @course.public_alerts end + def classroom_program_students_json + courses = Course.classroom_program_students + render json: courses.as_json( + only: %i[title created_at updated_at start end school term slug], + include: { + students: { + only: %i[username created_at updated_at permissions] + } + } + ) + end + + def classroom_program_students_and_instructors_json + courses = Course.classroom_program_students_and_instructors + render json: courses.as_json( + only: %i[title created_at updated_at start end school term slug], + include: { + students: { + only: %i[username created_at updated_at permissions] + }, + instructors: { + only: %i[username created_at updated_at permissions] + } + } + ) + end + + def fellows_cohort_students_json + courses = Course.fellows_cohort_students + render json: courses.as_json( + only: %i[title created_at updated_at start end school term slug], + include: { + students: { + only: %i[username created_at updated_at permissions] + } + } + ) + end + + def fellows_cohort_students_and_instructors_json + courses = Course.fellows_cohort_students_and_instructors + render json: courses.as_json( + only: %i[title created_at updated_at start end school term slug], + include: { + students: { + only: %i[username created_at updated_at permissions] + }, + instructors: { + only: %i[username created_at updated_at permissions] + } + } + ) + end + ########################## # User-initiated actions # ########################## diff --git a/app/models/course.rb b/app/models/course.rb index 80e1fb2c35..02e50ddfe4 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -160,6 +160,38 @@ def self.unsubmitted .where(submitted: false).references(:campaigns) end + def self.classroom_program_students + nonprivate + .where(type: 'ClassroomProgramCourse', withdrawn: false) + .joins(:campaigns) + .distinct + .includes(:students) + end + + def self.classroom_program_students_and_instructors + nonprivate + .where(type: 'ClassroomProgramCourse', withdrawn: false) + .joins(:campaigns) + .distinct + .includes(:students, :instructors) + end + + def self.fellows_cohort_students + nonprivate + .where(type: 'FellowsCohort', withdrawn: false) + .joins(:campaigns) + .distinct + .includes(:students) + end + + def self.fellows_cohort_students_and_instructors + nonprivate + .where(type: 'FellowsCohort', withdrawn: false) + .joins(:campaigns) + .distinct + .includes(:students, :instructors) + end + scope :strictly_current, -> { where('? BETWEEN start AND end', Time.zone.now) } scope :current, -> { current_and_future.where('start < ?', Time.zone.now) } scope :ended, -> { where('end < ?', Time.zone.now) } diff --git a/config/routes.rb b/config/routes.rb index 7b48dd80f2..af7c002c19 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -169,6 +169,19 @@ _subsubsubpage: /.*/ } + get '/courses/classroom_program_students.json', + to: 'courses#classroom_program_students_json', + as: :classroom_program_students + get '/courses/classroom_program_students_and_instructors.json', + to: 'courses#classroom_program_students_and_instructors_json', + as: :classroom_program_students_and_instructors + get '/courses/fellows_cohort_students.json', + to: 'courses#fellows_cohort_students_json', + as: :fellows_cohort_students + get '/courses/fellows_cohort_students_and_instructors.json', + to: 'courses#fellows_cohort_students_and_instructors_json', + as: :fellows_cohort_students_and_instructors + post '/courses/:slug/students/add_to_watchlist', to: 'courses/watchlist#add_to_watchlist', as: 'add_to_watchlist', constraints: { slug: /.*/ } delete 'courses/:slug/delete_from_campaign' => 'courses/delete_from_campaign#delete_course_from_campaign', as: 'delete_from_campaign',