From c23f69464a397f27dd4518149fcf86cd9726507c Mon Sep 17 00:00:00 2001 From: Louis Matthijssen Date: Tue, 13 Jun 2023 15:16:28 +0200 Subject: [PATCH] Add pagination fields helper --- .../helpers/macro_helpers.ex | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/cose_della_vita_ex/helpers/macro_helpers.ex b/lib/cose_della_vita_ex/helpers/macro_helpers.ex index 0d12de0..45b1aa0 100644 --- a/lib/cose_della_vita_ex/helpers/macro_helpers.ex +++ b/lib/cose_della_vita_ex/helpers/macro_helpers.ex @@ -51,4 +51,24 @@ defmodule CoseDellaVitaEx.Helpers.MacroHelpers do end end end + + @doc """ + Add boilerplate for pagination (`limit` and `offset` fields). + + Types can be overriden: + + add_pagination_fields(limit_type: :small_integer) + """ + defmacro add_pagination_fields(opts \\ []) do + limit_type = Keyword.get(opts, :limit_type, :integer) + offset_type = Keyword.get(opts, :offset_type, :integer) + + quote do + @desc "Limit results to N items." + field(:limit, unquote(limit_type)) + + @desc "Skip N items." + field(:offset, unquote(offset_type)) + end + end end