课程动态接口修改为用户所有课程动态接口

This commit is contained in:
z9hang 2015-03-03 09:11:47 +08:00
parent 18271946d7
commit 32264fb4a6
2 changed files with 29 additions and 15 deletions

View File

@ -213,7 +213,7 @@ module Mobile
present :status, 0 present :status, 0
end end
desc '课程动态' desc '用户课程动态'
params do params do
requires :token, type: String requires :token, type: String
end end

View File

@ -333,24 +333,38 @@ class CoursesService
end end
def course_dynamic(params,current_user) 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))) @user = User.find(params[:id])
raise '403' if !current_user.admin? && !@user.active?
raise '404'
return
end end
count,is_teacher = get_course_anonymous_evaluation current_user,course if current_user == @user || current_user.admin?
if is_teacher membership = @user.coursememberships.all
student_commit_number = count
else else
need_anonymous_comments_count = count membership = @user.coursememberships.all(:conditions => Course.visible_condition(current_user))
end end
news_count = course.news.count membership.sort! {|older, newer| newer.created_on <=> older.created_on }
message_count = course.journals_for_messages.count
result = [] result = []
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 1,:count => message_count} membership.each do |mp|
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 2,:count => need_anonymous_comments_count} course = mp.course
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 3,:count => student_commit_number} unless current_user.nil? || !(current_user.admin? || course.is_public == 1 || (course.is_public == 0 && current_user.member_of_course?(course)))
result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 4,:count => news_count} count,is_teacher = get_course_anonymous_evaluation current_user,course
#{: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} if is_teacher
student_commit_number = count
else
need_anonymous_comments_count = count
end
news_count = course.news.count
message_count = course.journals_for_messages.count
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 result
end end