40 lines
1.2 KiB
Ruby
40 lines
1.2 KiB
Ruby
|
module Mobile
|
||
|
class Courses < Grape::API
|
||
|
resource :courses do
|
||
|
desc "get all courses"
|
||
|
params do
|
||
|
requires :per_page_count, type: Integer
|
||
|
requires :page, type: Integer, desc: 'current page no'
|
||
|
end
|
||
|
get do
|
||
|
per_page_option = params[:per_page_count] || 10
|
||
|
page_no = params[:page] || 1
|
||
|
@courses_all = Course.active.visible.
|
||
|
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id")
|
||
|
@course_count = @courses_all.count
|
||
|
@course_pages = Redmine::Pagination::Paginator.new @course_count, per_page_option,page_no
|
||
|
@course_activity_count=Hash.new
|
||
|
@courses_all.each do |course|
|
||
|
@course_activity_count[course.id]=0
|
||
|
end
|
||
|
@courses = @courses_all.order("created_at desc")
|
||
|
@s_type = 0
|
||
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||
|
# @course_activity_count=get_course_activity @courses, @course_activity_count
|
||
|
end
|
||
|
|
||
|
desc "Return a course"
|
||
|
params do
|
||
|
requires :id, type: Integer
|
||
|
end
|
||
|
route_param :id do
|
||
|
get do
|
||
|
Course.find(params[:id])
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|