动态api调整
This commit is contained in:
parent
c8142b3ee5
commit
9cebcfdd2d
|
@ -10,6 +10,10 @@ module Mobile
|
|||
require_relative 'apis/issues'
|
||||
require_relative 'apis/activities'
|
||||
require_relative 'apis/whomeworks'
|
||||
require_relative 'apis/newss'
|
||||
require_relative 'apis/journal_for_messages'
|
||||
require_relative 'apis/messages'
|
||||
require_relative 'apis/blog_comments'
|
||||
|
||||
class API < Grape::API
|
||||
version 'v1', using: :path
|
||||
|
@ -46,6 +50,10 @@ module Mobile
|
|||
mount Apis::Issues
|
||||
mount Apis::Activities
|
||||
mount Apis::Whomeworks
|
||||
mount Apis::Newss
|
||||
mount Apis::JournalForMessages
|
||||
mount Apis::Messages
|
||||
mount Apis::BlogComments
|
||||
|
||||
#add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'})
|
||||
#add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class BlogComments< Grape::API
|
||||
resources :blog_comments do
|
||||
|
||||
desc "get special topic"
|
||||
get ':id' do
|
||||
blog = BlogComment.find params[:id]
|
||||
present :blog, message, with: Mobile::Entities::BlogComment
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -7,7 +7,7 @@ module Mobile
|
|||
|
||||
desc "get special issuse"
|
||||
get ':id' do
|
||||
issue = Issue.where("project_id = ?", params[:id])
|
||||
issue = Issue.find params[:id]
|
||||
present :data, issue, with: Mobile::Entities::Issue
|
||||
present :status, 0
|
||||
end
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class JournalForMessages< Grape::API
|
||||
resources :journal_for_messages do
|
||||
|
||||
desc "get special journal"
|
||||
get ':id' do
|
||||
jour = JournalsForMessage.find params[:id]
|
||||
present :data, jour, with: Mobile::Entities::Jours
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Messages< Grape::API
|
||||
resources :messages do
|
||||
|
||||
desc "get special topic"
|
||||
get ':id' do
|
||||
message = Message.find params[:id]
|
||||
present :data, message, with: Mobile::Entities::Message
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Newss< Grape::API
|
||||
resources :newss do
|
||||
|
||||
desc "get special news"
|
||||
get ':id' do
|
||||
news = News.find params[:id]
|
||||
present :data, news, with: Mobile::Entities::News
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -29,14 +29,32 @@ module Mobile
|
|||
elsif ac.act_type == "Issue"
|
||||
ac.nil? || ac.act.nil? ? 0 : ac.act.journals.count
|
||||
end
|
||||
when :subject
|
||||
if ac.act_type == "HomeworkCommon"
|
||||
ac.act.name unless ac.nil? || ac.act.nil?
|
||||
elsif ac.act_type == "News" || ac.act_type == "BlogComment"
|
||||
ac.act.title unless ac.nil? || ac.act.nil?
|
||||
elsif ac.act_type == "Message" || ac.act_type == "Issue"
|
||||
ac.act.subject unless ac.nil? || ac.act.nil?
|
||||
elsif ac.act_type == "JournalsForMessage"
|
||||
ac.act.private == 0 ? "留言" : "私信"
|
||||
end
|
||||
when :description
|
||||
if ac.act_type == "HomeworkCommon" || ac.act_type == "Issue" || ac.act_type == "News"
|
||||
ac.act.description unless ac.nil? || ac.act.nil?
|
||||
elsif ac.act_type == "Message" || ac.act_type == "BlogComment"
|
||||
ac.act.content unless ac.nil? || ac.act.nil?
|
||||
end
|
||||
when :latest_update
|
||||
time_from_now ac.updated_at unless ac.nil?
|
||||
when :activity_praise_count
|
||||
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 :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
|
||||
|
@ -91,10 +109,22 @@ module Mobile
|
|||
end
|
||||
end
|
||||
end
|
||||
act_expose :homework_common_detail_manual #作业相关信息
|
||||
expose :homework_common_detail , using: Mobile::Entities::Whomework do |a, opt| #作业相关信息
|
||||
if a.act_type == "HomeworkCommon"
|
||||
a.act
|
||||
end
|
||||
end
|
||||
expose :issue_detail, using: Mobile::Entities::Issue do |a, opt| #缺陷信息
|
||||
if a.act_type == "Issue"
|
||||
a.act
|
||||
end
|
||||
end
|
||||
act_expose :reply_count #回复数
|
||||
act_expose :activity_praise_count #点赞数
|
||||
act_expose :user_act #某个动态
|
||||
#act_expose :user_act #某个动态
|
||||
act_expose :subject #标题
|
||||
act_expose :description #描述
|
||||
act_expose :latest_update #最新更新时间
|
||||
act_expose :course_project_name #课程/项目名字
|
||||
act_expose :activity_type_name #课程问答区/项目缺陷等
|
||||
end
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class BlogComment < Grape::Entity
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.blog_comment_expose(f)
|
||||
expose f do |u,opt|
|
||||
if u.is_a?(Hash) && u.key?(f)
|
||||
u[f]
|
||||
elsif u.is_a?(::BlogComment)
|
||||
if u.respond_to?(f)
|
||||
if f == :created_at
|
||||
format_time( u.send(f))
|
||||
else
|
||||
u.send(f)
|
||||
end
|
||||
else
|
||||
# case f
|
||||
# when :xx
|
||||
# #
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
expose :user, using: Mobile::Entities::User do |c, opt|
|
||||
if c.is_a?(::BlogComment)
|
||||
c.author
|
||||
end
|
||||
end
|
||||
blog_comment_expose :blog_id
|
||||
blog_comment_expose :title
|
||||
blog_comment_expose :content
|
||||
blog_comment_expose :comments_count
|
||||
blog_comment_expose :created_at
|
||||
blog_comment_expose :id
|
||||
expose :blog_comment_children, using:Mobile::Entities::BlogComment do |c,opt|
|
||||
if c.is_a? (::BlogComment)
|
||||
c.children
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,7 +4,24 @@ module Mobile
|
|||
include ApiHelper
|
||||
include Redmine::I18n
|
||||
def self.issue_expose(f)
|
||||
f
|
||||
expose f do |issue, opt|
|
||||
if issue.is_a?(Hash) && issue.key?(f)
|
||||
issue[f]
|
||||
elsif issue.is_a?(::Issue)
|
||||
if issue.respond_to?(f)
|
||||
issue.send(f)
|
||||
else
|
||||
case f
|
||||
when :issue_priority
|
||||
get_issue_priority_api issue.priority_id
|
||||
when :issue_assigned_to
|
||||
(get_user(issue.assigned_to_id)).login
|
||||
when :issue_status
|
||||
IssueStatus.find(issue.status_id).name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
expose :subject
|
||||
expose :description
|
||||
|
@ -13,7 +30,6 @@ module Mobile
|
|||
issue_expose :issue_priority
|
||||
issue_expose :issue_assigned_to
|
||||
issue_expose :issue_status
|
||||
issue_expose :issue_status
|
||||
end
|
||||
end
|
||||
end
|
|
@ -55,8 +55,11 @@ module Mobile
|
|||
whomework_expose :evaluation_end
|
||||
whomework_expose :whomework_praise_count
|
||||
whomework_expose :whomework_journal_count
|
||||
expose :jours, using: Mobile::Entities::Jours do |f, opt|
|
||||
f[:jour] if f.is_a?(Hash) && f.key?(:jour)
|
||||
expose :journals_for_messages, using: Mobile::Entities::Jours do |f, opt|
|
||||
#f[:journals_for_messages] if f.is_a?(Hash) && f.key?(:journals_for_messages)
|
||||
if f.is_a?(::HomeworkCommon)
|
||||
f.journals_for_messages
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -240,4 +240,21 @@ module ApiHelper
|
|||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
#获取缺陷的优先级
|
||||
def get_issue_priority_api value
|
||||
issuetype = ""
|
||||
if value == 4
|
||||
issuetype = "紧急"
|
||||
elsif value == 2
|
||||
issuetype = "正常"
|
||||
elsif value == 3
|
||||
issuetype = "高"
|
||||
elsif value == 1
|
||||
issuetype = "低"
|
||||
else
|
||||
issuetype = "立刻"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue