diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-07-01 11:19:19 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-07-01 11:19:19 +0700 |
| commit | a54492e34db2a43d9aae2d575b2b3c073669631c (patch) | |
| tree | 409d317bed22355f844a1f9e81873ca83f2f9bd6 /indoteknik_api/controllers/controller.py | |
| parent | 53e3cacd7d32df44ce8637284c3ec16050e07e5b (diff) | |
<iman> update flash sale & get_request_params untuk boolean
Diffstat (limited to 'indoteknik_api/controllers/controller.py')
| -rw-r--r-- | indoteknik_api/controllers/controller.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/indoteknik_api/controllers/controller.py b/indoteknik_api/controllers/controller.py index 017e5c12..a5a05c1b 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) @@ -94,6 +95,13 @@ class Controller(http.Controller): result['reason'].append(f"{key} is required") if 'number' in rules and value and not value.isdigit(): result['reason'].append(f"{key} must be a number") + if is_boolean and value: + if value.lower() in ['true', '1']: + value = True + elif value.lower() in ['false', '0']: + value = False + else: + result['reason'].append(f"{key} must be a boolean") result['query'][key] = value @@ -102,13 +110,20 @@ class Controller(http.Controller): if is_number and value.isdigit(): value = int(value) + # Assign the boolean value + if is_boolean: + if value.lower() in ['true', '1']: + value = True + elif value.lower() in ['false', '0']: + value = False + if not value and is_exclude_if_null: continue result['value'][alias] = value result['valid'] = not result['reason'] - + return result def time_to_str(self, object, format): |
