- params
- |> get_all_query()
- |> maybe_filter_by_date(params)
- |> maybe_filter_by_user(params)
- |> maybe_filter_by_search(params)
- |> Repo.all()
+ base_query =
+ get_all_query()
+ |> maybe_filter_by_date(params)
+ |> maybe_filter_by_user(params)
+ |> maybe_filter_by_search(params)
+
+ query_with_pagination = base_query |> paginate_query(params)
+
+ %{
+ items: Repo.all(query_with_pagination),
+ count: Repo.aggregate(base_query, :count, :id)
+ }