Add public protocoin transaction route

This commit is contained in:
Tanner Collin 2022-09-02 01:00:39 +00:00
parent 0a6e9a6449
commit 3c8a4ae7e4
2 changed files with 24 additions and 0 deletions

View File

@ -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([

View File

@ -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