We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I'm using an Ecto embedded_schema in order to validate pagination params being passed into the query string of my API.
However I'm wondering how can I check if a cursor is indeed valid and without having to rescue ArgumentError from Paginator.paginate/4
defp changeset(schema \\ %__MODULE__{}, params) do schema |> cast(params, @optional) |> validate_cursor() |> validate_number(:limit, greater_than: 0, message: "must be greater than 0") end defp validate_cursor(changeset) do cursor_before = get_field(changeset, :before) cursor_after = get_field(changeset, :after) case {cursor_before, cursor_after} do {nil, nil} -> changeset {_cursor_before, nil} -> changeset {nil, _cursor_after} -> changeset {_cursor_before, _cursor_after} -> changeset |> add_error(:before, "use either 'before' or 'after'") |> add_error(:after, "use either 'before' or 'after'") end end
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I'm using an Ecto embedded_schema in order to validate pagination params being passed into the query string of my API.
However I'm wondering how can I check if a cursor is indeed valid and without having to rescue ArgumentError from Paginator.paginate/4
The text was updated successfully, but these errors were encountered: