diff --git a/webhook_to_fedora_messaging/endpoints/util.py b/webhook_to_fedora_messaging/endpoints/util.py index 0650ebc..0c0f8c3 100644 --- a/webhook_to_fedora_messaging/endpoints/util.py +++ b/webhook_to_fedora_messaging/endpoints/util.py @@ -1,5 +1,6 @@ from flask import Response, Request + def not_found() -> Response: return Response({'message': 'Not Found'}, status=404, mimetype='application/json') @@ -7,14 +8,22 @@ def not_found() -> Response: def success(data: dict) ->Response: return Response(data, status=200, mimetype='application/json') + def bad_request() -> Response: return Response("{'message': 'Bad Request'}", status=400, mimetype='application/json') + def created(data: dict) -> Response: return Response(data, status=201, mimetype='application/json') + def conflict(data: dict) -> Response: return Response(data, status=409, mimetype='application/json') -def validate_request(request: Request, fields=['username']): - return all(field in request for field in fields) \ No newline at end of file + +def unprocessable_entity() -> Response: + return Response("{'message: 'Unprocessable Entity'}", status=429, mimetype="application/json") + + +def validate_request(request: dict, fields=['username']) -> bool: + return all(field in request for field in fields)