Skip to content

Commit

Permalink
Merge pull request #6 from weareyipyip/add-pagination-fields
Browse files Browse the repository at this point in the history
Add pagination fields helper
  • Loading branch information
LouisMT authored Jun 13, 2023
2 parents b874328 + c23f694 commit 9e915b2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/cose_della_vita_ex/helpers/macro_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9e915b2

Please sign in to comment.