diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 8f8c08c3f..7dbfaffb0 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -209,6 +209,16 @@ module Mobile present :status, 0 end + desc '课程动态' + params do + requires :token, type: String + end + get "course_dynamic/:id" do + cs = CoursesService.new + count = cs.course_dynamic(params,current_user) + present :data, count, with: Mobile::Entities::CourseDynamic + present :status, 0 + end end end diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 69260716e..d780b9db4 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -22,13 +22,15 @@ module Mobile desc "显示用户" params do - + requires :id, type: Integer end - get ':id' do - us = UsersService.new - ue = us.show_user params - present :data, ue,with: Mobile::Entities::User - present :status, 0 + route_param :id do + get do + us = UsersService.new + ue = us.show_user params + present :data, ue,with: Mobile::Entities::User + present :status, 0 + end end desc "修改用户" @@ -77,11 +79,11 @@ module Mobile present :status, 0 end - desc "用户搜索" + desc "用户搜索" params do requires :name, type: String, desc: '用户名关键字' end - get 'search' do + get 'search/search_user' do us = UsersService.new user = us.search_user params present :data, user, with: Mobile::Entities::User diff --git a/app/api/mobile/entities/course_dynamic.rb b/app/api/mobile/entities/course_dynamic.rb new file mode 100644 index 000000000..11f8c2682 --- /dev/null +++ b/app/api/mobile/entities/course_dynamic.rb @@ -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 \ No newline at end of file diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb index b227a96ab..c865a500b 100644 --- a/app/helpers/api_helper.rb +++ b/app/helpers/api_helper.rb @@ -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 \ No newline at end of file diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 341ecd422..f4201774a 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -2,6 +2,7 @@ class CoursesService include ApplicationHelper include CoursesHelper include HomeworkAttachHelper + include ApiHelper #TODO:尚未整合权限系统 #参数school_id为0或不传时返回所有课程,否则返回对应学校的课程 #参数per_page_count分页功能,每页显示的课程数 @@ -326,6 +327,22 @@ class CoursesService end 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' + 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 def show_homework_info course,bid,current_user,is_course_teacher author = bid.author.lastname + bid.author.firstname @@ -361,4 +378,6 @@ class CoursesService :description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation} end + + end \ No newline at end of file