mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-05 13:35:23 +02:00
feat: Query Filter Builder for Cookbooks and Meal Plans (#4346)
This commit is contained in:
parent
2a9a6fa5e6
commit
b8e62ab8dd
47 changed files with 2043 additions and 440 deletions
|
@ -0,0 +1,62 @@
|
|||
from mealie.schema.response.query_filter import (
|
||||
LogicalOperator,
|
||||
QueryFilterBuilder,
|
||||
QueryFilterJSON,
|
||||
QueryFilterJSONPart,
|
||||
RelationalKeyword,
|
||||
RelationalOperator,
|
||||
)
|
||||
|
||||
|
||||
def test_query_filter_builder_json():
|
||||
qf = (
|
||||
'(( (name = "my-recipe") AND is_active = TRUE) AND tags.name CONTAINS ALL ["tag1","tag2"]) '
|
||||
'OR (name="my-other-recipe" AND (count=1 OR count=2) )'
|
||||
)
|
||||
builder = QueryFilterBuilder(qf)
|
||||
assert builder.as_json_model() == QueryFilterJSON(
|
||||
parts=[
|
||||
QueryFilterJSONPart(
|
||||
left_parenthesis="(((",
|
||||
attribute_name="name",
|
||||
relational_operator=RelationalOperator.EQ,
|
||||
value="my-recipe",
|
||||
right_parenthesis=")",
|
||||
),
|
||||
QueryFilterJSONPart(
|
||||
logical_operator=LogicalOperator.AND,
|
||||
attribute_name="is_active",
|
||||
relational_operator=RelationalOperator.EQ,
|
||||
value="TRUE",
|
||||
right_parenthesis=")",
|
||||
),
|
||||
QueryFilterJSONPart(
|
||||
logical_operator=LogicalOperator.AND,
|
||||
attribute_name="tags.name",
|
||||
relational_operator=RelationalKeyword.CONTAINS_ALL,
|
||||
value=["tag1", "tag2"],
|
||||
right_parenthesis=")",
|
||||
),
|
||||
QueryFilterJSONPart(
|
||||
logical_operator=LogicalOperator.OR,
|
||||
left_parenthesis="(",
|
||||
attribute_name="name",
|
||||
relational_operator=RelationalOperator.EQ,
|
||||
value="my-other-recipe",
|
||||
),
|
||||
QueryFilterJSONPart(
|
||||
logical_operator=LogicalOperator.AND,
|
||||
left_parenthesis="(",
|
||||
attribute_name="count",
|
||||
relational_operator=RelationalOperator.EQ,
|
||||
value="1",
|
||||
),
|
||||
QueryFilterJSONPart(
|
||||
logical_operator=LogicalOperator.OR,
|
||||
attribute_name="count",
|
||||
relational_operator=RelationalOperator.EQ,
|
||||
value="2",
|
||||
right_parenthesis="))",
|
||||
),
|
||||
]
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue