f1tness_parser/backend/app/schemas/trainings.py
2026-10-23 20:21:48 +03:00

36 lines
1 KiB
Python

from datetime import date
from typing import List, Optional
from pydantic import BaseModel, Field, field_validator
class ApproachUpdate(BaseModel):
weight: float = Field(ge=0)
reps: int = Field(gt=0)
class ExerciseUpdate(BaseModel):
name: str = Field(max_length=255)
splitted_weight: bool = False
approaches: List[ApproachUpdate] = Field(default_factory=list)
@field_validator("name")
@classmethod
def strip_name(cls, value: str) -> str:
value = value.strip()
if not value:
raise ValueError("name must not be empty")
return value
class TrainingUpdate(BaseModel):
"""The whole training as it should be after the edit (PUT replaces it)."""
date: date
trainer: Optional[str] = Field(default=None, max_length=100)
exercises: List[ExerciseUpdate] = Field(default_factory=list)
@field_validator("trainer")
@classmethod
def blank_trainer_is_none(cls, value: Optional[str]) -> Optional[str]:
return value.strip() or None if value else None