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:
parent
3af52f2829
commit
ae07e3efc2
2 changed files with 36 additions and 0 deletions
|
|
@ -22,6 +22,10 @@ defmodule Mv.Constants do
|
|||
|
||||
@boolean_filter_prefix "bf_"
|
||||
|
||||
@group_filter_prefix "group_"
|
||||
|
||||
@fee_type_filter_prefix "fee_type_"
|
||||
|
||||
@max_boolean_filters 50
|
||||
|
||||
@max_uuid_length 36
|
||||
|
|
@ -70,6 +74,16 @@ defmodule Mv.Constants do
|
|||
"""
|
||||
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 """
|
||||
Returns the maximum number of boolean custom field filters allowed per request.
|
||||
|
||||
|
|
|
|||
22
lib/mv_web/live/member_live/index/filter_params.ex
Normal file
22
lib/mv_web/live/member_live/index/filter_params.ex
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue