课程动态接口修改为用户所有课程动态接口
This commit is contained in:
parent
18271946d7
commit
32264fb4a6
|
@ -213,7 +213,7 @@ module Mobile
|
|||
present :status, 0
|
||||
end
|
||||
|
||||
desc '课程动态'
|
||||
desc '用户课程动态'
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
|
|
|
@ -333,10 +333,22 @@ class CoursesService
|
|||
end
|
||||
|
||||
def course_dynamic(params,current_user)
|
||||
course = Course.find(params[:id])
|
||||
if current_user.nil? || !(current_user.admin? || course.is_public == 1 || (course.is_public == 0 && current_user.member_of_course?(course)))
|
||||
raise '403'
|
||||
|
||||
@user = User.find(params[:id])
|
||||
if !current_user.admin? && !@user.active?
|
||||
raise '404'
|
||||
return
|
||||
end
|
||||
if current_user == @user || current_user.admin?
|
||||
membership = @user.coursememberships.all
|
||||
else
|
||||
membership = @user.coursememberships.all(:conditions => Course.visible_condition(current_user))
|
||||
end
|
||||
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
|
||||
result = []
|
||||
membership.each do |mp|
|
||||
course = mp.course
|
||||
unless current_user.nil? || !(current_user.admin? || course.is_public == 1 || (course.is_public == 0 && current_user.member_of_course?(course)))
|
||||
count,is_teacher = get_course_anonymous_evaluation current_user,course
|
||||
if is_teacher
|
||||
student_commit_number = count
|
||||
|
@ -345,12 +357,14 @@ class CoursesService
|
|||
end
|
||||
news_count = course.news.count
|
||||
message_count = course.journals_for_messages.count
|
||||
result = []
|
||||
|
||||
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 1,:count => message_count}
|
||||
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 2,:count => need_anonymous_comments_count}
|
||||
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 3,:count => student_commit_number}
|
||||
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 4,:count => news_count}
|
||||
#{:course_name => course.name,:need_anonymous_comments_count=>need_anonymous_comments_count,:student_commit_number=>student_commit_number,:news_count=> news_count,:message_count=>message_count}
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue