Add filter prefix constants and shared FilterParams module

- Mv.Constants: group_filter_prefix/0, fee_type_filter_prefix/0
- MvWeb.MemberLive.Index.FilterParams: parse_in_not_in_value/1 for URL param parsing
This commit is contained in:
Moritz 2026-03-09 14:28:31 +01:00
parent 5ab73aada6
commit 2a07ddef80
Signed by: moritz
GPG key ID: 1020A035E5DD0824
2 changed files with 36 additions and 0 deletions

View file

@ -22,6 +22,10 @@ defmodule Mv.Constants do
@boolean_filter_prefix "bf_" @boolean_filter_prefix "bf_"
@group_filter_prefix "group_"
@fee_type_filter_prefix "fee_type_"
@max_boolean_filters 50 @max_boolean_filters 50
@max_uuid_length 36 @max_uuid_length 36
@ -70,6 +74,16 @@ defmodule Mv.Constants do
""" """
def boolean_filter_prefix, do: @boolean_filter_prefix def boolean_filter_prefix, do: @boolean_filter_prefix
@doc """
Returns the prefix for group filter URL parameters (e.g. group_<uuid>=in|not_in).
"""
def group_filter_prefix, do: @group_filter_prefix
@doc """
Returns the prefix for fee type filter URL parameters (e.g. fee_type_<uuid>=in|not_in).
"""
def fee_type_filter_prefix, do: @fee_type_filter_prefix
@doc """ @doc """
Returns the maximum number of boolean custom field filters allowed per request. Returns the maximum number of boolean custom field filters allowed per request.

View file

@ -0,0 +1,22 @@
defmodule MvWeb.MemberLive.Index.FilterParams do
@moduledoc """
Shared parsing helpers for member list filter URL/params (in/not_in style).
Used by MemberLive.Index and MemberFilterComponent to avoid duplication and recursion bugs.
"""
@doc """
Parses a value for group or fee-type filter params.
Returns `:in`, `:not_in`, or `nil`. Handles trimmed strings; no recursion.
"""
def parse_in_not_in_value("in"), do: :in
def parse_in_not_in_value("not_in"), do: :not_in
def parse_in_not_in_value(val) when is_binary(val) do
case String.trim(val) do
"in" -> :in
"not_in" -> :not_in
_ -> nil
end
end
def parse_in_not_in_value(_), do: nil
end