2016-01-19 23:11:52 -05:00
|
|
|
class UserSummarySerializer < ApplicationSerializer
|
2016-04-20 16:58:30 -04:00
|
|
|
|
2017-10-13 16:29:56 -04:00
|
|
|
class TopicSerializer < ListableTopicSerializer
|
2017-11-27 13:18:14 -05:00
|
|
|
attributes :category_id, :like_count
|
2016-01-19 23:11:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class ReplySerializer < ApplicationSerializer
|
|
|
|
attributes :post_number, :like_count, :created_at
|
|
|
|
has_one :topic, serializer: TopicSerializer
|
|
|
|
end
|
|
|
|
|
2016-04-13 17:02:51 -04:00
|
|
|
class LinkSerializer < ApplicationSerializer
|
2016-04-20 16:58:30 -04:00
|
|
|
attributes :url, :title, :clicks, :post_number
|
|
|
|
has_one :topic, serializer: TopicSerializer
|
|
|
|
|
|
|
|
def post_number
|
|
|
|
object.post.post_number
|
|
|
|
end
|
2016-04-13 17:02:51 -04:00
|
|
|
end
|
|
|
|
|
2019-01-11 13:09:06 -05:00
|
|
|
class UserWithCountSerializer < ApplicationSerializer
|
|
|
|
attributes :id, :username, :name, :count, :avatar_template
|
|
|
|
|
2019-01-13 20:30:44 -05:00
|
|
|
def include_name?
|
|
|
|
SiteSetting.enable_names?
|
|
|
|
end
|
|
|
|
|
2019-01-11 13:09:06 -05:00
|
|
|
def avatar_template
|
|
|
|
User.avatar_template(object[:username], object[:uploaded_avatar_id])
|
|
|
|
end
|
2016-04-13 17:02:51 -04:00
|
|
|
end
|
|
|
|
|
2018-07-18 16:37:50 -04:00
|
|
|
class CategoryWithCountsSerializer < ApplicationSerializer
|
|
|
|
attributes :topic_count, :post_count,
|
|
|
|
:id, :name, :color, :text_color, :slug,
|
|
|
|
:read_restricted, :parent_category_id
|
|
|
|
end
|
|
|
|
|
2016-01-19 23:11:52 -05:00
|
|
|
has_many :topics, serializer: TopicSerializer
|
|
|
|
has_many :replies, serializer: ReplySerializer, embed: :object
|
2016-04-13 17:02:51 -04:00
|
|
|
has_many :links, serializer: LinkSerializer, embed: :object
|
2016-05-04 16:47:48 -04:00
|
|
|
has_many :most_liked_by_users, serializer: UserWithCountSerializer, embed: :object
|
|
|
|
has_many :most_liked_users, serializer: UserWithCountSerializer, embed: :object
|
|
|
|
has_many :most_replied_to_users, serializer: UserWithCountSerializer, embed: :object
|
2016-04-20 16:58:30 -04:00
|
|
|
has_many :badges, serializer: UserBadgeSerializer, embed: :object
|
2018-07-18 16:37:50 -04:00
|
|
|
has_many :top_categories, serializer: CategoryWithCountsSerializer, embed: :object
|
2016-01-19 23:11:52 -05:00
|
|
|
|
2016-03-30 12:05:16 -04:00
|
|
|
attributes :likes_given,
|
|
|
|
:likes_received,
|
2017-11-17 17:53:22 -05:00
|
|
|
:topics_entered,
|
2016-03-30 12:05:16 -04:00
|
|
|
:posts_read_count,
|
|
|
|
:days_visited,
|
|
|
|
:topic_count,
|
|
|
|
:post_count,
|
2016-04-13 17:02:51 -04:00
|
|
|
:time_read,
|
2017-11-14 16:39:07 -05:00
|
|
|
:recent_time_read,
|
2016-04-13 17:02:51 -04:00
|
|
|
:bookmark_count
|
2016-03-29 02:11:47 -04:00
|
|
|
|
|
|
|
def include_badges?
|
|
|
|
SiteSetting.enable_badges
|
|
|
|
end
|
2016-03-30 12:05:16 -04:00
|
|
|
|
2016-05-09 09:51:43 -04:00
|
|
|
def include_bookmark_count?
|
|
|
|
scope.authenticated? && object.user_id == scope.user.id
|
|
|
|
end
|
|
|
|
|
2016-03-30 12:05:16 -04:00
|
|
|
def time_read
|
2017-11-14 16:39:07 -05:00
|
|
|
object.time_read
|
|
|
|
end
|
|
|
|
|
|
|
|
def recent_time_read
|
|
|
|
object.recent_time_read
|
2016-03-30 12:05:16 -04:00
|
|
|
end
|
2016-01-19 23:11:52 -05:00
|
|
|
end
|