mirror of
https://github.com/wahyd4/libr-2.git
synced 2026-08-09 05:15:53 +10:00
32 lines
591 B
Ruby
32 lines
591 B
Ruby
class UserSerializer < ActiveModel::Serializer
|
|
|
|
attributes :id, :name, :email, :avatar, :followed, :posts_count, :likes_count, :follows_count,
|
|
:followers_count,
|
|
|
|
def followed
|
|
return true if object == scope.current_user
|
|
object.followers_ids.include? scope.current_user.try(:id)
|
|
end
|
|
|
|
def posts_count
|
|
object.share_instances.count
|
|
end
|
|
|
|
def likes_count
|
|
object.likes.count
|
|
end
|
|
|
|
def follows_count
|
|
object.stars.count
|
|
end
|
|
|
|
def followers_count
|
|
FollowRelation.where(star_id: object.id).count
|
|
end
|
|
|
|
def avatar
|
|
object.avatar_url
|
|
end
|
|
|
|
|
|
end |