137 lines
No EOL
5.3 KiB
Python
137 lines
No EOL
5.3 KiB
Python
import re
|
|
from pydantic import BaseModel, Field, validator
|
|
from typing import Optional
|
|
|
|
class User(BaseModel):
|
|
id: Optional[int] = Field(description="Идентификатор (автоматический)", default=None)
|
|
username: str = Field(max_length=150, description="Пользовательское имя", example="john_doe")
|
|
#password: str = Field(max_length=255, description="Пароль", example="secret123")
|
|
email: Optional[str] = Field(max_length=254, default="", description="Электронная почта", example="john@example.com")
|
|
first_name: Optional[str] = Field(max_length=150, default="", description="Имя", example="John")
|
|
last_name: Optional[str] = Field(max_length=150, default="", description="Фамилия", example="Doe")
|
|
#is_staff: bool = Field(default=False, description="Статус администратора")
|
|
#is_active: bool = Field(default=False, description="Активен")
|
|
#is_superuser: bool = Field(default=False, description="Суперпользователь")
|
|
#date_joined: str = Field(description="Дата создания", example="2024-01-01T12:00:00")
|
|
#last_login: Optional[str] = Field(null=True, default=None, description="Последний вход")
|
|
|
|
class Config:
|
|
extra = "ignore"
|
|
from_attributes = True
|
|
|
|
|
|
|
|
class SIPAccount(BaseModel):
|
|
"""
|
|
SIP-аккаунт.
|
|
"""
|
|
unique_id: str = Field(description="Уникальный идентификатор", example="00000000-0000-0000-0000-000000000000")
|
|
id: Optional[int] = Field(description="Идентификатор (автоматический)", default=None)
|
|
created_at: Optional[str] = Field(description="Дата создания", example="2024-01-01T12:00:00")
|
|
updated_at: Optional[str] = Field(description="Дата обновления", example="2024-01-01T12:00:00")
|
|
|
|
owner: Optional[User] = Field(description="Владелец")
|
|
name: str = Field(max_length=255, description="Название", example="SIP-аккаунт-1")
|
|
is_registered: bool = Field(default=False, description="Зарегистрирован")
|
|
username: str = Field(max_length=40, description="Имя SIP клиента", example="user123")
|
|
password: Optional[str] = Field(max_length=80, null=True, blank=True, description="Пароль (открытый, временно)")
|
|
|
|
server_url: str = Field(
|
|
max_length=215,
|
|
description="URL сервера",
|
|
example="https://192.168.1.100:5060"
|
|
)
|
|
port: Optional[int] = Field(null=True, blank=True, description="Порт", ge=0, le=65535)
|
|
internal_number: Optional[str] = Field(max_length=255, null=True, blank=True, description="Внутренний номер")
|
|
endpoint_name: Optional[str] = Field(max_length=255, null=True, blank=True, description="Имя конечной точки")
|
|
|
|
@validator("username")
|
|
def validate_username(cls, v):
|
|
if len(v) > 40:
|
|
raise ValueError("Username too long (max 40 characters)")
|
|
return v
|
|
|
|
@validator("name")
|
|
def validate_name(cls, v):
|
|
if len(v) > 255:
|
|
raise ValueError("Name too long (max 255 characters)")
|
|
return v
|
|
|
|
@validator("internal_number")
|
|
def validate_internal_number(cls, v):
|
|
if v and len(v) > 255:
|
|
raise ValueError("Internal number too long (max 255 characters)")
|
|
return v
|
|
|
|
@validator("endpoint_name")
|
|
def validate_endpoint_name(cls, v):
|
|
if v and len(v) > 255:
|
|
raise ValueError("Endpoint name too long (max 255 characters)")
|
|
return v
|
|
|
|
@validator("port")
|
|
def validate_port(cls, v):
|
|
if v is not None and not (0 <= v <= 65535):
|
|
raise ValueError("Port must be between 0 and 65535")
|
|
return v
|
|
|
|
class Config:
|
|
extra = "ignore"
|
|
from_attributes = True
|
|
|
|
class SIPAccountIn(BaseModel):
|
|
"""
|
|
SIP-аккаунт.
|
|
"""
|
|
owner_id: Optional[int]
|
|
name: Optional[str]
|
|
is_registered: Optional[bool]
|
|
username: Optional[str]
|
|
password: Optional[str]
|
|
|
|
server_url: Optional[str]
|
|
port: Optional[int]
|
|
internal_number: Optional[str]
|
|
endpoint_name: Optional[str]
|
|
|
|
@validator("username")
|
|
def validate_username(cls, v):
|
|
if v and len(v) > 40:
|
|
raise ValueError("Username too long (max 40 characters)")
|
|
return v
|
|
|
|
@validator("name")
|
|
def validate_name(cls, v):
|
|
if v and len(v) > 255:
|
|
raise ValueError("Name too long (max 255 characters)")
|
|
return v
|
|
|
|
@validator("internal_number")
|
|
def validate_internal_number(cls, v):
|
|
if v and len(v) > 255:
|
|
raise ValueError("Internal number too long (max 255 characters)")
|
|
return v
|
|
|
|
@validator("endpoint_name")
|
|
def validate_endpoint_name(cls, v):
|
|
if v and len(v) > 255:
|
|
raise ValueError("Endpoint name too long (max 255 characters)")
|
|
return v
|
|
|
|
@validator("port")
|
|
def validate_port(cls, v):
|
|
if v is not None and not (0 <= v <= 65535):
|
|
raise ValueError("Port must be between 0 and 65535")
|
|
return v
|
|
|
|
class Config:
|
|
extra = "ignore"
|
|
from_attributes = True
|
|
|
|
|
|
class AccessResponse(BaseModel):
|
|
success: bool
|
|
token: str
|
|
|
|
class Registration(BaseModel):
|
|
auth_key: str |