51 lines
1.9 KiB
Python
51 lines
1.9 KiB
Python
from typing import Required
|
|
import uuid
|
|
from pydantic import BaseModel, ConfigDict, Field, field_validator, StrictBool
|
|
|
|
class AdminCreateUser(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
username: str = Field(..., max_length=20, description='username of the user')
|
|
phone_number: str | None = Field(None, max_length=11, description='phone number of user')
|
|
|
|
# validate phone number
|
|
@field_validator('phone_number')
|
|
def validate_phone_number(cls, v: str | None) -> str | None:
|
|
if v is None:
|
|
return None
|
|
if not v.isdigit():
|
|
raise ValueError('شماره تلفن باید عدد باشد')
|
|
if len(v) != 11:
|
|
raise ValueError('شماره تلفن باید 11 رقم باشد')
|
|
if not v.startswith('09'):
|
|
raise ValueError('شماره تلفن باید با 09 شروع شود')
|
|
return v
|
|
|
|
class AdminUserResponse(BaseModel):
|
|
id: uuid.UUID = Field(...)
|
|
username: str = Field(..., max_length=20, description='username of the user')
|
|
phone_number: str | None = Field(..., description='phone number of user')
|
|
is_admin: bool = Field(..., description='is admin')
|
|
is_active: bool = Field(..., description='is active')
|
|
|
|
@field_validator('phone_number')
|
|
def validate_phone_number(cls, v: str | None) -> str | None:
|
|
if v is None:
|
|
return None
|
|
if not v.isdigit():
|
|
raise ValueError('شماره تلفن باید عدد باشد')
|
|
if len(v) != 11:
|
|
raise ValueError('شماره تلفن باید 11 رقم باشد')
|
|
if not v.startswith('09'):
|
|
raise ValueError('شماره تلفن باید با 09 شروع شود')
|
|
return v
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
class AdminCreateUserResult(BaseModel):
|
|
user: AdminUserResponse = Field(...)
|
|
secret: str = Field(...)
|
|
|
|
class AdminResetSecretResult(BaseModel):
|
|
secret: str = Field(...)
|