修改加入课程、退出课程接口调用,添加创建课程,编辑课程的参数说明

This commit is contained in:
z9han 2014-12-23 11:07:17 +08:00
parent 7f1826ebf2
commit 93762e89d3
3 changed files with 32 additions and 6 deletions

View File

@ -34,7 +34,7 @@ module Mobile
post ":id" do post ":id" do
authenticate! authenticate!
cs = CoursesService.new 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} out = {status: status}
message = case status message = case status
when 0; "加入成功" when 0; "加入成功"
@ -54,7 +54,7 @@ module Mobile
delete ":id" do delete ":id" do
authenticate! authenticate!
cs = CoursesService.new cs = CoursesService.new
cs.exit_course({"object_id" => params[:id]}, current_user.id) cs.exit_course({"object_id" => params[:id]}, current_user)
{status: 0} {status: 0}
end end

View File

@ -428,7 +428,7 @@ class CoursesController < ApplicationController
def create def create
cs = CoursesService.new cs = CoursesService.new
@course = cs.create_course params @course = cs.create_course params,User.current
if @course.new_record? if @course.new_record?
respond_to do |format| respond_to do |format|
format.html { render :action => 'new', :layout => 'base' } #Added by young format.html { render :action => 'new', :layout => 'base' } #Added by young

View File

@ -49,7 +49,7 @@ class CoursesService
url_to_avatar(obj) url_to_avatar(obj)
end end
#课程老师或课程学生列表 TODO:更新业务逻辑,当前版本未包含分班功能 #课程老师或课程学生列表
def course_teacher_or_student_list params,course,current_user def course_teacher_or_student_list params,course,current_user
if course.is_a?(Course) if course.is_a?(Course)
c = course c = course
@ -110,8 +110,20 @@ class CoursesService
end end
#创建课程 #创建课程
def create_course params #current_user当前用户对象不是id
if User.current.user_extensions.identity # 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 = Course.new
@course.extra = 'course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s @course.extra = 'course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s
@course.safe_attributes = params[:course] @course.safe_attributes = params[:course]
@ -145,6 +157,7 @@ class CoursesService
end end
#验证编辑课程的权限 #验证编辑课程的权限
#当前
def edit_course_authorize(current_user,course) def edit_course_authorize(current_user,course)
unless current_user.allowed_to?({:controller => 'courses', :action => 'update'}, course) unless current_user.allowed_to?({:controller => 'courses', :action => 'update'}, course)
raise '403' raise '403'
@ -152,6 +165,15 @@ class CoursesService
end 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 def edit_course params,course
course.safe_attributes = params[:course] course.safe_attributes = params[:course]
course.time = params[:time] course.time = params[:time]
@ -171,6 +193,8 @@ class CoursesService
end end
#退出课程 #退出课程
#object_id: 课程id
#user当前用户
def exit_course params,user def exit_course params,user
@member = Member.where('course_id = ? and user_id = ?', params[:object_id], user.id) @member = Member.where('course_id = ? and user_id = ?', params[:object_id], user.id)
@member.first.destroy @member.first.destroy
@ -182,6 +206,8 @@ class CoursesService
end end
#加入课程 #加入课程
#object_id课程id
#course_password :加入课程的密码
#@state == 0 加入成功 #@state == 0 加入成功
#@state == 1 密码错误 #@state == 1 密码错误
#@state == 2 课程已过期 请联系课程管理员重启课程。(在配置课程处) #@state == 2 课程已过期 请联系课程管理员重启课程。(在配置课程处)