Neda/Back/domains/users/schemas.py

32 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import uuid
from pydantic import BaseModel, Field, field_validator
import re
class UserCreate(BaseModel):
username: str = Field(..., max_length=20, description='username of the user')
phone_number: str | None = Field(None, description="11 digit phone number")
is_admin: bool = Field(False)
@field_validator("phone_number")
@classmethod
def validate_phone_number(cls, v: str | None) -> str | None:
if v is None:
return v
if not re.match(r"^09\d{9}$", v):
raise ValueError("شماره تلفن باید ۱۱ رقم باشد و با ۰۹ شروع شود")
return v
class UserResponse(BaseModel):
id: uuid.UUID = Field(...)
username: str = Field(..., description='username of the user')
phone_number: str | None = Field(..., description='phone number of the user')
is_admin: bool = Field(..., description='is admin')
is_active: bool = Field(..., description='is active')
class Config:
from_attributes = True
class UserCreateResult(BaseModel):
user: UserResponse = Field(..., description='user created')
secret: str = Field(..., description='secret of the user')