46 lines
1.0 KiB
Python
46 lines
1.0 KiB
Python
|
|
import uuid
|
||
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
from pydantic import BaseModel, field_validator
|
||
|
|
import re
|
||
|
|
|
||
|
|
|
||
|
|
class TenantBase(BaseModel):
|
||
|
|
name: str
|
||
|
|
slug: str
|
||
|
|
|
||
|
|
@field_validator("slug")
|
||
|
|
@classmethod
|
||
|
|
def slug_format(cls, v: str) -> str:
|
||
|
|
if not re.match(r"^[a-z0-9-]+$", v):
|
||
|
|
raise ValueError(
|
||
|
|
"Der Slug darf nur Kleinbuchstaben, Zahlen und Bindestriche enthalten."
|
||
|
|
)
|
||
|
|
return v
|
||
|
|
|
||
|
|
|
||
|
|
class TenantCreate(TenantBase):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class TenantUpdate(BaseModel):
|
||
|
|
name: str | None = None
|
||
|
|
slug: str | None = None
|
||
|
|
|
||
|
|
@field_validator("slug")
|
||
|
|
@classmethod
|
||
|
|
def slug_format(cls, v: str | None) -> str | None:
|
||
|
|
if v is not None and not re.match(r"^[a-z0-9-]+$", v):
|
||
|
|
raise ValueError(
|
||
|
|
"Der Slug darf nur Kleinbuchstaben, Zahlen und Bindestriche enthalten."
|
||
|
|
)
|
||
|
|
return v
|
||
|
|
|
||
|
|
|
||
|
|
class TenantRead(TenantBase):
|
||
|
|
model_config = {"from_attributes": True}
|
||
|
|
|
||
|
|
id: uuid.UUID
|
||
|
|
created_at: datetime
|
||
|
|
updated_at: datetime
|