filtrex
filtrex copied to clipboard
Create dump/1 for saving filters
A particular type of JSON format must be followed to construct a filter. However, no method currently exists to dump a filter to a JSON-encodable format that can be later re-serialized into a filter. The following should work:
import Filtrex.Type.Config
config = defconfig do
text :title
end
{:ok, filter} = Filtrex.parse_params(config, %{"title_contains" => "Buy"})
assert Filtrex.dump(filter) == %{
"filter" => %{
"type" => "all",
"conditions" => [
%{"column" => "title", "comparator" => "contains",
"value" => "Buy", "type" => "text"}
],
"sub_filters" => []
}
It also might be nice to have an Ecto type that could automatically serialize to and from a JSONB-like database field.
I Want to make a pr for this one. I hope you don't mind :)
Go for it @gen1321! I certainly don't mind. 😄