socialforge/app/api/mobile/entities/course.rb

55 lines
1.4 KiB
Ruby
Raw Normal View History

2014-12-09 16:36:43 +08:00
module Mobile
module Entities
class Course < Grape::Entity
def self.course_expose(field)
expose field do |f,opt|
c = nil
2014-12-23 09:44:31 +08:00
if f.is_a? ::Course
c = f
2014-12-23 09:44:31 +08:00
else
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))
2014-12-23 09:44:31 +08:00
end
2014-12-09 16:36:43 +08:00
end
end
2014-12-23 09:44:31 +08:00
course_expose :img_url
2014-12-09 16:36:43 +08:00
course_expose :attachmenttype
course_expose :class_period
course_expose :code
course_expose :created_at
course_expose :description
course_expose :endup_time
course_expose :extra
course_expose :id
course_expose :inherit_members
course_expose :is_public
course_expose :lft
course_expose :location
course_expose :name
course_expose :open_student
# course_expose :password
course_expose :rgt
course_expose :school_id
course_expose :setup_time
course_expose :state
course_expose :status
course_expose :string
course_expose :tea_id
course_expose :term
course_expose :time
course_expose :updated_at
expose :teacher, using: Mobile::Entities::User do |c, opt|
if c.is_a? ::Course
c.teacher
else
c[:course].teacher
end
end
2014-12-09 16:36:43 +08:00
end
end
end