Skip to content

Commit

Permalink
Merge pull request #130 from UnitapApp/feature/add-user-history-count
Browse files Browse the repository at this point in the history
Add user history count
  • Loading branch information
PooyaFekri authored Dec 19, 2023
2 parents cd1e771 + c8e4747 commit c3f047f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions authentication/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
1 change: 1 addition & 0 deletions authentication/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
]
17 changes: 16 additions & 1 deletion authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
UsernameRequestSerializer,
MessageResponseSerializer,
ProfileSerializer,
WalletSerializer,
WalletSerializer, UserHistoryCountSerializer,
)


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c3f047f

Please sign in to comment.