pagination.ex: Drop atom keys in params

Atom keys could also have been transformed to string, or the other
way around but this one is more efficient and what we actually
expect with the current param_types in Pagination
This commit is contained in:
Haelwenn (lanodan) Monnier 2019-03-26 00:07:33 +01:00
parent 6f15224053
commit e83ad12c57
No known key found for this signature in database
GPG Key ID: D5B7A8E43C997DEE
1 changed files with 6 additions and 0 deletions

View File

@ -36,6 +36,12 @@ defp cast_params(params) do
limit: :integer limit: :integer
} }
params =
Enum.reduce(params, %{}, fn
{key, _value}, acc when is_atom(key) -> Map.drop(acc, [key])
{key, value}, acc -> Map.put(acc, key, value)
end)
changeset = cast({%{}, param_types}, params, Map.keys(param_types)) changeset = cast({%{}, param_types}, params, Map.keys(param_types))
changeset.changes changeset.changes
end end