From 3c8a4ae7e4b230f97336991fa1867473097bdf77 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Fri, 2 Sep 2022 01:00:39 +0000 Subject: [PATCH] Add public protocoin transaction route --- apiserver/apiserver/api/serializers.py | 11 +++++++++++ apiserver/apiserver/api/views.py | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/apiserver/apiserver/api/serializers.py b/apiserver/apiserver/api/serializers.py index a584721..9068e49 100644 --- a/apiserver/apiserver/api/serializers.py +++ b/apiserver/apiserver/api/serializers.py @@ -28,6 +28,17 @@ class UsageSerializer(serializers.ModelSerializer): def get_first_name(self, obj): return obj.user.member.preferred_name +class ProtocoinTransactionSerializer(serializers.ModelSerializer): + class Meta: + model = models.Transaction + fields = [ + 'id', + 'date', + 'protocoin', + 'account_type', + 'category', + ] + class TransactionSerializer(serializers.ModelSerializer): # fields directly from old portal. replace with slugs we want account_type = serializers.ChoiceField([ diff --git a/apiserver/apiserver/api/views.py b/apiserver/apiserver/api/views.py index 04aa1b4..23d5a58 100644 --- a/apiserver/apiserver/api/views.py +++ b/apiserver/apiserver/api/views.py @@ -1215,6 +1215,19 @@ class ProtocoinViewSet(Base): except OperationalError: self.card_vend_request(request, pk) + @action(detail=False, methods=['get']) + def transactions(self, request): + transactions = models.Transaction.objects.exclude(protocoin=0).order_by('-date', '-id') + total_protocoin = transactions.aggregate(Sum('protocoin'))['protocoin__sum'] or 0 + + serializer = serializers.ProtocoinTransactionSerializer(transactions, many=True) + + res = dict( + total_protocoin=total_protocoin, + transactions=serializer.data, + ) + return Response(res) + class RegistrationView(RegisterView): serializer_class = serializers.MyRegisterSerializer