diff --git a/services/backend/api/v1/competition/schemas.py b/services/backend/api/v1/competition/schemas.py index 079baab..c1252c2 100644 --- a/services/backend/api/v1/competition/schemas.py +++ b/services/backend/api/v1/competition/schemas.py @@ -8,6 +8,14 @@ from apps.competition.models import Competition, State class CompetitionOut(ModelSchema): id: UUID + state: Literal["not_started", "started", "finished"] + + @staticmethod + def resolve_state(self, context) -> Literal["not_started", "started", "finished"]: + if not (state := State.objects.filter(user=context.get("request").auth, competition=self).first()): + return "not_started" + return state.state + class Meta: model = Competition diff --git a/services/backend/apps/competition/models.py b/services/backend/apps/competition/models.py index 9c0c0fc..9c37c79 100644 --- a/services/backend/apps/competition/models.py +++ b/services/backend/apps/competition/models.py @@ -60,5 +60,5 @@ class State(BaseModel): user = models.ForeignKey(User, on_delete=models.CASCADE) competition = models.ForeignKey(Competition, on_delete=models.CASCADE) - state = models.CharField(choices=StateChoices.choices, max_length=11) + state = models.CharField(choices=StateChoices.choices, max_length=11, default=StateChoices.NOT_STARTED.value) changed_at = models.DateTimeField(default=datetime.now)