2014-12-09 16:36:43 +08:00
|
|
|
module Mobile
|
|
|
|
module Entities
|
|
|
|
class User < Grape::Entity
|
2015-01-20 17:42:18 +08:00
|
|
|
include ApplicationHelper
|
|
|
|
include ApiHelper
|
2014-12-15 14:06:00 +08:00
|
|
|
def self.user_expose(f)
|
|
|
|
expose f do |u,opt|
|
2015-01-06 16:51:44 +08:00
|
|
|
if u.is_a?(Hash) && u.key?(f)
|
|
|
|
u[f]
|
2015-01-20 17:42:18 +08:00
|
|
|
elsif u.is_a?(::User)
|
|
|
|
if u.respond_to?(f)
|
|
|
|
u.send(f)
|
|
|
|
else
|
|
|
|
case f
|
|
|
|
when :img_url
|
|
|
|
url_to_avatar(u)
|
|
|
|
when :gender
|
|
|
|
u.user_extensions.gender.nil? ? 0 : u.user_extensions.gender
|
|
|
|
when :work_unit
|
|
|
|
get_user_work_unit u
|
|
|
|
when :location
|
|
|
|
get_user_location u
|
|
|
|
when :brief_introduction
|
|
|
|
u.user_extensions.brief_introduction
|
|
|
|
end
|
|
|
|
end
|
2015-01-06 16:51:44 +08:00
|
|
|
end
|
|
|
|
|
2014-12-15 14:06:00 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :id
|
2014-12-09 16:36:43 +08:00
|
|
|
#头像
|
2014-12-15 14:06:00 +08:00
|
|
|
user_expose :img_url
|
2014-12-09 16:36:43 +08:00
|
|
|
#昵称
|
2014-12-09 16:57:08 +08:00
|
|
|
expose :nickname
|
2014-12-09 16:36:43 +08:00
|
|
|
#性别
|
2014-12-15 14:06:00 +08:00
|
|
|
user_expose :gender
|
2014-12-09 16:36:43 +08:00
|
|
|
#我的二维码
|
|
|
|
#工作单位
|
2014-12-15 14:06:00 +08:00
|
|
|
user_expose :work_unit
|
2014-12-09 16:36:43 +08:00
|
|
|
#邮箱地址
|
2014-12-15 14:06:00 +08:00
|
|
|
user_expose :mail
|
2014-12-09 16:36:43 +08:00
|
|
|
#地区
|
2014-12-15 14:06:00 +08:00
|
|
|
user_expose :location
|
2014-12-09 16:36:43 +08:00
|
|
|
#签名
|
2014-12-15 14:06:00 +08:00
|
|
|
user_expose :brief_introduction
|
2014-12-09 16:36:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|