2014-12-10 18:26:38 +08:00
|
|
|
#coding=utf-8
|
2014-11-27 19:43:04 +08:00
|
|
|
module Mobile
|
2014-12-09 15:16:47 +08:00
|
|
|
module Apis
|
2014-12-09 16:36:43 +08:00
|
|
|
class Courses < Grape::API
|
|
|
|
resource :courses do
|
2014-12-10 16:23:56 +08:00
|
|
|
desc "获取所有课程"
|
2014-12-09 16:36:43 +08:00
|
|
|
params do
|
2014-12-10 16:23:56 +08:00
|
|
|
optional :school_id, type: Integer, desc: '传入学校id,返回该学校课程列表'
|
|
|
|
requires :per_page_count, type: Integer, desc: '每页总数'
|
|
|
|
requires :page, type: Integer, desc: '当前页码'
|
2014-12-08 16:51:21 +08:00
|
|
|
end
|
2014-11-27 19:43:04 +08:00
|
|
|
get do
|
2014-12-09 16:36:43 +08:00
|
|
|
cs = CoursesService.new
|
|
|
|
courses = cs.course_list(params)
|
|
|
|
present :data, courses, with: Mobile::Entities::Course
|
|
|
|
present :status, 0
|
2014-11-27 19:43:04 +08:00
|
|
|
end
|
|
|
|
|
2014-12-13 21:52:26 +08:00
|
|
|
desc "新建课程[TODO,参数没弄清]"
|
|
|
|
params do
|
|
|
|
end
|
|
|
|
post do
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "编辑课程[TODO,参数没弄清]"
|
|
|
|
params do
|
|
|
|
end
|
|
|
|
post do
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "加入课程"
|
|
|
|
params do
|
|
|
|
end
|
|
|
|
post ":id" do
|
|
|
|
authenticate!
|
|
|
|
cs = CoursesService.new
|
|
|
|
status = cs.join_course({"object_id" => params[:id]},current_user.id)
|
|
|
|
out = {status: status}
|
|
|
|
message = case status
|
|
|
|
when 0; "加入成功"
|
|
|
|
when 1; "密码错误"
|
|
|
|
when 2; "课程已过期 请联系课程管理员重启课程。(在配置课程处)"
|
|
|
|
when 3; "您已经加入了课程"
|
|
|
|
when 4; "您加入的课程不存在"
|
|
|
|
when 5; "您还未登录"
|
|
|
|
else; "未知错误,请稍后再试"
|
|
|
|
end
|
|
|
|
out.merge(message: message)
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "退出课程"
|
|
|
|
params do
|
|
|
|
end
|
|
|
|
delete ":id" do
|
|
|
|
authenticate!
|
|
|
|
cs = CoursesService.new
|
|
|
|
cs.exit_course({"object_id" => params[:id]}, current_user.id)
|
|
|
|
{status: 0}
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "搜索课程"
|
|
|
|
params do
|
|
|
|
requires :name, type: String, desc: "课程名"
|
|
|
|
end
|
|
|
|
get 'search' do
|
|
|
|
cs = CoursesService.new
|
|
|
|
courses = cs.search_course(params)
|
|
|
|
present :data, courses, with: Mobile::Entities::Course
|
|
|
|
present :status, 0
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "课程老师列表"
|
|
|
|
params do
|
|
|
|
requires :course_id, type: Integer, desc: "课程id"
|
|
|
|
end
|
|
|
|
get 'teachers' do
|
|
|
|
cs = CoursesService.new
|
|
|
|
teachers = cs.course_teacher_or_student_list({role: 1}, params[:course_id])
|
|
|
|
{status: 0, data: teachers}
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "课程学生列表"
|
|
|
|
params do
|
|
|
|
requires :course_id, type: Integer, desc: "课程id"
|
|
|
|
end
|
|
|
|
get 'teachers' do
|
|
|
|
cs = CoursesService.new
|
|
|
|
teachers = cs.course_teacher_or_student_list({role: 2}, params[:course_id])
|
|
|
|
{status: 0, data: teachers}
|
|
|
|
end
|
|
|
|
|
2014-12-10 16:23:56 +08:00
|
|
|
desc "返回单个课程"
|
2014-12-09 16:36:43 +08:00
|
|
|
params do
|
|
|
|
requires :id, type: Integer
|
|
|
|
end
|
|
|
|
route_param :id do
|
|
|
|
get do
|
|
|
|
course = Course.find(params[:id])
|
|
|
|
{status: 0, data: course}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2014-11-27 19:43:04 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|