parent
406bb7930c
commit
4de598873f
@ -0,0 +1,32 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
module Mobile
|
||||||
|
module Apis
|
||||||
|
class Activities< Grape::API
|
||||||
|
resources :activities do
|
||||||
|
|
||||||
|
desc "get user activities"
|
||||||
|
get ':id' do
|
||||||
|
#uw = UserWechat.find params[:openid]
|
||||||
|
user = User.find params[:id]
|
||||||
|
shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id)
|
||||||
|
shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
|
||||||
|
page = params[:page] ? params[:page].to_i + 1 : 0
|
||||||
|
user_project_ids = (user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
|
||||||
|
user_course_ids = (user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")"
|
||||||
|
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
|
||||||
|
project_types = "('Message','Issue','ProjectCreateInfo')"
|
||||||
|
principal_types = "JournalsForMessage"
|
||||||
|
|
||||||
|
blog_ids = "("+user.blog.id.to_s+","+((User.watched_by(user.id).count == 0 )? '0' :User.watched_by(user.id).map{|u| u.blog.id}.join(','))+")"
|
||||||
|
activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
|
||||||
|
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
|
||||||
|
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " +
|
||||||
|
"or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(page * 10)
|
||||||
|
present :data, activities, with: Mobile::Entities::Activity
|
||||||
|
present :status, 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,17 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
module Mobile
|
||||||
|
module Apis
|
||||||
|
class Whomeworks< Grape::API
|
||||||
|
resources :whomeworks do
|
||||||
|
|
||||||
|
desc "get one homework"
|
||||||
|
get ':id' do
|
||||||
|
homework = HomeworkCommon.find params[:id]
|
||||||
|
present :data, homework, with: Mobile::Entities::Whomework
|
||||||
|
present :status, 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,102 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
module Mobile
|
||||||
|
module Entities
|
||||||
|
class Activity <Grape::Entity
|
||||||
|
include ApplicationHelper
|
||||||
|
include ApiHelper
|
||||||
|
def self.act_expose(f)
|
||||||
|
expose f do |ac,opt|
|
||||||
|
if ac.is_a?(Hash) && ac.key?(f)
|
||||||
|
ac[f]
|
||||||
|
elsif ac.is_a?(::UserActivity)
|
||||||
|
if ac.respond_to?(f)
|
||||||
|
ac.send(f)
|
||||||
|
else
|
||||||
|
case f
|
||||||
|
when :user_act
|
||||||
|
if ac.act_type == "ProjectCreateInfo"
|
||||||
|
ac unless ac.nil?
|
||||||
|
else
|
||||||
|
ac.act unless ac.nil? || ac.act.nil?
|
||||||
|
end
|
||||||
|
when :reply_num
|
||||||
|
if ac.act_type == "HomeworkCommon"
|
||||||
|
ac.nil? || ac.act.nil? ? 0 : ac.act.journals_for_messages.count
|
||||||
|
elsif ac.act_type == "News"
|
||||||
|
ac.nil? || ac.act.nil? ? 0 : ac.act.comments.count
|
||||||
|
elsif ac.act_type == "Message" || ac.act_type == "BlogComment" || ac.act_type == "JournalsForMessage"
|
||||||
|
ac.nil? || ac.act.nil? ? 0 : ac.act.children.count
|
||||||
|
elsif ac.act_type == "Issue"
|
||||||
|
ac.nil? || ac.act.nil? ? 0 : ac.act.journals.count
|
||||||
|
end
|
||||||
|
when :activity_praise_num
|
||||||
|
if ac.act_type == "HomeworkCommon" || ac.act_type == "News" || ac.act_type == "Message" || ac.act_type == "BlogComment" || ac.act_type == "JournalsForMessage" || ac.act_type == "Issue"
|
||||||
|
ac.nil? || ac.act.nil? ? 0 : get_activity_praise_num(ac.act)
|
||||||
|
end
|
||||||
|
when :homework_common_detail_manual
|
||||||
|
if ac.act_type == "HomeworkCommon"
|
||||||
|
ac.act.homework_detail_manual unless ac.nil? || ac.act.nil? || ac.act.homework_detail_manual.nil?
|
||||||
|
end
|
||||||
|
when :course_project_name
|
||||||
|
if ac.container_type == "Course"
|
||||||
|
name = (get_course(ac.container_id)).name
|
||||||
|
name
|
||||||
|
elsif ac.container_type == "Project"
|
||||||
|
name = (get_project(ac.container_id)).name
|
||||||
|
name
|
||||||
|
elsif ac.container_type == "Blog"
|
||||||
|
"发表博客"
|
||||||
|
end
|
||||||
|
when :activity_type_name
|
||||||
|
if ac.container_type == "Course"
|
||||||
|
case ac.act_type
|
||||||
|
when "HomeworkCommon"
|
||||||
|
"课程作业"
|
||||||
|
when "News"
|
||||||
|
"课程通知"
|
||||||
|
when "Message"
|
||||||
|
"课程问答区"
|
||||||
|
when "Poll"
|
||||||
|
"课程问卷"
|
||||||
|
when "Course"
|
||||||
|
"课程"
|
||||||
|
end
|
||||||
|
elsif ac.container_type == "Project"
|
||||||
|
case ac.act_type
|
||||||
|
when "Issue"
|
||||||
|
"项目缺陷"
|
||||||
|
when "Message"
|
||||||
|
"项目问答区"
|
||||||
|
when "ProjectCreateInfo"
|
||||||
|
"项目"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expose :act_type
|
||||||
|
expose :container_type
|
||||||
|
expose :author, using: Mobile::Entities::User do |a, opt|
|
||||||
|
if a.is_a? ::UserActivity
|
||||||
|
if a.act_type == "ProjectCreateInfo"
|
||||||
|
get_user(get_project(a.act_id).user_id)
|
||||||
|
elsif a.act_type == 'Issue' || a.act_type == 'News' || a.act_type == 'Message' || a.act_type == 'BlogComment'
|
||||||
|
a.act.author
|
||||||
|
elsif a.act_type == 'HomeworkCommon' || a.act_type == 'Poll' || a.act_type == 'JournalsForMessage'
|
||||||
|
a.act.user
|
||||||
|
elsif a.act_type == 'Course'
|
||||||
|
a.act.teacher
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
act_expose :homework_common_detail_manual
|
||||||
|
act_expose :reply_num
|
||||||
|
act_expose :activity_praise_num
|
||||||
|
act_expose :user_act
|
||||||
|
act_expose :course_project_name
|
||||||
|
act_expose :activity_type_name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,53 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
module Mobile
|
||||||
|
module Entities
|
||||||
|
class Whomework <Grape::Entity
|
||||||
|
include ApiHelper
|
||||||
|
include ApplicationHelper
|
||||||
|
include Redmine::I18n
|
||||||
|
def self.whomework_expose(f)
|
||||||
|
expose f do |wh, opt|
|
||||||
|
if wh.is_a?(Hash) && wh.key?(f)
|
||||||
|
if f == :created_at
|
||||||
|
format_time(wh[f])
|
||||||
|
else
|
||||||
|
wh[f]
|
||||||
|
end
|
||||||
|
elsif wh.is_a?(::HomeworkCommon)
|
||||||
|
if wh.respond_to?(f)
|
||||||
|
wh.send(f)
|
||||||
|
else
|
||||||
|
case f
|
||||||
|
when :absence_penalty
|
||||||
|
wh.nil? || wh.homework_detail_manual.nil? ? 0 : wh.homework_detail_manual.absence_penalty
|
||||||
|
when :evaluation_start
|
||||||
|
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_start, 0)
|
||||||
|
when :evaluation_end
|
||||||
|
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_end, 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expose :name
|
||||||
|
expose :description
|
||||||
|
expose :publish_time
|
||||||
|
expose :end_time
|
||||||
|
expose :homework_type
|
||||||
|
expose :late_penalty
|
||||||
|
expose :course_id
|
||||||
|
expose :anonymous_comment
|
||||||
|
expose :quotes
|
||||||
|
expose :is_open
|
||||||
|
whomework_expose :created_at
|
||||||
|
whomework_expose :absence_penalty
|
||||||
|
whomework_expose :evaluation_start
|
||||||
|
whomework_expose :evaluation_end
|
||||||
|
expose :author, using: Mobile::Entities::User do |w, opt|
|
||||||
|
if w.is_a?(::HomeworkCommon)
|
||||||
|
w.user
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue