diff --git a/authentication/serializers.py b/authentication/serializers.py index ad8e830a..eac73fc0 100644 --- a/authentication/serializers.py +++ b/authentication/serializers.py @@ -93,3 +93,9 @@ def get_username(self, user_profile: UserProfile): if not user_profile.username: return f"User{user_profile.pk}" return user_profile.username + + +class UserHistoryCountSerializer(serializers.Serializer): + gas_claim = serializers.IntegerField() + token_claim = serializers.IntegerField() + raffle_win = serializers.IntegerField() diff --git a/authentication/urls.py b/authentication/urls.py index 3ec01b5e..dbfd02e4 100644 --- a/authentication/urls.py +++ b/authentication/urls.py @@ -38,4 +38,5 @@ ), path("user/info/", GetProfileView.as_view(), name="get-profile-user"), path("user/sponsor/", SponsorView.as_view(), name="sponsor-user"), + path("user/history-count/", UserHistoryCountView.as_view(), name="user-history-count") ] diff --git a/authentication/views.py b/authentication/views.py index 4c668f91..9ca512f5 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -18,7 +18,7 @@ UsernameRequestSerializer, MessageResponseSerializer, ProfileSerializer, - WalletSerializer, + WalletSerializer, UserHistoryCountSerializer, ) @@ -342,6 +342,21 @@ def get_queryset(self): return Wallet.objects.filter(user_profile=self.request.user.profile) +class UserHistoryCountView(RetrieveAPIView): + permissions = [IsAuthenticated] + serializer_class = UserHistoryCountSerializer + + def get_object(self): + from faucet.models import ClaimReceipt + user_profile = self.request.user.profile + data = { + 'gas_claim': user_profile.claims.filter(_status=ClaimReceipt.VERIFIED).count(), + 'token_claim': user_profile.tokentap_claims.filter(status=ClaimReceipt.VERIFIED).count(), + 'raffle_win': user_profile.raffle_entries.count() + } + return data + + class GetProfileView(RetrieveAPIView): permission_classes = [IsAuthenticated] serializer_class = ProfileSerializer