修正加入课程接口问题
This commit is contained in:
parent
d407f8656d
commit
b711793d7c
|
@ -90,13 +90,14 @@ module Mobile
|
|||
desc "加入课程"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :course_password, type: String
|
||||
end
|
||||
post ":id" do
|
||||
authenticate!
|
||||
cs = CoursesService.new
|
||||
status = cs.join_course({"object_id" => params[:id]},current_user)
|
||||
out = {status: status}
|
||||
message = case status
|
||||
status = cs.join_course({:object_id => params[:id],:course_password => params[:course_password]},current_user)
|
||||
out = {status: status[:state]}
|
||||
message = case status[:state]
|
||||
when 0; "加入成功"
|
||||
when 1; "密码错误"
|
||||
when 2; "课程已过期 请联系课程管理员重启课程。(在配置课程处)"
|
||||
|
|
|
@ -27,7 +27,9 @@ class CoursesController < ApplicationController
|
|||
def join
|
||||
if User.current.logged?
|
||||
cs = CoursesService.new
|
||||
@state,course = cs.join_course params
|
||||
join = cs.join_course params,User.current
|
||||
@state = join[:state]
|
||||
course = join[:course]
|
||||
#course = Course.find_by_id params[:object_id]
|
||||
#if course
|
||||
# if course_endTime_timeout? course
|
||||
|
|
|
@ -217,20 +217,21 @@ class CoursesService
|
|||
#@state == 4 您加入的课程不存在
|
||||
#@state == 5 您还未登录
|
||||
#@state 其他 未知错误,请稍后再试
|
||||
def join_course params
|
||||
def join_course params,current_user
|
||||
course = Course.find_by_id params[:object_id]
|
||||
@state = 10
|
||||
if course
|
||||
if course_endTime_timeout? course
|
||||
@state = 2
|
||||
else
|
||||
if User.current.member_of_course?(course)
|
||||
if current_user.member_of_course?(course)
|
||||
@state = 3
|
||||
else
|
||||
if params[:course_password] == course.password
|
||||
members = []
|
||||
members << Member.new(:role_ids => [10], :user_id => User.current.id)
|
||||
members << Member.new(:role_ids => [10], :user_id => current_user.id)
|
||||
course.members << members
|
||||
StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id])
|
||||
StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id])
|
||||
@state = 0
|
||||
else
|
||||
@state = 1
|
||||
|
@ -240,7 +241,7 @@ class CoursesService
|
|||
else
|
||||
@state = 4
|
||||
end
|
||||
[@state,course]
|
||||
{:state => @state,:course => course}
|
||||
end
|
||||
|
||||
#作业列表
|
||||
|
|
Loading…
Reference in New Issue