github-actions[bot]
Automated Deploy: 3ea2037ab7d55d5b498f7e2ea0336818fc24f725
fe40b87
Raw History Blame Contribute Delete
1.84 kB
from datetime import datetime
from math import isfinite
from typing import Annotated, Literal
from uuid import UUID
from pydantic import Field, StrictFloat, StrictInt, field_validator
from app.common.schemas import RequestModel, ResponseModel
Mode = Literal["h", "p"]
Due = Literal["1 week", "2 weeks", "End of month"]
class WeeklyIn(RequestModel):
practice_days: Annotated[int, Field(strict=True, ge=1, le=7)]
drill_sets: Annotated[int, Field(strict=True, ge=1, le=30)]
class GoalIn(RequestModel):
type: Literal["groups", "param", "score"]
target: StrictInt | StrictFloat
metric_id: str | None = Field(None, max_length=64)
due: Due
weekly: WeeklyIn
note: str = Field("", max_length=160)
expected_version: int | None = Field(None, ge=0)
@field_validator("target")
@classmethod
def _finite(cls, value: int | float) -> int | float:
if not isfinite(value):
raise ValueError("Must be a finite number.")
return value
class WeeklyOut(ResponseModel):
practice_days: int
drill_sets: int
class GoalOut(ResponseModel):
id: UUID
player_id: UUID
mode: str
type: str
target: int | float
metric_id: str | None
metric_name: str | None
due: str
due_at: datetime
set_at: datetime
set_by: str | None
set_by_id: UUID | None
note: str
weekly: WeeklyOut
version: int
class GoalEnvelope(ResponseModel):
goal: GoalOut | None
class GoalHistoryOut(ResponseModel):
id: UUID
text: str
range: str
met: bool | None
outcome: str | None
start_at: datetime
end_at: datetime | None
evaluated_session_id: UUID | None
class MilestoneOut(ResponseModel):
id: UUID
icon: str
tone: str
title: str
when: str
occurred_at: datetime
source_goal_id: UUID