Ejemplo n.º 1
0
    def get(self, request, **kwargs):
        """
        Returns the list of all transactions of current user
        """

        try:
            identifier = request.META.get('HTTP_AUTHORIZATION')
            identifier = identifier.split(' ')[1] if identifier else request.GET.get('identifier')
            token = AccessToken.objects.get(token=identifier)
            user = token.user

            # Retrieve associated transactions to user
            user_transactions = Transaction.get_approved_user_transactions(user)
            swapping_history = {'history': [transaction.to_dict() for transaction in user_transactions]}

            return Response(swapping_history, status=status.HTTP_200_OK)
        except AccessToken.DoesNotExist:
            return Response("Access Token is invalid", status=status.HTTP_400_BAD_REQUEST)