diff options
author | Frederick Muriuki Muriithi | 2024-09-25 18:48:07 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-09-25 18:48:33 -0500 |
commit | 1968503b6b01e8612d1d2aaedd7c1d80092ba2de (patch) | |
tree | 3a549e0c46e3f221420ac3aca9fcba7e5ea4c47a /gn_auth/auth/authorisation/resources/request_utils.py | |
parent | a3f0e670635ad4319e241ada50587af75a0a2901 (diff) | |
download | gn-auth-1968503b6b01e8612d1d2aaedd7c1d80092ba2de.tar.gz |
Implement genotype resource creation via API with resource data
Create the resource, assign the resource-owner role and link the
resource's data in a single API call.
Diffstat (limited to 'gn_auth/auth/authorisation/resources/request_utils.py')
-rw-r--r-- | gn_auth/auth/authorisation/resources/request_utils.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/gn_auth/auth/authorisation/resources/request_utils.py b/gn_auth/auth/authorisation/resources/request_utils.py new file mode 100644 index 0000000..03d3c3b --- /dev/null +++ b/gn_auth/auth/authorisation/resources/request_utils.py @@ -0,0 +1,20 @@ +"""Some common utils for requests to the resources endpoints.""" +from functools import reduce + +from pymonad.either import Left, Right, Either + +def check_form(form, *fields) -> Either: + """Check form for errors""" + def __check_field__(errors, field): + if not bool(form.get(field)): + return errors + (f"Missing `{field}` value.") + return errors + + errors = reduce(__check_field__, fields, tuple()) + if len(errors) > 0: + return Left({ + "error": "Invalid request data!", + "error_description": "\n\t - ".join(errors) + }) + + return Right(form) |