Return total from pagination + tests
This commit is contained in:
parent
6d33c89c4d
commit
a4c5f71e93
10 changed files with 109 additions and 7 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue