mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 21:27:10 +00:00
feat: added competition logic
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from typing import Literal
|
||||
from uuid import UUID
|
||||
|
||||
from ninja import ModelSchema
|
||||
from ninja import ModelSchema, Schema
|
||||
|
||||
from apps.competition.models import Competition
|
||||
from apps.competition.models import Competition, State
|
||||
|
||||
|
||||
class CompetitionOut(ModelSchema):
|
||||
@@ -12,12 +13,31 @@ class CompetitionOut(ModelSchema):
|
||||
model = Competition
|
||||
fields = "__all__"
|
||||
|
||||
class StateOut(ModelSchema):
|
||||
class Meta:
|
||||
model = State
|
||||
fields = (
|
||||
"state",
|
||||
)
|
||||
|
||||
class StateIn(Schema):
|
||||
state: Literal["started", "not_started", "finished"]
|
||||
|
||||
class CompetitionListInstanceOut(ModelSchema):
|
||||
id: UUID
|
||||
is_participating: bool
|
||||
completed: bool
|
||||
|
||||
@staticmethod
|
||||
def resolve_is_participating(self, context):
|
||||
user = context["request"].auth
|
||||
return self.participants.filter(id=user.id).exists()
|
||||
|
||||
@staticmethod
|
||||
def resolve_completed(self, context):
|
||||
user = context["request"].auth
|
||||
return State.objects.filter(competition=self, user=user, state="finished").exists()
|
||||
|
||||
class Meta:
|
||||
model = Competition
|
||||
fields = (
|
||||
|
||||
Reference in New Issue
Block a user