From 416dee2d30dfa47163df72a13e1136537aebe00d Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Tue, 30 Jun 2015 15:17:22 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=8A=A8=E6=80=81=20api?= =?UTF-8?q?=E6=94=B9=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/entities/course_dynamic.rb | 39 +++----------- app/api/mobile/entities/homework.rb | 12 ++++- app/api/mobile/entities/news.rb | 10 +++- app/helpers/api_helper.rb | 42 +++++++++++++++ app/services/courses_service.rb | 65 +++++++---------------- 5 files changed, 85 insertions(+), 83 deletions(-) diff --git a/app/api/mobile/entities/course_dynamic.rb b/app/api/mobile/entities/course_dynamic.rb index f086f1dd1..221870cd4 100644 --- a/app/api/mobile/entities/course_dynamic.rb +++ b/app/api/mobile/entities/course_dynamic.rb @@ -38,30 +38,6 @@ module Mobile end end obj - elsif field == :homework_submit_num - obj = nil - c[:dynamics].each do |d| - if d[:type] == 4 - obj = d[:submit_count] - end - end - obj - elsif field == :homework_submit_students - obj = nil - c[:dynamics].each do |d| - if d[:type] == 4 - obj = d[:studentlist] - end - end - obj - elsif field == :homework_status - obj = nil - c[:dynamics].each do |d| - if d[:type] == 4 - obj = d[:homework_status] - end - end - obj else c[field] if (c.is_a?(Hash) && c.key?(field)) end @@ -82,11 +58,8 @@ module Mobile course_dynamic_expose :document_count course_dynamic_expose :topic_count course_dynamic_expose :homework_count - course_dynamic_expose :homework_submit_students - course_dynamic_expose :homework_submit_num - course_dynamic_expose :homework_status #在dynamics里解析出四种动态 - expose :document,using:Mobile::Entities::Attachment do |f,opt| + expose :documents,using:Mobile::Entities::Attachment do |f,opt| obj = nil f[:dynamics].each do |d| if d[:type] == 3 @@ -95,20 +68,20 @@ module Mobile end obj end - expose :topic,using:Mobile::Entities::Message do |f,opt| + expose :topics,using:Mobile::Entities::Message do |f,opt| obj = nil f[:dynamics].each do |d| if d[:type] == 2 - obj = d[:topic] + obj = d[:topics] end end obj end - expose :homework,using:Mobile::Entities::Homework do |f,opt| + expose :homeworks,using:Mobile::Entities::Homework do |f,opt| obj = nil f[:dynamics].each do |d| if d[:type] == 4 - obj = d[:homework] + obj = d[:homeworks] end end obj @@ -118,7 +91,7 @@ module Mobile obj = nil f[:dynamics].each do |d| if d[:type] == 1 - obj = d + obj = d[:news] end end obj diff --git a/app/api/mobile/entities/homework.rb b/app/api/mobile/entities/homework.rb index e2c181048..9ee89430a 100644 --- a/app/api/mobile/entities/homework.rb +++ b/app/api/mobile/entities/homework.rb @@ -3,6 +3,8 @@ module Mobile module Entities class Homework < Grape::Entity include Redmine::I18n + include ApplicationHelper + include ApiHelper def self.homework_expose(field) expose field do |f,opt| if f.is_a?(Hash) && f.key?(field) @@ -20,6 +22,10 @@ module Mobile f.send(:name) when :homework_notsubmit_num f.course.members.count - f.student_works.count + when :homework_submit_num + f.student_works.count + when :homework_status + get_homework_status f end end end @@ -66,11 +72,13 @@ module Mobile f[:homework_for_anonymous_comments] if f.is_a?(Hash) && f.key?(:homework_for_anonymous_comments) end + homework_expose :homework_submit_num homework_expose :homework_notsubmit_num - expose :submit_student_list ,using:Mobile::Entities::User do |f,opt| - f[:studentlist] + expose :submit_student_list ,using: Mobile::Entities::User do |f,opt| + get_submit_sutdent_list f end + homework_expose :homework_status end end diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index 7399ebb4c..fe0291e68 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -6,6 +6,12 @@ module Mobile expose field do |f,opt| 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) + else + f.send(field) if f.respond_to?(field) + end elsif f.is_a?(Hash) && !f.key?(field) n = f[:news] comments = f[:comments] @@ -26,8 +32,8 @@ module Mobile news_expose :title expose :author,using: Mobile::Entities::User do |f, opt| - n = f[:author] - #n.author if n.respond_to?(:author) + #n = f[:author] + f.author if f.respond_to?(:author) end #作者id news_expose :author_id diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb index afdc306a4..916383b05 100644 --- a/app/helpers/api_helper.rb +++ b/app/helpers/api_helper.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 module ApiHelper #获取用户的工作单位 def get_user_work_unit user @@ -64,4 +65,45 @@ module ApiHelper def get_user_language user (user.language.nil? || user.language == "") ? 'zh':user.language end + + # 获取课程作业的状态 + def get_homework_status homework + homework_status = "" + if !homework.nil? + if homework.homework_type == 1 && homework.homework_detail_manual + case homework.homework_detail_manual.comment_status + when 1 + homework_status = show_homework_deadline homework + when 2 + homework_status = "正在匿评中" + when 3 + homework_status = "匿评已结束" + end + elsif homework.homework_type == 0 + homework_status = "未启用匿评" + elsif homework.homework_type == 2 + homework_status = "编程作业" + else + end + end + homework_status + end + + #获取 + def get_submit_sutdent_list homework + studentlist = [] + if homework.is_a?(Hash) && homework.key?(:studentlist) + studentlist = homework[:studentlist] + else + homework.student_works.order("created_at desc").page(1).per(6).each do |work| + studentlist << work.user + end + end + studentlist + end + + #计算作业的截止日期,剩余日期 + def show_homework_deadline homework + "距作业截止还有" << (Date.parse(Time.now.to_s) - Date.parse(homework.end_time.to_s)).to_i.to_s << "天" + end end \ No newline at end of file diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index f5ff2670f..fbdaee7cf 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -120,7 +120,7 @@ class CoursesService if current_user.nil? || !(current_user.admin? || @course.is_public == 1 || (@course.is_public == 0 && current_user.member_of_course?(@course))) raise '403' end - scope = @course ? @course.news.course_visible(current_user) : News.course_visible(current_user) + scope = @course ? @course.news.order("news.created_on desc").course_visible(current_user) : News.order("news.created_on desc").course_visible(current_user) news = [] scope.each do |n| news << {:id => n.id,:title => n.title,:author_name => n.author.name,:author_id => n.author.id, :author=>n.author, :description => n.description,:created_on => format_time(n.created_on),:comments_count => n.comments_count} @@ -330,7 +330,7 @@ class CoursesService def homework_list params,current_user course = Course.find(params[:id]) if course.is_public != 0 || current_user.member_of_course?(course) - bids = course.homework_commons.page(1).per(3).order('created_at DESC') + bids = course.homework_commons.page(1).per(20).order('created_at DESC') bids = bids.like(params[:name]) if params[:name].present? homeworks = [] bids.each do |bid| @@ -665,58 +665,35 @@ class CoursesService course = mp.course latest_course_dynamics = [] dynamics_count = 0 + # 课程学霸 学生总分数排名靠前的5个人 + # 课程通知 - latest_news = course.news.order("created_on desc").first - unless latest_news.nil? - latest_course_dynamics << {:type => 1, :time => latest_news.created_on,:count=>course.news.count, - :news => latest_news} + latest_news = course.news.page(1).per(2).order("created_on desc") + unless latest_news.first.nil? + latest_course_dynamics << {:type => 1, :time => latest_news.first.created_on,:count=>course.news.count, + :news => latest_news.all} dynamics_count += 1 end # 课程讨论区 - latest_message = course.boards.first.topics[0] - unless latest_message.nil? - latest_course_dynamics << {:type => 2, :time => latest_message.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count, - :topic => latest_message} + latest_message = course.boards.first.topics.page(1).per(2) + unless latest_message.first.nil? + latest_course_dynamics << {:type => 2, :time => latest_message.first.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count, + :topics => latest_message.all} dynamics_count += 1 end # 课程资源 - latest_attachment = course.attachments.order("created_on desc").first - unless latest_attachment.nil? - latest_course_dynamics << {:type => 3, :time => latest_attachment.created_on,:count =>course.attachments.count , :documents=>latest_attachment} + latest_attachment = course.attachments.order("created_on desc").page(1).per(2) + unless latest_attachment.first.nil? + latest_course_dynamics << {:type => 3, :time => latest_attachment.first.created_on,:count =>course.attachments.count , :documents=>latest_attachment} dynamics_count += 1 end #课程作业 已经交的学生列表(暂定显示6人),未交的学生列表,作业的状态 - homework = course.homework_commons.order('created_at desc').first - homework_status = ""; - # 判断作业所处的状态,如果是刚发布,就获取剩余时间 - #如果是匿评状态,显示正在匿评 - #如果是匿评结束,显示匿评结束 - #获取作业提交的前6个人,不足6个显示所有 - studentlist = [] - if !homework.nil? - if homework.homework_type == 1 && homework.homework_detail_manual - case homework.homework_detail_manual.comment_status - when 1 - homework_status = show_homework_deadline homework - when 2 - homework_status = "正在匿评中" - when 3 - homework_status = "匿评已结束" - end - elsif homework.homework_type == 0 - homework_status = "未启用匿评" - elsif homework.homework_type == 2 - homework_status = "编程作业" - else - end - # 获取提交作业的前六个学生的名字 和 头像路径 - homework.student_works.order("created_at desc").page(1).per(6).each do |work| - studentlist << {:image_url=> url_to_avatar(work.user),:user_name=>work.user.realname} - end - latest_course_dynamics << {:type => 4, :time => homework.updated_at, :count=>course.homework_commons.count,:submit_count => homework.student_works.count , :homework => homework, :homework_status => homework_status, :studentlist => studentlist} + homeworks = course.homework_commons.page(1).per(2).order('created_at desc') + unless homeworks.first.nil? + latest_course_dynamics << {:type => 4, :time => homeworks.first.updated_at, :count=>course.homework_commons.count , :homeworks => homeworks} dynamics_count += 1 end latest_course_dynamics.sort! { |order, newer| newer[:time] <=> order[:time] } @@ -730,9 +707,5 @@ class CoursesService result end - #计算作业的截止日期,剩余日期 - def show_homework_deadline homework - "距作业截止还有" << (Date.parse(Time.now.to_s) - Date.parse(homework.end_time.to_s)).to_i.to_s << "天" - end - end +end From 664770c63f89efabcb6487550dbc5e1bdacfabff Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Wed, 1 Jul 2015 16:56:03 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=8A=A8=E6=80=81api?= =?UTF-8?q?=E6=94=B9=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 查看学生作业总平均分列表 --- app/api/mobile/apis/courses.rb | 12 ++++++++++++ app/api/mobile/entities/course_dynamic.rb | 10 ++++++++++ app/api/mobile/entities/user.rb | 6 ++++++ app/services/courses_service.rb | 17 ++++++++++++++++- 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index c325639f9..4b574cc11 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -311,6 +311,18 @@ module Mobile present :data,news,with:Mobile::Entities::News present :status,0 end + + desc '课程历次作业总成绩列表' + params do + requires :token,type:String + requires :course_id,type:Integer,desc:'课程id' + optional :page,type:Integer,desc:'页码' + end + get ':course_id/students_score_list' do + cs = CoursesService.new + news = cs.students_score_list params,current_user + present :data,news,with:Mobile::Entities::User + end end end end diff --git a/app/api/mobile/entities/course_dynamic.rb b/app/api/mobile/entities/course_dynamic.rb index 221870cd4..46ab5b272 100644 --- a/app/api/mobile/entities/course_dynamic.rb +++ b/app/api/mobile/entities/course_dynamic.rb @@ -97,6 +97,16 @@ module Mobile obj end + expose :better_students,using:Mobile::Entities::User do |f,opt| + obj = nil + f[:dynamics].each do |d| + if d[:type] == 6 + obj = d[:better_students] + end + end + obj + end + end end end \ No newline at end of file diff --git a/app/api/mobile/entities/user.rb b/app/api/mobile/entities/user.rb index aee687dc9..2b3483625 100644 --- a/app/api/mobile/entities/user.rb +++ b/app/api/mobile/entities/user.rb @@ -22,6 +22,8 @@ module Mobile get_user_location u unless u.user_extensions.nil? when :brief_introduction u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.brief_introduction + when :student_num + u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.student_id end end end @@ -47,6 +49,10 @@ module Mobile user_expose :location #签名 user_expose :brief_introduction + #总成绩 + user_expose :score + #学号 + user_expose :student_num end end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index fbdaee7cf..339d9a92d 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -666,7 +666,13 @@ class CoursesService latest_course_dynamics = [] dynamics_count = 0 # 课程学霸 学生总分数排名靠前的5个人 - + homework_count = course.homework_commons.count + unless homework_count == 0 + sql = "select users.*,sum(IFNULL(0,student_works.final_score))/#{homework_count} score from student_works left outer join users on student_works.user_id = users.id" << + " where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{course.id}) GROUP BY student_works.user_id ORDER BY score limit 0,5" + latest_course_dynamics <<{:type=> 6,:time=>Time.now.to_s,:count=> 5,:better_students=> User.find_by_sql(sql)} + dynamics_count += 1 + end # 课程通知 latest_news = course.news.page(1).per(2).order("created_on desc") unless latest_news.first.nil? @@ -707,5 +713,14 @@ class CoursesService result end + # 获取课程历次作业的学生总成绩 + def students_score_list params,current_user + homework_count = Course.find(params[:course_id]).homework_commons.count + page = (params[:page] || 1) - 1 + sql = "select users.*,sum(IFNULL(0,student_works.final_score))/#{homework_count} score from student_works left outer join users on student_works.user_id = users.id" << + " where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{params[:course_id]}) GROUP BY student_works.user_id ORDER BY score limit #{page*10},10" + User.find_by_sql(sql) + end + end From 9eab8b92ca8798536b76a0924e95dbe59ff6e049 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Thu, 2 Jul 2015 17:31:30 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=8A=A8=E6=80=81=20api=20=E9=9A=90?= =?UTF-8?q?=E8=97=8F=20=E8=B5=84=E6=BA=90=20=E8=AE=A8=E8=AE=BA=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/courses.rb | 13 +++++++ app/api/mobile/entities/homework.rb | 2 ++ app/services/courses_service.rb | 56 ++++++++++++++++++++++------- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 4b574cc11..0d34cecaf 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -323,6 +323,19 @@ module Mobile news = cs.students_score_list params,current_user present :data,news,with:Mobile::Entities::User end + + desc '课程某次作业提交列表 并显示成绩' + params do + requires :token,type:String + requires :course_id,type:Integer,desc:'课程id' + requires :homework_id,type:Integer,desc:'作业id' + optional :page,type:Integer,desc:'页码' + end + get ':course_id/student_works_list' do + cs = CoursesService.new + student_works = cs.student_work_list params,current_user + present :data,student_works.all,with:Mobile::Entities::StudentWork + end end end end diff --git a/app/api/mobile/entities/homework.rb b/app/api/mobile/entities/homework.rb index 9ee89430a..2ea9404b8 100644 --- a/app/api/mobile/entities/homework.rb +++ b/app/api/mobile/entities/homework.rb @@ -26,6 +26,8 @@ module Mobile f.student_works.count when :homework_status get_homework_status f + when :homework_times + f.course.homework_commons.index(f) + 1 end end end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 339d9a92d..faca0738a 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -669,8 +669,8 @@ class CoursesService homework_count = course.homework_commons.count unless homework_count == 0 sql = "select users.*,sum(IFNULL(0,student_works.final_score))/#{homework_count} score from student_works left outer join users on student_works.user_id = users.id" << - " where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{course.id}) GROUP BY student_works.user_id ORDER BY score limit 0,5" - latest_course_dynamics <<{:type=> 6,:time=>Time.now.to_s,:count=> 5,:better_students=> User.find_by_sql(sql)} + " where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{course.id}) GROUP BY student_works.user_id ORDER BY score limit 0,6" + latest_course_dynamics <<{:type=> 6,:time=>Time.now.to_s,:count=> 6,:better_students=> User.find_by_sql(sql)} dynamics_count += 1 end # 课程通知 @@ -682,19 +682,19 @@ class CoursesService end # 课程讨论区 - latest_message = course.boards.first.topics.page(1).per(2) - unless latest_message.first.nil? - latest_course_dynamics << {:type => 2, :time => latest_message.first.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count, - :topics => latest_message.all} - dynamics_count += 1 - end + # latest_message = course.boards.first.topics.page(1).per(2) + # unless latest_message.first.nil? + # latest_course_dynamics << {:type => 2, :time => latest_message.first.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count, + # :topics => latest_message.all} + # dynamics_count += 1 + # end # 课程资源 - latest_attachment = course.attachments.order("created_on desc").page(1).per(2) - unless latest_attachment.first.nil? - latest_course_dynamics << {:type => 3, :time => latest_attachment.first.created_on,:count =>course.attachments.count , :documents=>latest_attachment} - dynamics_count += 1 - end + # latest_attachment = course.attachments.order("created_on desc").page(1).per(2) + # unless latest_attachment.first.nil? + # latest_course_dynamics << {:type => 3, :time => latest_attachment.first.created_on,:count =>course.attachments.count , :documents=>latest_attachment} + # dynamics_count += 1 + # end #课程作业 已经交的学生列表(暂定显示6人),未交的学生列表,作业的状态 homeworks = course.homework_commons.page(1).per(2).order('created_at desc') @@ -722,5 +722,35 @@ class CoursesService User.find_by_sql(sql) end + # 获取某次作业的所有作业列表 + def student_work_list params,current_user + is_teacher = User.current.allowed_to?(:as_teacher,Course.find(params[:course_id])) + homework = HomeworkCommon.find(params[:homework_id]) + student_works = [] + #老师 || 非匿评作业 || 匿评结束 显示所有的作品 + show_all = is_teacher || homework.homework_type != 1 || homework.homework_detail_manual.comment_status == 3 + if show_all + if homework.homework_type == 1 || is_teacher || current_user.admin? + student_works = homework.student_works.page(params[:page] || 1).per(10).order("final_score desc ") + else + my_work = homework.student_works.where(:user_id => current_user.id) + if my_work.empty? + student_works = [] + else + student_works = homework.student_works.page(params[:page] || 1).per(10).order("final_score desc") + end + end + else #学生 + if homework.homework_detail_manual.comment_status == 1 #未开启匿评,只显示我的作品 + student_works = homework.student_works.where(:user_id => current_user.id).page(params[:page] || 1).per(10) + elsif homework.homework_detail_manual.comment_status == 2 #匿评列表,显示匿评作品和我的作品 + #is_evaluation = true + my_work = homework.student_works.where(:user_id => current_user.id).page(params[:page] || 1).per(10) + student_works = my_work + current_user.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == homework.id} + end + end + student_works + end + end From 426d382ee5313466d30d22e3164224dfb7c6d41d Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Thu, 2 Jul 2015 17:32:36 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/entities/student_work.rb | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 app/api/mobile/entities/student_work.rb diff --git a/app/api/mobile/entities/student_work.rb b/app/api/mobile/entities/student_work.rb new file mode 100644 index 000000000..6cf68c875 --- /dev/null +++ b/app/api/mobile/entities/student_work.rb @@ -0,0 +1,45 @@ +module Mobile + module Entities + class StudentWork < Grape::Entity + include ApplicationHelper + include ApiHelper + def self.student_work_expose(f) + expose f do |u,opt| + if u.is_a?(Hash) && u.key?(f) + u[f] + elsif u.is_a?(::StudentWork) + if u.respond_to?(f) + if f == :created_at + format_time(u.send(:created_at)) + else + u.send(f) + end + + else + case f + when :student_id + u.user.user_extensions.student_id + end + end + end + + end + end + + expose :user, using: Mobile::Entities::User do |c, opt| + if c.is_a?(::StudentWork) + c.user + end + end + student_work_expose :student_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 + end + end +end \ No newline at end of file From 662fc02a805a31736448b9c14e489d07d713e94e Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Fri, 3 Jul 2015 09:44:26 +0800 Subject: [PATCH 5/5] =?UTF-8?q?news=20author=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/entities/news.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index fe0291e68..5ed3958ba 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -32,8 +32,13 @@ module Mobile news_expose :title expose :author,using: Mobile::Entities::User do |f, opt| - #n = f[:author] - f.author if f.respond_to?(:author) + obj = nil + if f.is_a?(::News) && f.respond_to?(:author) + obj = f.send(:author) + elsif f.is_a?(Hash) && f.key?(:author) + obj = f[:author] + end + obj end #作者id news_expose :author_id