forked from mtusi2026/mtusi2026lab2
28 lines
635 B
Python
28 lines
635 B
Python
import re
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
USERNAME_RE = re.compile(r"^[a-z0-9_]{3,32}$")
|
|
|
|
|
|
class CreateUser(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
password: str = Field(min_length=12,max_length=128)
|
|
username: str
|
|
display_name: str
|
|
|
|
|
|
class CreateChat(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
title: str
|
|
member_ids: list[str]
|
|
|
|
|
|
class CreateMessage(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
text: str
|
|
|
|
|
|
def valid_text(value: str, maximum: int) -> bool:
|
|
return isinstance(value, str) and value.strip() != "" and 1 <= len(value) <= maximum
|