Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/dso_api/dynamic_api/filters/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,18 @@ def from_request(cls, request) -> QueryFilterEngine:
# custom query headers are passed with a DSO- prefix
raw_key = key[len(cls.HEADER_PARAMS_PREFIX) :]

# default operator will be "eq"
operator = "eq"

# split on operator if passed
parts = raw_key.rsplit(".", 1)

if len(parts) == 2:
has_operator = len(parts) == 2

if has_operator:
raw_key, operator = parts[0], parts[1].lower()

# convert query param to camelCase
query_part = raw_key.replace("-", "")
query_param = toCamelCase(query_part)
query_param = toCamelCase(raw_key.replace("-", ""))

new_key = f"{query_param}[{operator}]"
new_key = f"{query_param}[{operator}]" if has_operator else query_param

dso_headers.setlist(new_key, [value])

Expand Down
8 changes: 4 additions & 4 deletions src/tests/test_dynamic_api/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def test_dso_headers_overwrite_query(self, movies_model, movie1, movie2):
"other-header": "ignore-me",
},
{
"aantalBouwlagen[eq]": [5],
"status[eq]": ["active"],
"aantalBouwlagen": [5],
"status": ["active"],
"aantalBouwlagen[gt]": [2],
"aantalBouwlagen[lt]": [10],
"perJaarPerM2[isnull]": ["true"],
Expand All @@ -170,8 +170,8 @@ def test_dso_headers_overwrite_query(self, movies_model, movie1, movie2):
"other-header": "ignore-me",
},
{
"aantalBouwlagen[eq]": [5],
"status[eq]": ["active"],
"aantalBouwlagen": [5],
"status": ["active"],
"aantalBouwlagen[gt]": [2],
"aantalBouwlagen[lt]": [10],
},
Expand Down
Loading