diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index 8e5609f32..0dd0d6aeb 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -3,14 +3,17 @@ module Mobile class Course < Grape::Entity def self.course_expose(field) expose field do |f,opt| - o = nil - o = f.img_url if f.respond_to?(:img_url) + c = nil if f.is_a? ::Course - o = f.send(field) if f.respond_to?(field) + c = f else - f[:course][field] || f[:course].__send__(field) + c = f[:course] + end + if field == :img_url + f.img_url if f.respond_to?(:img_url) + else + (c[field] if (c.is_a?(Hash) && c.key?(field))) || (c.send(field) if c.respond_to?(field)) end - o end end course_expose :img_url @@ -39,7 +42,13 @@ module Mobile course_expose :term course_expose :time course_expose :updated_at - course_expose :teacher + expose :teacher, using: Mobile::Entities::User do |c, opt| + if c.is_a? ::Course + c.teacher + else + c[:course].teacher + end + end end end end