Skip to content

Commit

Permalink
Merge pull request #6080 from Aminehassou/AddStudentProgramEndpoint
Browse files Browse the repository at this point in the history
Add student program endpoint
  • Loading branch information
ragesoss authored Dec 31, 2024
2 parents 3465125 + 6afed6e commit 3d912ba
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
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

0 comments on commit 3d912ba

Please sign in to comment.