diff --git a/app/api/mobile/apis/blog_comments.rb b/app/api/mobile/apis/blog_comments.rb index f94d0bbc7..01fd05c0f 100644 --- a/app/api/mobile/apis/blog_comments.rb +++ b/app/api/mobile/apis/blog_comments.rb @@ -1,17 +1,18 @@ -#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 +#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 :data, blog, with: Mobile::Entities::BlogComment + present :status, 0 + end + end + end + end +end + diff --git a/app/api/mobile/entities/blog_comment.rb b/app/api/mobile/entities/blog_comment.rb index 1e7a6dd75..ac3fc3d9e 100644 --- a/app/api/mobile/entities/blog_comment.rb +++ b/app/api/mobile/entities/blog_comment.rb @@ -1,46 +1,50 @@ -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 +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 :blog_praise_count + get_activity_praise_num(u) + when :lasted_comment + time_from_now(u.created_at) + 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 :lasted_comment + blog_comment_expose :id + blog_comment_expose :blog_praise_count + expose :blog_comment_children, using:Mobile::Entities::BlogComment do |c,opt| + if c.is_a? (::BlogComment) + c.children + end + end + end + end end \ No newline at end of file diff --git a/app/api/mobile/entities/jours.rb b/app/api/mobile/entities/jours.rb index 97eabd21f..257721d3e 100644 --- a/app/api/mobile/entities/jours.rb +++ b/app/api/mobile/entities/jours.rb @@ -15,9 +15,9 @@ module Mobile f.send(field) end else - case f - when :course_name - f[:jour_type] == "Course" ? f.course.name : "" + case field + when :lasted_comment + time_from_now f.created_on end end end @@ -29,6 +29,7 @@ module Mobile f.user end jours_expose :created_on + jours_expose :lasted_comment jours_expose :notes jours_expose :m_reply_id jours_expose :m_parent_id diff --git a/app/api/mobile/entities/message.rb b/app/api/mobile/entities/message.rb index 6a2ca1fb0..3d7fb7bbe 100644 --- a/app/api/mobile/entities/message.rb +++ b/app/api/mobile/entities/message.rb @@ -15,10 +15,16 @@ module Mobile u.send(f) end else - # case f - # when :xx - # # - # end + case f + when :course_project_name + if u.board.project_id == -1 + u.course.name + else + u.project.name + end + when :lasted_comment + time_from_now u.created_on + end end end @@ -30,12 +36,14 @@ module Mobile c.author end end + message_expose :course_project_name message_expose :board_id message_expose :subject message_expose :content message_expose :replies_count message_expose :created_on message_expose :id + message_expose :lasted_comment expose :message_children,using:Mobile::Entities::Message do |c,opt| if c.is_a? (::Message) c.children diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index 36893d16f..bf084c2f4 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -7,10 +7,17 @@ module Mobile if f.is_a?(Hash) && f.key?(field) f[field] elsif f.is_a?(::News) - if field == :created_on - format_time(f.send(field)) if f.respond_to?(field) + if f.respond_to?(field) + if field == :created_on + format_time(f.send(field)) + else + f.send(field) + end else - f.send(field) if f.respond_to?(field) + case field + when :course_name + Course.find(f.course_id).name unless f.course_id == nil + end end elsif f.is_a?(Hash) && !f.key?(field) n = f[:news] @@ -52,6 +59,8 @@ module Mobile news_expose :created_on #评论数量 news_expose :comments_count + #课程名字 + news_expose :course_name #评论 expose :comments, using: Mobile::Entities::Comment do |f, opt| if f.is_a?(Hash) && f.key?(:comments) diff --git a/app/api/mobile/entities/student_work.rb b/app/api/mobile/entities/student_work.rb index 6cf68c875..9dafdd240 100644 --- a/app/api/mobile/entities/student_work.rb +++ b/app/api/mobile/entities/student_work.rb @@ -32,14 +32,14 @@ module Mobile end end student_work_expose :student_id - student_work_expose :id + student_work_expose :id student_work_expose :name - student_work_expose :description - student_work_expose :final_score - student_work_expose :teacher_score - student_work_expose :student_score - student_work_expose :teacher_asistant_score - student_work_expose :created_at + student_work_expose :description + student_work_expose :final_score + student_work_expose :teacher_score + student_work_expose :student_score + student_work_expose :teacher_asistant_score + student_work_expose :created_at end end end \ No newline at end of file diff --git a/app/api/mobile/entities/whomework.rb b/app/api/mobile/entities/whomework.rb index 062ea61b5..562e3a1a7 100644 --- a/app/api/mobile/entities/whomework.rb +++ b/app/api/mobile/entities/whomework.rb @@ -1,66 +1,69 @@ -# encoding: utf-8 -module Mobile - module Entities - class Whomework