Add API route for protocoin printer balance

This commit is contained in:
Tanner Collin 2023-02-20 02:38:34 +00:00
parent b8a0effbb2
commit 0f5dbee24b
2 changed files with 33 additions and 1 deletions

View File

@ -24,7 +24,7 @@ class LoggingThrottle(throttling.BaseThrottle):
return True return True
elif path == '/sessions/' and user == None: elif path == '/sessions/' and user == None:
return True return True
elif path in ['/pinball/high_scores/']: elif path in ['/pinball/high_scores/', '/protocoin/printer_balance/']:
return True return True
if request.data: if request.data:

View File

@ -1236,6 +1236,38 @@ class ProtocoinViewSet(Base):
) )
return Response(res) return Response(res)
@action(detail=False, methods=['get'])
def printer_balance(self, request, pk=None):
#auth_token = request.META.get('HTTP_AUTHORIZATION', '')
#if secrets.VEND_API_TOKEN and auth_token != 'Bearer ' + secrets.VEND_API_TOKEN:
# raise exceptions.PermissionDenied()
track = cache.get('track', {})
track_graphics_computer = track.get('PROTOGRAPH1', None)
if not track_graphics_computer:
return Response(200)
track_username = track_graphics_computer['username']
track_time = track_graphics_computer['time']
try:
source_user = User.objects.get(username__iexact=track_username)
except User.DoesNotExist:
return Response(200)
if time.time() - track_time > 10:
return Response(200)
user_balance = source_user.transactions.aggregate(Sum('protocoin'))['protocoin__sum'] or 0
user_balance = float(user_balance)
res = dict(
balance=user_balance,
first_name=source_user.member.preferred_name,
)
return Response(res)
@action(detail=True, methods=['post']) @action(detail=True, methods=['post'])
def card_vend_request(self, request, pk=None): def card_vend_request(self, request, pk=None):
try: try: