diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index ec00579ce..977c32c48 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -1,6 +1,7 @@ module Mobile module Entities class Course < Grape::Entity + include Redmine::I18n def self.course_expose(field) expose field do |f,opt| c = nil @@ -12,6 +13,8 @@ module Mobile if field == :img_url f[field] if f.is_a?(Hash) && f.key?(field) #f.img_url if f.respond_to?(:img_url) + elsif field == :created_at || field == :updated_at + (format_time(c[field]) if (c.is_a?(Hash) && c.key?(field))) || (format_time(c.send(field)) if c.respond_to?(field)) else (c[field] if (c.is_a?(Hash) && c.key?(field))) || (c.send(field) if c.respond_to?(field)) end diff --git a/app/api/mobile/entities/homework_jours.rb b/app/api/mobile/entities/homework_jours.rb index 63c6997fd..0b9defe67 100644 --- a/app/api/mobile/entities/homework_jours.rb +++ b/app/api/mobile/entities/homework_jours.rb @@ -6,7 +6,11 @@ module Mobile def self.homework_jours_expose(field) expose field do |f,opt| if f.is_a?(Hash) && f.key?(field) - f[field] + if field == :created_at + format_time(f[field]) + else + f[field] + end elsif f.is_a?(::SeemsRateableRates) end diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index 406db59e4..f189771e3 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -1,6 +1,7 @@ module Mobile module Entities class News < Grape::Entity + include Redmine::I18n def self.news_expose(field) expose field do |f,opt| if f.is_a?(Hash) && f.key?(field) @@ -9,13 +10,18 @@ module Mobile n = f[:news] comments = f[:comments] if n.is_a?(::News) - n.send(field) if n.respond_to?(field) + if field == :created_on + format_time(n.send(field)) if n.respond_to?(field) + else + n.send(field) if n.respond_to?(field) + end + end end end end - + news_expose :id #新闻标题 news_expose :title diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index f4201774a..7ed8fe65a 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -117,7 +117,7 @@ class CoursesService scope = @course ? @course.news.course_visible(current_user) : News.course_visible(current_user) news = [] scope.each do |n| - news << {:title => n.title,:author_name => n.author.name,:author_id => n.author.id, :description => n.description,:created_on => format_time(n.created_on),:comments_count => n.comments_count} + news << {:id => n.id,:title => n.title,:author_name => n.author.name,:author_id => n.author.id, :description => n.description,:created_on => format_time(n.created_on),:comments_count => n.comments_count} end news end