搜索和列表中的课程老师输出一致
This commit is contained in:
parent
8fe5fee0f0
commit
d6aadc1624
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue