2014-11-27 19:43:04 +08:00
|
|
|
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)
|
2014-12-03 17:28:19 +08:00
|
|
|
{status: 0, data: @courses}
|
2014-11-27 19:43:04 +08:00
|
|
|
# @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
|
2014-12-03 17:28:19 +08:00
|
|
|
course = Course.find(params[:id])
|
|
|
|
{status: 0, data: course}
|
2014-11-27 19:43:04 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|