添加课程动态接口

This commit is contained in:
z9hang 2015-02-06 15:52:34 +08:00
parent cc83b30fc6
commit d913f89a82
4 changed files with 34 additions and 7 deletions

View File

@ -216,7 +216,7 @@ module Mobile
get "course_dynamic/:id" do
cs = CoursesService.new
count = cs.course_dynamic(params,current_user)
present :data, count
present :data, count, with: Mobile::Entities::CourseDynamic
present :status, 0
end

View File

@ -0,0 +1,17 @@
module Mobile
module Entities
class CourseDynamic < Grape::Entity
def self.course_dynamic_expose(field)
expose field do |c,opt|
c[field] if (c.is_a?(Hash) && c.key?(field))
end
end
course_dynamic_expose :course_name
course_dynamic_expose :need_anonymous_comments_count
course_dynamic_expose :student_commit_number
course_dynamic_expose :news_count
course_dynamic_expose :message_count
end
end
end

View File

@ -44,8 +44,7 @@ module ApiHelper
#param: user => "用户", course_id => "查询的课程ID"
#return: 作业的数量
#########################################################
def get_course_anonymous_evaluation user,course_id
course = Course.find course_id
def get_course_anonymous_evaluation user,course
count = 0
if course
is_teacher = is_course_teacher user,course
@ -59,6 +58,6 @@ module ApiHelper
end
end
end
count
[count,is_teacher]
end
end

View File

@ -327,9 +327,20 @@ class CoursesService
end
end
def course_dynamic params,current_user
count = get_course_anonymous_evaluation current_user,params[:id]
count
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'
end
count,is_teacher = get_course_anonymous_evaluation current_user,course
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
{: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
private