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)
|
2015-05-15 10:17:47 +08:00
|
|
|
u.send(f) unless u.user_extensions.nil?
|
2015-01-20 17:42:18 +08:00
|
|
|
else
|
|
|
|
case f
|
|
|
|
when :img_url
|
2016-09-09 08:35:08 +08:00
|
|
|
"/images/#{url_to_avatar(u)}"
|
2015-01-20 17:42:18 +08:00
|
|
|
when :gender
|
2015-04-15 10:52:10 +08:00
|
|
|
u.nil? || u.user_extensions.nil? || u.user_extensions.gender.nil? ? 0 : u.user_extensions.gender
|
2015-01-20 17:42:18 +08:00
|
|
|
when :work_unit
|
2015-05-15 10:17:47 +08:00
|
|
|
get_user_work_unit u unless u.user_extensions.nil?
|
2015-01-20 17:42:18 +08:00
|
|
|
when :location
|
2015-05-15 10:17:47 +08:00
|
|
|
get_user_location u unless u.user_extensions.nil?
|
2015-01-20 17:42:18 +08:00
|
|
|
when :brief_introduction
|
2015-04-15 10:52:10 +08:00
|
|
|
u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.brief_introduction
|
2015-07-01 16:56:03 +08:00
|
|
|
when :student_num
|
|
|
|
u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.student_id
|
2016-07-27 14:30:19 +08:00
|
|
|
when :real_name
|
|
|
|
u.nil? ? "" : get_user_realname(u).gsub(/\s*/,"");
|
2016-06-24 13:29:36 +08:00
|
|
|
when :name
|
|
|
|
u.nil? ? "" : u.show_name
|
2016-07-27 14:30:19 +08:00
|
|
|
when :roles_id
|
|
|
|
u[:roles_id].nil? ? nil : u.roles_id
|
2016-09-08 14:10:58 +08:00
|
|
|
when :login
|
|
|
|
u.login
|
|
|
|
when :lastname
|
|
|
|
u.lastname
|
|
|
|
when :mail
|
|
|
|
u.mail
|
2016-09-19 13:22:29 +08:00
|
|
|
when :is_me
|
|
|
|
defined? u.is_me ? u.is_me : 0
|
2015-01-20 17:42:18 +08:00
|
|
|
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
|
|
|
#头像
|
2016-09-08 14:10:58 +08:00
|
|
|
user_expose :login
|
|
|
|
user_expose :lastname
|
2016-09-07 14:19:07 +08:00
|
|
|
#邮箱地址
|
2016-09-08 14:10:58 +08:00
|
|
|
user_expose :mail
|
2014-12-09 16:57:08 +08:00
|
|
|
expose :nickname
|
2015-04-16 15:48:53 +08:00
|
|
|
#真名
|
2016-07-27 14:30:19 +08:00
|
|
|
user_expose :img_url
|
|
|
|
#昵称
|
|
|
|
expose :realname
|
|
|
|
#昵称
|
|
|
|
user_expose :real_name
|
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 :location
|
2014-12-09 16:36:43 +08:00
|
|
|
#签名
|
2014-12-15 14:06:00 +08:00
|
|
|
user_expose :brief_introduction
|
2015-07-01 16:56:03 +08:00
|
|
|
#总成绩
|
|
|
|
user_expose :score
|
|
|
|
#学号
|
|
|
|
user_expose :student_num
|
2015-07-07 17:18:29 +08:00
|
|
|
# 活跃值
|
|
|
|
user_expose :active_count
|
2016-06-24 13:29:36 +08:00
|
|
|
|
|
|
|
user_expose :role_name
|
|
|
|
|
2016-07-27 14:30:19 +08:00
|
|
|
user_expose :roles_id
|
|
|
|
|
2016-06-24 13:29:36 +08:00
|
|
|
user_expose :name
|
|
|
|
|
2016-09-19 13:22:29 +08:00
|
|
|
user_expose :is_me
|
|
|
|
|
2014-12-09 16:36:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|