merge
This commit is contained in:
commit
8ecdaf2fe8
|
@ -65,12 +65,13 @@ module Mobile
|
|||
requires :is_public, type: Integer, desc: '是否公开 1公开 0私有'
|
||||
requires :open_student, type: Integer, desc: '是否公开学生列表1公开,0不公开,不公开时非课程成员无法看到学生列表'
|
||||
requires :course_type, type:Integer, desc: '暂时传1'
|
||||
requires :term, type: String, desc: '学期(秋秀学期或春秀学期)'
|
||||
requires :term, type: String, desc: '学期(秋季学期或春季学期)'
|
||||
requires :time, type: String, desc: '年份'
|
||||
requires :class_period, type: String, desc: '学时总数'
|
||||
end
|
||||
put do
|
||||
authenticate!
|
||||
cs = CoursesService.new
|
||||
cs_params = {
|
||||
course: params.reject{|k,v| [:term,:time,:class_period].include?(k)},
|
||||
term: params[:term],
|
||||
|
@ -79,7 +80,7 @@ module Mobile
|
|||
}
|
||||
course = ::Course.find(params[:course_id])
|
||||
cs.edit_course_authorize(current_user,course)
|
||||
course = cs.edit_course(cs_params, course)
|
||||
course = cs.edit_course(cs_params, course,current_user)
|
||||
present :data, course, with: Mobile::Entities::Course
|
||||
present :status, 0
|
||||
end
|
||||
|
@ -89,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; "课程已过期 请联系课程管理员重启课程。(在配置课程处)"
|
||||
|
@ -114,8 +116,15 @@ module Mobile
|
|||
delete ":id" do
|
||||
authenticate!
|
||||
cs = CoursesService.new
|
||||
cs.exit_course({"object_id" => params[:id]}, current_user)
|
||||
{status: 0}
|
||||
status = cs.exit_course({:object_id => params[:id]}, current_user)
|
||||
out = {status: status}
|
||||
message = case status
|
||||
when 0; "退出成功"
|
||||
when 1; "您不在课程中"
|
||||
when 2; "您还未登录"
|
||||
else; "未知错误,请稍后再试"
|
||||
end
|
||||
out.merge(message: message)
|
||||
end
|
||||
|
||||
desc "搜索课程"
|
||||
|
@ -131,22 +140,26 @@ module Mobile
|
|||
|
||||
desc "课程老师列表"
|
||||
params do
|
||||
requires :token, type: String
|
||||
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],current_user)
|
||||
{status: 0, data: teachers}
|
||||
teachers = cs.course_teacher_or_student_list({role: '1'}, params[:course_id],current_user)
|
||||
present :data, teachers, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "课程学生列表"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :course_id, type: Integer, desc: "课程id"
|
||||
end
|
||||
get 'teachers' do
|
||||
get 'students' do
|
||||
cs = CoursesService.new
|
||||
teachers = cs.course_teacher_or_student_list({role: 2}, params[:course_id],current_user)
|
||||
{status: 0, data: teachers}
|
||||
students = cs.course_teacher_or_student_list({role: '2'}, params[:course_id],current_user)
|
||||
present :data, students, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "返回单个课程"
|
||||
|
|
|
@ -20,6 +20,16 @@ module Mobile
|
|||
present :status, 0
|
||||
end
|
||||
|
||||
desc "显示用户"
|
||||
params do
|
||||
|
||||
end
|
||||
get ':id' do
|
||||
us = UsersService.new
|
||||
ue = us.show_user params
|
||||
present :data, ue,with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "修改用户"
|
||||
params do
|
||||
|
@ -35,7 +45,19 @@ module Mobile
|
|||
authenticate!
|
||||
us = UsersService.new
|
||||
ue = us.edit_user params.merge(id: current_user.id)
|
||||
present :data, ue.user, with: Mobile::Entities::User
|
||||
present :data, ue,with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc '获取用户课程'
|
||||
params do
|
||||
|
||||
end
|
||||
|
||||
get ':id/courses' do
|
||||
us = UsersService.new
|
||||
ue = us.user_courses_list params,current_user.nil? ? User.find(2):current_user
|
||||
present :data, ue,with: Mobile::Entities::Course
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ module Mobile
|
|||
c = f[:course]
|
||||
end
|
||||
if field == :img_url
|
||||
f.img_url if f.respond_to?(:img_url)
|
||||
f[field] if f.is_a?(Hash) && f.key?(field)
|
||||
#f.img_url if f.respond_to?(:img_url)
|
||||
else
|
||||
(c[field] if (c.is_a?(Hash) && c.key?(field))) || (c.send(field) if c.respond_to?(field))
|
||||
end
|
||||
|
|
|
@ -3,7 +3,12 @@ module Mobile
|
|||
class User < Grape::Entity
|
||||
def self.user_expose(f)
|
||||
expose f do |u,opt|
|
||||
u.send(f) if u.respond_to?(f)
|
||||
if u.is_a?(Hash) && u.key?(f)
|
||||
u[f]
|
||||
#else
|
||||
# u.send(f) if u.respond_to?(f)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -95,7 +97,7 @@ class CoursesController < ApplicationController
|
|||
#更新课程信息
|
||||
def update
|
||||
cs = CoursesService.new
|
||||
@course = cs.edit_course params,@course
|
||||
@course = cs.edit_course params,@course,User.current
|
||||
if @course.errors.full_messages.count <= 0
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
|
|
|
@ -72,7 +72,36 @@ class CoursesService
|
|||
#@subPage_title = ''
|
||||
@members = c.member_principals.includes(:roles, :principal).all.sort
|
||||
end
|
||||
@members
|
||||
users = []
|
||||
@members.each do |m|
|
||||
img_url = url_to_avatar(m.user)
|
||||
gender = m.user.user_extensions.gender.nil? ? 0 : m.user.user_extensions.gender
|
||||
work_unit = get_user_work_unit m.user
|
||||
location = get_user_location m.user
|
||||
users << {:id => m.user.id, :img_url => img_url, :nickname => m.user.login, :gender => gender, :work_unit => work_unit, :mail => m.user.mail, :location => location, :brief_introduction => m.user.user_extensions.brief_introduction}
|
||||
end
|
||||
users
|
||||
end
|
||||
|
||||
#获取用户的工作单位
|
||||
def get_user_work_unit user
|
||||
work_unit = ""
|
||||
if user.user_extensions.identity == 0 || user.user_extensions.identity == 1
|
||||
work_unit = user.user_extensions.school.name unless user.user_extensions.school.nil?
|
||||
elsif user.user_extensions.identity == 3
|
||||
work_unit = user.user_extensions.occupation
|
||||
elsif user.user_extensions.identity == 2
|
||||
work_unit = user.firstname
|
||||
end
|
||||
work_unit
|
||||
end
|
||||
|
||||
#获取用户地区
|
||||
def get_user_location user
|
||||
location = ""
|
||||
location << (user.user_extensions.location || '')
|
||||
location << (user.user_extensions.location_city || '')
|
||||
location
|
||||
end
|
||||
|
||||
#课程通知列表
|
||||
|
@ -175,8 +204,9 @@ class CoursesService
|
|||
#params[:term]:学期(秋季学期或春季学期)
|
||||
#params[:time]: 年份(例:2014)
|
||||
#params[:class_period]:学时总数
|
||||
def edit_course params,course
|
||||
course.safe_attributes = params[:course]
|
||||
def edit_course(params,course,current_user)
|
||||
course.send(:safe_attributes=, params[:course], current_user)
|
||||
#course.safe_attributes = params[:course]
|
||||
course.time = params[:time]
|
||||
course.term = params[:term]
|
||||
course.class_period = params[:class_period]
|
||||
|
@ -196,14 +226,27 @@ class CoursesService
|
|||
#退出课程
|
||||
#object_id: 课程id
|
||||
#user:当前用户
|
||||
#@state == 0 退出成功
|
||||
#@state == 1 不在课程中
|
||||
#@state == 2 您还未登录
|
||||
#@state 其他 未知错误,请稍后再试
|
||||
def exit_course params,user
|
||||
if user.nil?
|
||||
@state = 2
|
||||
return @state
|
||||
end
|
||||
@member = Member.where('course_id = ? and user_id = ?', params[:object_id], user.id)
|
||||
if @member.nil? || @member.count == 0
|
||||
@state = 1
|
||||
return @state
|
||||
end
|
||||
@member.first.destroy
|
||||
|
||||
joined = StudentsForCourse.where('student_id = ? and course_id = ?', user.id, params[:object_id])
|
||||
joined.each do |join|
|
||||
join.delete
|
||||
@state = 0
|
||||
end
|
||||
@state
|
||||
end
|
||||
|
||||
#加入课程
|
||||
|
@ -216,20 +259,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
|
||||
|
@ -239,7 +283,7 @@ class CoursesService
|
|||
else
|
||||
@state = 4
|
||||
end
|
||||
[@state,course]
|
||||
{:state => @state,:course => course}
|
||||
end
|
||||
|
||||
#作业列表
|
||||
|
|
|
@ -13,16 +13,17 @@ class HomeworkService
|
|||
def show_homework params
|
||||
@bid = Bid.find(params[:id])
|
||||
course = @bid.courses.first
|
||||
author = @bid.author.firstname + @bid.author.lastname
|
||||
author = @bid.author.lastname + @bid.author.firstname
|
||||
many_times = course.homeworks.index(@bid) + 1
|
||||
name = @bid.name
|
||||
homework_count = @bid.homeworks.count
|
||||
homework_count = @bid.homeworks.count #已提交的作业数量
|
||||
student_questions_count = @bid.commit.nil? ? 0 : @bid.commit
|
||||
description = @bid.description
|
||||
if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2
|
||||
state = bid.comment_status
|
||||
end
|
||||
{:course => 'course', :atuthor => 'author', :many_times => 'many_times', :name => 'name', :homework_count => 'homework_count',
|
||||
:descriptiong => 'description', :state => 'state'}
|
||||
{:course => course, :atuthor => author, :many_times => many_times, :name => name, :homework_count => homework_count,:student_questions_count => student_questions_count,
|
||||
:descriptiong => description, :state => state}
|
||||
end
|
||||
|
||||
# 启动作业匿评
|
||||
|
|
|
@ -36,7 +36,11 @@ class UsersService
|
|||
ue.user_id = @user.id
|
||||
ue.save
|
||||
end
|
||||
@user
|
||||
img_url = url_to_avatar(@user)
|
||||
gender = @user.user_extensions.gender.nil? ? 0 : @user.user_extensions.gender
|
||||
work_unit = get_user_work_unit @user
|
||||
location = get_user_location @user
|
||||
{:id => @user.id, :img_url => img_url, :nickname => @user.login, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extensions.brief_introduction}
|
||||
end
|
||||
|
||||
#显示用户
|
||||
|
@ -95,7 +99,11 @@ class UsersService
|
|||
logger.error "[Error] avatar : users_service#edit_user ===> #{e}"
|
||||
end
|
||||
end
|
||||
[:user_extensions =>@se,:img_url => url_to_avatar(@user),:work_unit => get_user_work_unit(@user),:location => get_user_location(@user)]
|
||||
img_url = url_to_avatar(@user)
|
||||
gender = @user.user_extensions.gender.nil? ? 0 : @user.user_extensions.gender
|
||||
work_unit = get_user_work_unit @user
|
||||
location = get_user_location @user
|
||||
{:id => @user.id, :img_url => img_url, :nickname => @user.login, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extensions.brief_introduction}
|
||||
end
|
||||
|
||||
#获取用户的工作单位
|
||||
|
@ -138,7 +146,11 @@ class UsersService
|
|||
membership = @user.coursememberships.all(:conditions => Course.visible_condition(User.current))
|
||||
end
|
||||
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
|
||||
membership
|
||||
course_list = []
|
||||
membership.each do |mp|
|
||||
course_list << {:course => mp.course,:img_url => url_to_avatar(mp.course)}
|
||||
end
|
||||
course_list
|
||||
end
|
||||
|
||||
#修改密码
|
||||
|
|
Loading…
Reference in New Issue