Return total from pagination + tests

This commit is contained in:
Maxim Filippov 2019-09-02 22:48:52 +03:00
commit a4c5f71e93
10 changed files with 109 additions and 7 deletions

View file

@ -18,19 +18,29 @@ defmodule Pleroma.Pagination do
def fetch_paginated(query, params, :keyset) do
options = cast_params(params)
total = Repo.aggregate(query, :count, :id)
query
|> paginate(options, :keyset)
|> Repo.all()
|> enforce_order(options)
%{
total: total,
items:
query
|> paginate(options, :keyset)
|> Repo.all()
|> enforce_order(options)
}
end
def fetch_paginated(query, params, :offset) do
options = cast_params(params)
total = Repo.aggregate(query, :count, :id)
query
|> paginate(options, :offset)
|> Repo.all()
%{
total: total,
items:
query
|> paginate(options, :offset)
|> Repo.all()
}
end
def paginate(query, options, method \\ :keyset)