修改加入课程、退出课程接口调用,添加创建课程,编辑课程的参数说明
This commit is contained in:
parent
7f1826ebf2
commit
93762e89d3
|
@ -34,7 +34,7 @@ module Mobile
|
|||
post ":id" do
|
||||
authenticate!
|
||||
cs = CoursesService.new
|
||||
status = cs.join_course({"object_id" => params[:id]},current_user.id)
|
||||
status = cs.join_course({"object_id" => params[:id]},current_user)
|
||||
out = {status: status}
|
||||
message = case status
|
||||
when 0; "加入成功"
|
||||
|
@ -54,7 +54,7 @@ module Mobile
|
|||
delete ":id" do
|
||||
authenticate!
|
||||
cs = CoursesService.new
|
||||
cs.exit_course({"object_id" => params[:id]}, current_user.id)
|
||||
cs.exit_course({"object_id" => params[:id]}, current_user)
|
||||
{status: 0}
|
||||
end
|
||||
|
||||
|
|
|
@ -428,7 +428,7 @@ class CoursesController < ApplicationController
|
|||
|
||||
def create
|
||||
cs = CoursesService.new
|
||||
@course = cs.create_course params
|
||||
@course = cs.create_course params,User.current
|
||||
if @course.new_record?
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new', :layout => 'base' } #Added by young
|
||||
|
|
|
@ -49,7 +49,7 @@ class CoursesService
|
|||
url_to_avatar(obj)
|
||||
end
|
||||
|
||||
#课程老师或课程学生列表 TODO:更新业务逻辑,当前版本未包含分班功能
|
||||
#课程老师或课程学生列表
|
||||
def course_teacher_or_student_list params,course,current_user
|
||||
if course.is_a?(Course)
|
||||
c = course
|
||||
|
@ -110,8 +110,20 @@ class CoursesService
|
|||
end
|
||||
|
||||
#创建课程
|
||||
def create_course params
|
||||
if User.current.user_extensions.identity
|
||||
#current_user当前用户对象(不是id)
|
||||
# params[:course][:name]:课程名称
|
||||
#params[:course][:password]:密码
|
||||
#params[:course][:description]:描述
|
||||
#params[:course][:is_public]:是否公开1公开,0私有
|
||||
#params[:course][:open_student]:是否公开学生列表1公开,0不公开,不公开时非课程成员无法看到学生列表
|
||||
#params[:course][:course_type]:暂时默认给1值。
|
||||
#params[:term]:学期(秋季学期或春季学期)
|
||||
#params[:time]: 年份(例:2014)
|
||||
#params[:setup_time]:暂不传(貌似已经没用了)
|
||||
#params[:endup_time]: 暂不传(貌似已经没用了)
|
||||
#params[:class_period]:学时总数
|
||||
def create_course params,current_user
|
||||
if current_user.user_extensions.identity
|
||||
@course = Course.new
|
||||
@course.extra = 'course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s
|
||||
@course.safe_attributes = params[:course]
|
||||
|
@ -145,6 +157,7 @@ class CoursesService
|
|||
end
|
||||
|
||||
#验证编辑课程的权限
|
||||
#当前
|
||||
def edit_course_authorize(current_user,course)
|
||||
unless current_user.allowed_to?({:controller => 'courses', :action => 'update'}, course)
|
||||
raise '403'
|
||||
|
@ -152,6 +165,15 @@ class CoursesService
|
|||
end
|
||||
|
||||
#编辑课程 需验证权限
|
||||
# params[:course][:name]:课程名称
|
||||
#params[:course][:password]:密码
|
||||
#params[:course][:description]:描述
|
||||
#params[:course][:is_public]:是否公开1公开,0私有
|
||||
#params[:course][:open_student]:是否公开学生列表1公开,0不公开,不公开时非课程成员无法看到学生列表
|
||||
#params[:course][:course_type]:暂时默认给1值。
|
||||
#params[:term]:学期(秋季学期或春季学期)
|
||||
#params[:time]: 年份(例:2014)
|
||||
#params[:class_period]:学时总数
|
||||
def edit_course params,course
|
||||
course.safe_attributes = params[:course]
|
||||
course.time = params[:time]
|
||||
|
@ -171,6 +193,8 @@ class CoursesService
|
|||
end
|
||||
|
||||
#退出课程
|
||||
#object_id: 课程id
|
||||
#user:当前用户
|
||||
def exit_course params,user
|
||||
@member = Member.where('course_id = ? and user_id = ?', params[:object_id], user.id)
|
||||
@member.first.destroy
|
||||
|
@ -182,6 +206,8 @@ class CoursesService
|
|||
end
|
||||
|
||||
#加入课程
|
||||
#object_id:课程id
|
||||
#course_password :加入课程的密码
|
||||
#@state == 0 加入成功
|
||||
#@state == 1 密码错误
|
||||
#@state == 2 课程已过期 请联系课程管理员重启课程。(在配置课程处)
|
||||
|
|
Loading…
Reference in New Issue