2019-04-08 21:07:45 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-08-21 19:56:14 +08:00
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class UserSerializer < ActiveModel::Serializer
|
2019-04-08 21:07:45 +08:00
|
|
|
type :users
|
2018-08-21 19:56:14 +08:00
|
|
|
attributes :full_name, :initials, :email
|
2019-04-30 23:03:24 +08:00
|
|
|
attribute :avatar_file_name, if: -> { object.avatar.present? }
|
|
|
|
attribute :avatar_file_size, if: -> { object.avatar.present? }
|
|
|
|
attribute :avatar_url, if: -> { object.avatar.present? }
|
|
|
|
|
|
|
|
def avatar_file_name
|
|
|
|
object.avatar_file_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def avatar_file_size
|
|
|
|
object.avatar.size
|
|
|
|
end
|
|
|
|
|
|
|
|
def avatar_url
|
|
|
|
object.avatar.url(:icon)
|
|
|
|
end
|
2018-08-21 19:56:14 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|