defmodule FrenzyWeb.Fervor.Paginator do import Ecto.Query def paginate(query, %{"max_id" => max_id} = params) do limit = Map.get(params, "limit", 20) from(o in query, where: o.id < ^max_id, order_by: [desc: :id]) end def paginate(query, %{"min_id" => min_id} = params) do limit = Map.get(params, "limit", 20) from(o in query, where: o.id > ^min_id, order_by: [asc: :id]) end def paginate(query, %{"since_id" => since_id} = params) do limit = Map.get(params, "limit", 20) from(o in query, where: o.id > ^since_id, order_by: [desc: :id]) end def paginate(query, _params) do from(query, order_by: [desc: :id]) end def limit(query, params) do limit = Map.get(params, "limit", 20) from(query, limit: ^limit) end end