module Mobile module Entities class User < Grape::Entity include ApplicationHelper include ApiHelper def self.user_expose(f) expose f do |u,opt| if u.is_a?(Hash) && u.key?(f) u[f] elsif u.is_a?(::User) if u.respond_to?(f) u.send(f) unless u.user_extensions.nil? else case f when :img_url "/images/#{url_to_avatar(u)}" when :gender u.nil? || u.user_extensions.nil? || u.user_extensions.gender.nil? ? 0 : u.user_extensions.gender when :work_unit get_user_work_unit u unless u.user_extensions.nil? when :location get_user_location u unless u.user_extensions.nil? when :brief_introduction u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.brief_introduction when :student_num u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.student_id when :real_name u.nil? ? "" : get_user_realname(u).gsub(/\s*/,""); when :name u.nil? ? "" : u.show_name when :roles_id u[:roles_id].nil? ? nil : u.roles_id when :login u.login when :lastname u.lastname when :mail u.mail when :is_me defined? u.is_me ? u.is_me : 0 end end end end end expose :id #头像 user_expose :login user_expose :lastname #邮箱地址 user_expose :mail expose :nickname #真名 user_expose :img_url #昵称 expose :realname #昵称 user_expose :real_name #性别 user_expose :gender #我的二维码 #工作单位 user_expose :work_unit #地区 user_expose :location #签名 user_expose :brief_introduction #总成绩 user_expose :score #学号 user_expose :student_num # 活跃值 user_expose :active_count user_expose :role_name user_expose :roles_id user_expose :name user_expose :is_me end end end