Created
August 27, 2020 18:56
-
-
Save mentix02/8222c556322d27ed5a82df406411091b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class FollowRequestActionAPIView(APIView): | |
""" | |
APIView to accept or reject a FollowRequest by the person | |
who is being requested to act upon said request. | |
""" | |
parser_classes = (FormParser,) | |
permission_classes = (IsAuthenticated,) | |
@staticmethod | |
def post(request: WSGIRequest) -> Response: | |
try: | |
action = request.POST['action'] | |
follow_request_id = request.POST['follow_request_id'] | |
except KeyError as field: | |
return Response( | |
{'error': f'{str(field)} not provided.'}, | |
status=status.HTTP_400_BAD_REQUEST, | |
) | |
follow_request: FollowRequest = get_object_or_404( | |
FollowRequest, id=follow_request_id | |
) | |
resp = {'detail': 'rejected'} | |
if action == '1': | |
resp['detail'] = 'accepted' | |
follow_request.accept() | |
else: | |
follow_request.reject() | |
return Response(resp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment