Files
sdb2-backend/app/schemas/user.py
JSC 92571f4de9
Some checks failed
Backend CI / lint (push) Failing after 1m29s
Backend CI / test (push) Failing after 1m36s
Refactor code structure for improved readability and maintainability
2025-09-13 22:38:55 +02:00

28 lines
905 B
Python

"""User schemas."""
from pydantic import BaseModel, Field, field_validator
class UserUpdate(BaseModel):
"""Schema for updating a user."""
name: str | None = Field(
None,
min_length=1,
max_length=100,
description="User full name",
)
plan_id: int | None = Field(None, description="User plan ID")
credits: int | None = Field(None, ge=0, description="User credits")
is_active: bool | None = Field(None, description="Whether user is active")
role: str | None = Field(None, description="User role (admin or user)")
@field_validator("role")
@classmethod
def validate_role(cls, v: str | None) -> str | None:
"""Validate that role is either 'user' or 'admin'."""
if v is not None and v not in {"user", "admin"}:
msg = "Role must be either 'user' or 'admin'"
raise ValueError(msg)
return v