Skip to content

Commit

Permalink
endpoint for user upvoted lists, add pairs to vote
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometheo committed Oct 3, 2024
1 parent 7518252 commit 34a5a5e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
5 changes: 2 additions & 3 deletions grantpicks/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@
PaginatedProjectsResponseSerializer,
PaginatedRoundApplicationsResponseSerializer,
PaginatedRoundsResponseSerializer,
PaginatedVotePairResponseSerializer,
PaginatedVotesResponseSerializer,
ProjectSerializer,
RoundApplicationSerializer,
RoundSerializer,
VotePairSerializer,
VoteSerializer,
)

Expand Down Expand Up @@ -175,7 +174,7 @@ class ProjectRoundVotesAPI(APIView, CustomSizePageNumberPagination):
],
responses={
200: OpenApiResponse(
response=PaginatedVotePairResponseSerializer, # Update to use the appropriate serializer
response=PaginatedVotesResponseSerializer, # Update to use the appropriate serializer
description="Returns votes for a project in the round",
examples=[
OpenApiExample(
Expand Down
27 changes: 14 additions & 13 deletions grantpicks/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,30 @@ class PaginatedRoundApplicationsResponseSerializer(serializers.Serializer):



class VotePairSerializer(serializers.ModelSerializer):
project = ProjectSerializer()

class Meta:
model = VotePair
fields = [
'pair_id',
'project',
]



class VoteSerializer(serializers.ModelSerializer):
round = serializers.PrimaryKeyRelatedField(queryset=Round.objects.all())
voter = AccountSerializer()
pairs = VotePairSerializer(many=True)

class Meta:
model = Vote
fields = [
'id',
'round',
'voter',
'pairs',
'tx_hash',
'voted_at',
]
Expand All @@ -289,19 +303,6 @@ class PaginatedVotesResponseSerializer(serializers.Serializer):
results = VoteSerializer(many=True)



class VotePairSerializer(serializers.ModelSerializer):
vote = VoteSerializer()
project = ProjectSerializer()

class Meta:
model = VotePair
fields = [
'vote',
'pair_id',
'project',
]

class PaginatedVotePairResponseSerializer(serializers.Serializer):
count = serializers.IntegerField()
next = serializers.CharField(allow_null=True)
Expand Down
4 changes: 3 additions & 1 deletion indexer_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,10 @@ async def handle_list_upvote(
"created_at": created_at
}

list_obj = List.objects.get(on_chain_id=data.get("list_id"))

await ListUpvote.objects.aupdate_or_create(
list_id=data.get("list_id") or receiver_id,
list=list_obj,
account_id=signer_id,
defaults=up_default
)
Expand Down
17 changes: 17 additions & 0 deletions lists/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from rest_framework.response import Response
from rest_framework.views import APIView

from accounts.models import Account
from api.pagination import pagination_parameters
from api.pagination import CustomSizePageNumberPagination

Expand All @@ -34,6 +35,12 @@ class ListsListAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
OpenApiParameter(
"account",
str,
OpenApiParameter.QUERY,
description="Filter lists by account",
),
*pagination_parameters,
],
responses={
Expand All @@ -50,12 +57,22 @@ class ListsListAPI(APIView, CustomSizePageNumberPagination):
),
],
),
404: OpenApiResponse(description="Account not found"),
500: OpenApiResponse(description="Internal server error"),
},
)
@method_decorator(cache_page(60 * 5))
def get(self, request: Request, *args, **kwargs):
lists = List.objects.all()
account_id = request.query_params.get("account")
if account_id:
try:
account = Account.objects.get(id=account_id)
lists = lists.filter(owner=account)
except Account.DoesNotExist:
return Response(
{"message": f"Account with ID {account_id} not found."}, status=404
)
results = self.paginate_queryset(lists, request, view=self)
serializer = ListSerializer(results, many=True)
return self.get_paginated_response(serializer.data)
Expand Down

0 comments on commit 34a5a5e

Please sign in to comment.