Skip to content

Commit

Permalink
sort round by chain, add constraint to round
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometheo committed Nov 5, 2024
1 parent bbeb310 commit b06976c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
10 changes: 10 additions & 0 deletions grantpicks/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class RoundsListAPI(APIView, CustomSizePageNumberPagination):
location=OpenApiParameter.QUERY,
description="Sort by field, e.g., deployed_at, vault_total_deposits",
),
OpenApiParameter(
"chain",
str,
OpenApiParameter.QUERY,
description="Filter projects by chain",
),
*pagination_parameters,
],
responses={
Expand All @@ -79,6 +85,10 @@ class RoundsListAPI(APIView, CustomSizePageNumberPagination):
@method_decorator(cache_page(60 * 1))
def get(self, request: Request, *args, **kwargs):
rounds = Round.objects.all()
chain_param = request.query_params.get("chain")
if chain_param:
# chain = Chain.objects.get(name=chain_param)
rounds = rounds.filter(chain_id=chain_param)
sort = request.query_params.get("sort", None)
if sort == "deployed_at":
rounds = rounds.order_by(
Expand Down
36 changes: 36 additions & 0 deletions grantpicks/migrations/0004_alter_round_on_chain_id_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 5.0.6 on 2024-11-05 10:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("chains", "0003_add_stellar_chain"),
("grantpicks", "0003_alter_votepair_project"),
]

operations = [
migrations.AlterField(
model_name="round",
name="on_chain_id",
field=models.IntegerField(
help_text="Round ID in contract", verbose_name="contract round ID"
),
),
migrations.AlterField(
model_name="rounddeposit",
name="on_chain_id",
field=models.IntegerField(
help_text="Deposit ID in contract", verbose_name="contract deposit ID"
),
),
migrations.AlterUniqueTogether(
name="round",
unique_together={("chain", "on_chain_id")},
),
migrations.AlterUniqueTogether(
name="rounddeposit",
unique_together={("round", "on_chain_id")},
),
]
9 changes: 6 additions & 3 deletions grantpicks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class Round(models.Model):
on_chain_id = models.IntegerField(
_("contract round ID"),
null=False,
unique=True,
help_text=_("Round ID in contract"),
)
chain = models.ForeignKey(
Expand Down Expand Up @@ -326,6 +325,9 @@ class Round(models.Model):
help_text=_("Round complete date."),
)

class Meta:
unique_together = ('chain', 'on_chain_id')




Expand Down Expand Up @@ -357,7 +359,6 @@ def save(self, *args, **kwargs):
super().save(*args, **kwargs)



class RoundDeposit(models.Model):
id = models.AutoField(
_("deposit id"),
Expand All @@ -367,7 +368,6 @@ class RoundDeposit(models.Model):
on_chain_id = models.IntegerField(
_("contract deposit ID"),
null=False,
unique=True,
help_text=_("Deposit ID in contract"),
)
round = models.ForeignKey(
Expand Down Expand Up @@ -436,6 +436,9 @@ class RoundDeposit(models.Model):
help_text=_("Transaction hash."),
)

class Meta:
unique_together = ('round', 'on_chain_id')

class Vote(models.Model):
round = models.ForeignKey(Round, on_delete=models.CASCADE, related_name='votes')
voter = models.ForeignKey(Account, on_delete=models.CASCADE, related_name='votes')
Expand Down

0 comments on commit b06976c

Please sign in to comment.