-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
from flask import Response, Request | ||
|
||
|
||
def not_found() -> Response: | ||
return Response({'message': 'Not Found'}, status=404, mimetype='application/json') | ||
|
||
|
||
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) | ||
|
||
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) |