diff options
Diffstat (limited to 'indoteknik_api/controllers/controller.py')
| -rw-r--r-- | indoteknik_api/controllers/controller.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/indoteknik_api/controllers/controller.py b/indoteknik_api/controllers/controller.py index 017e5c12..a34a2688 100644 --- a/indoteknik_api/controllers/controller.py +++ b/indoteknik_api/controllers/controller.py @@ -80,9 +80,10 @@ class Controller(http.Controller): 'value': {}, 'query': {} } - + for key, rules in queries.items(): is_number = 'number' in rules + is_boolean = 'boolean' in rules is_exclude_if_null = 'exclude_if_null' in rules alias = next((r.replace('alias:', '') for r in rules if r.startswith('alias:')), key) default = next((r.replace('default:', '') for r in rules if r.startswith('default:')), None) @@ -92,8 +93,10 @@ class Controller(http.Controller): value = '' if 'required' in rules and not value: result['reason'].append(f"{key} is required") - if 'number' in rules and value and not value.isdigit(): + if is_number and value and not value.isdigit(): result['reason'].append(f"{key} must be a number") + if is_boolean and value and value.lower() not in ['true', 'false', '1', '0']: + result['reason'].append(f"{key} must be a boolean") result['query'][key] = value @@ -101,6 +104,8 @@ class Controller(http.Controller): value = default if is_number and value.isdigit(): value = int(value) + if is_boolean: + value = value.lower() in ['true', '1'] if not value and is_exclude_if_null: continue @@ -108,7 +113,7 @@ class Controller(http.Controller): result['value'][alias] = value result['valid'] = not result['reason'] - + return result def time_to_str(self, object, format): |
