2020-04-01 00:09:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UserBookmarkListSerializer < ApplicationSerializer
|
2022-04-21 18:23:42 -04:00
|
|
|
attributes :more_bookmarks_url, :bookmarks
|
2020-04-01 00:09:07 -04:00
|
|
|
|
2022-04-21 18:23:42 -04:00
|
|
|
def bookmarks
|
|
|
|
if SiteSetting.use_polymorphic_bookmarks
|
|
|
|
object.bookmarks.map do |bm|
|
|
|
|
serialize_registered_type(bm)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
object.bookmarks.map { |bm| UserBookmarkSerializer.new(bm, scope: scope, root: false) }
|
|
|
|
end
|
|
|
|
end
|
2020-04-01 00:09:07 -04:00
|
|
|
|
|
|
|
def include_more_bookmarks_url?
|
2020-07-14 00:43:41 -04:00
|
|
|
@include_more_bookmarks_url ||= object.bookmarks.size == object.per_page
|
2020-04-01 00:09:07 -04:00
|
|
|
end
|
2022-04-21 18:23:42 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def serialize_registered_type(bookmark)
|
|
|
|
Bookmark.registered_bookmarkable_from_type(
|
|
|
|
bookmark.bookmarkable_type
|
|
|
|
).serializer.new(bookmark, scope: scope, root: false)
|
|
|
|
end
|
2020-04-01 00:09:07 -04:00
|
|
|
end
|