Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add student program endpoint #6080

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
##########################
Expand Down
32 changes: 32 additions & 0 deletions app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
13 changes: 13 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading