Merge branch 'weixin_guange' of https://git.trustie.net/jacknudt/trustieforge into weixin_guange
commit
1c5b22abf4
@ -1,17 +1,18 @@
|
|||||||
#coding=utf-8
|
#coding=utf-8
|
||||||
|
|
||||||
module Mobile
|
module Mobile
|
||||||
module Apis
|
module Apis
|
||||||
class BlogComments< Grape::API
|
class BlogComments< Grape::API
|
||||||
resources :blog_comments do
|
resources :blog_comments do
|
||||||
|
|
||||||
desc "get special topic"
|
desc "get special topic"
|
||||||
get ':id' do
|
get ':id' do
|
||||||
blog = BlogComment.find params[:id]
|
blog = BlogComment.find params[:id]
|
||||||
present :blog, message, with: Mobile::Entities::BlogComment
|
present :data, blog, with: Mobile::Entities::BlogComment
|
||||||
present :status, 0
|
present :status, 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,46 +1,50 @@
|
|||||||
module Mobile
|
module Mobile
|
||||||
module Entities
|
module Entities
|
||||||
class BlogComment < Grape::Entity
|
class BlogComment < Grape::Entity
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
include ApiHelper
|
include ApiHelper
|
||||||
def self.blog_comment_expose(f)
|
def self.blog_comment_expose(f)
|
||||||
expose f do |u,opt|
|
expose f do |u,opt|
|
||||||
if u.is_a?(Hash) && u.key?(f)
|
if u.is_a?(Hash) && u.key?(f)
|
||||||
u[f]
|
u[f]
|
||||||
elsif u.is_a?(::BlogComment)
|
elsif u.is_a?(::BlogComment)
|
||||||
if u.respond_to?(f)
|
if u.respond_to?(f)
|
||||||
if f == :created_at
|
if f == :created_at
|
||||||
format_time( u.send(f))
|
format_time( u.send(f))
|
||||||
else
|
else
|
||||||
u.send(f)
|
u.send(f)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# case f
|
case f
|
||||||
# when :xx
|
when :blog_praise_count
|
||||||
# #
|
get_activity_praise_num(u)
|
||||||
# end
|
when :lasted_comment
|
||||||
end
|
time_from_now(u.created_at)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
end
|
||||||
expose :user, using: Mobile::Entities::User do |c, opt|
|
end
|
||||||
if c.is_a?(::BlogComment)
|
|
||||||
c.author
|
expose :user, using: Mobile::Entities::User do |c, opt|
|
||||||
end
|
if c.is_a?(::BlogComment)
|
||||||
end
|
c.author
|
||||||
blog_comment_expose :blog_id
|
end
|
||||||
blog_comment_expose :title
|
end
|
||||||
blog_comment_expose :content
|
blog_comment_expose :blog_id
|
||||||
blog_comment_expose :comments_count
|
blog_comment_expose :title
|
||||||
blog_comment_expose :created_at
|
blog_comment_expose :content
|
||||||
blog_comment_expose :id
|
blog_comment_expose :comments_count
|
||||||
expose :blog_comment_children, using:Mobile::Entities::BlogComment do |c,opt|
|
blog_comment_expose :created_at
|
||||||
if c.is_a? (::BlogComment)
|
blog_comment_expose :lasted_comment
|
||||||
c.children
|
blog_comment_expose :id
|
||||||
end
|
blog_comment_expose :blog_praise_count
|
||||||
end
|
expose :blog_comment_children, using:Mobile::Entities::BlogComment do |c,opt|
|
||||||
end
|
if c.is_a? (::BlogComment)
|
||||||
end
|
c.children
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
@ -1,66 +1,69 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
module Mobile
|
module Mobile
|
||||||
module Entities
|
module Entities
|
||||||
class Whomework <Grape::Entity
|
class Whomework <Grape::Entity
|
||||||
include ApiHelper
|
include ApiHelper
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
include Redmine::I18n
|
include Redmine::I18n
|
||||||
def self.whomework_expose(f)
|
def self.whomework_expose(f)
|
||||||
expose f do |wh, opt|
|
expose f do |wh, opt|
|
||||||
if wh.is_a?(Hash) && wh.key?(f)
|
if wh.is_a?(Hash) && wh.key?(f)
|
||||||
if f == :created_at
|
wh[f]
|
||||||
format_time(wh[f])
|
elsif wh.is_a?(::HomeworkCommon)
|
||||||
else
|
if wh.respond_to?(f)
|
||||||
wh[f]
|
if f == :created_at
|
||||||
end
|
format_time(wh.send(f))
|
||||||
elsif wh.is_a?(::HomeworkCommon)
|
else
|
||||||
if wh.respond_to?(f)
|
wh.send(f)
|
||||||
wh.send(f)
|
end
|
||||||
else
|
else
|
||||||
case f
|
case f
|
||||||
when :absence_penalty
|
when :absence_penalty
|
||||||
wh.nil? || wh.homework_detail_manual.nil? ? 0 : wh.homework_detail_manual.absence_penalty
|
wh.nil? || wh.homework_detail_manual.nil? ? 0 : wh.homework_detail_manual.absence_penalty
|
||||||
when :evaluation_start
|
when :evaluation_start
|
||||||
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_start, 0)
|
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_start, 0)
|
||||||
when :evaluation_end
|
when :evaluation_end
|
||||||
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_end, 1)
|
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_end, 1)
|
||||||
when :whomework_praise_count
|
when :whomework_praise_count
|
||||||
get_activity_praise_num(wh)
|
get_activity_praise_num(wh)
|
||||||
when :whomework_journal_count
|
when :whomework_journal_count
|
||||||
wh.journals_for_messages.count
|
wh.journals_for_messages.count
|
||||||
end
|
when :course_name
|
||||||
end
|
wh.course.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
expose :author, using: Mobile::Entities::User do |w, opt|
|
end
|
||||||
if w.is_a?(::HomeworkCommon)
|
|
||||||
w.user
|
expose :author, using: Mobile::Entities::User do |w, opt|
|
||||||
end
|
if w.is_a?(::HomeworkCommon)
|
||||||
end
|
w.user
|
||||||
expose :name
|
end
|
||||||
expose :description
|
end
|
||||||
expose :publish_time
|
expose :name
|
||||||
expose :end_time
|
expose :description
|
||||||
expose :homework_type
|
expose :publish_time
|
||||||
expose :late_penalty
|
expose :end_time
|
||||||
expose :course_id
|
expose :homework_type
|
||||||
expose :anonymous_comment
|
expose :late_penalty
|
||||||
expose :quotes
|
expose :course_id
|
||||||
expose :is_open
|
expose :anonymous_comment
|
||||||
whomework_expose :created_at
|
expose :quotes
|
||||||
whomework_expose :absence_penalty
|
expose :is_open
|
||||||
whomework_expose :evaluation_start
|
whomework_expose :course_name
|
||||||
whomework_expose :evaluation_end
|
whomework_expose :created_at
|
||||||
whomework_expose :whomework_praise_count
|
whomework_expose :absence_penalty
|
||||||
whomework_expose :whomework_journal_count
|
whomework_expose :evaluation_start
|
||||||
expose :journals_for_messages, using: Mobile::Entities::Jours do |f, opt|
|
whomework_expose :evaluation_end
|
||||||
#f[:journals_for_messages] if f.is_a?(Hash) && f.key?(:journals_for_messages)
|
whomework_expose :whomework_praise_count
|
||||||
if f.is_a?(::HomeworkCommon)
|
whomework_expose :whomework_journal_count
|
||||||
f.journals_for_messages
|
expose :journals_for_messages, using: Mobile::Entities::Jours do |f, opt|
|
||||||
end
|
#f[:journals_for_messages] if f.is_a?(Hash) && f.key?(:journals_for_messages)
|
||||||
end
|
if f.is_a?(::HomeworkCommon)
|
||||||
end
|
f.journals_for_messages
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Reference in new issue