2020-04-01 12:09:07 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UserBookmarkList
|
|
|
|
include ActiveModel::Serialization
|
|
|
|
|
|
|
|
PER_PAGE = 20
|
|
|
|
|
2021-01-19 06:53:49 +08:00
|
|
|
attr_reader :bookmarks, :per_page
|
2022-08-08 22:24:04 +08:00
|
|
|
attr_accessor :more_bookmarks_url, :bookmark_serializer_opts
|
2020-04-01 12:09:07 +08:00
|
|
|
|
2020-04-01 13:04:04 +08:00
|
|
|
def initialize(user:, guardian:, params:)
|
2020-04-01 12:09:07 +08:00
|
|
|
@user = user
|
|
|
|
@guardian = guardian
|
2021-01-19 06:53:49 +08:00
|
|
|
@params = params
|
|
|
|
|
|
|
|
@params.merge!(per_page: PER_PAGE) if params[:per_page].blank?
|
|
|
|
@params[:per_page] = PER_PAGE if @params[:per_page] > PER_PAGE
|
|
|
|
|
2020-04-01 12:09:07 +08:00
|
|
|
@bookmarks = []
|
2022-08-08 22:24:04 +08:00
|
|
|
@bookmark_serializer_opts = {}
|
2020-04-01 12:09:07 +08:00
|
|
|
end
|
|
|
|
|
2022-08-08 22:24:04 +08:00
|
|
|
def load(&blk)
|
|
|
|
@bookmarks = BookmarkQuery.new(user: @user, guardian: @guardian, params: @params).list_all(&blk)
|
2020-04-01 12:09:07 +08:00
|
|
|
@bookmarks
|
|
|
|
end
|
|
|
|
|
|
|
|
def per_page
|
2021-01-19 06:53:49 +08:00
|
|
|
@per_page ||= @params[:per_page]
|
2020-04-01 12:09:07 +08:00
|
|
|
end
|
|
|
|
end
|