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-07-26 21:58:51 +08:00
|
|
|
attribute :avatar_file_name, if: -> { object.avatar.attached? }
|
|
|
|
attribute :avatar_file_size, if: -> { object.avatar.attached? }
|
|
|
|
attribute :avatar_url, if: -> { object.avatar.attached? }
|
2019-04-30 23:03:24 +08:00
|
|
|
|
|
|
|
def avatar_file_name
|
2019-07-26 21:58:51 +08:00
|
|
|
object.avatar.blob.filename
|
2019-04-30 23:03:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def avatar_file_size
|
2019-07-26 21:58:51 +08:00
|
|
|
object.avatar.blob.byte_size
|
2019-04-30 23:03:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def avatar_url
|
2019-07-26 21:58:51 +08:00
|
|
|
object.avatar_url(:icon)
|
2019-04-30 23:03:24 +08:00
|
|
|
end
|
2018-08-21 19:56:14 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|