feat: add validation for minimum length on various fields and update type definitions

This commit is contained in:
Abhimanyu Saharan
2026-02-06 16:12:04 +05:30
parent ca614328ac
commit d86fe0a7a6
157 changed files with 12340 additions and 2977 deletions

View File

@@ -1,6 +1,7 @@
from __future__ import annotations
from datetime import datetime
from typing import Self
from uuid import UUID
from pydantic import model_validator
@@ -20,8 +21,10 @@ class BoardBase(SQLModel):
class BoardCreate(BoardBase):
gateway_id: UUID
@model_validator(mode="after")
def validate_goal_fields(self):
def validate_goal_fields(self) -> Self:
if self.board_type == "goal" and self.goal_confirmed:
if not self.objective or not self.success_metrics:
raise ValueError("Confirmed goal boards require objective and success_metrics")
@@ -39,6 +42,13 @@ class BoardUpdate(SQLModel):
goal_confirmed: bool | None = None
goal_source: str | None = None
@model_validator(mode="after")
def validate_gateway_id(self) -> Self:
# Treat explicit null like "unset" is invalid for patch updates.
if "gateway_id" in self.model_fields_set and self.gateway_id is None:
raise ValueError("gateway_id is required")
return self
class BoardRead(BoardBase):
id: UUID