-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started replacing Response with new APIResponse to prefill metadata w…
…hen we add it (#517) Signed-off-by: Trey <[email protected]>
- Loading branch information
Showing
4 changed files
with
32 additions
and
6 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
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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from rest_framework.response import Response | ||
|
||
|
||
def APIResponse(success: bool = True, data: str | dict | None = None, meta=None, status: int = 0, **kwargs) -> Response: | ||
""" | ||
Returns a rest_framework Response object, but prefills meta (success etc) aswell as the data with KWARGS. | ||
""" | ||
meta = meta or {} | ||
if not status and success: | ||
status = 201 | ||
elif not status: | ||
status = 400 | ||
|
||
if success: | ||
return Response({"meta": {"success": True, **meta}, "data": {**data, **kwargs}}, status=status) | ||
else: | ||
return Response({"meta": {"success": False}, "error": data}, status=status) |
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