Files
game-marathon/backend/app/schemas/user.py

58 lines
1.3 KiB
Python
Raw Normal View History

2025-12-14 02:38:35 +07:00
from datetime import datetime
from pydantic import BaseModel, Field, field_validator
import re
class UserBase(BaseModel):
nickname: str = Field(..., min_length=2, max_length=50)
class UserRegister(UserBase):
login: str = Field(..., min_length=3, max_length=50)
password: str = Field(..., min_length=6, max_length=100)
@field_validator("login")
@classmethod
def validate_login(cls, v: str) -> str:
if not re.match(r"^[a-zA-Z0-9_]+$", v):
raise ValueError("Login can only contain letters, numbers, and underscores")
return v.lower()
class UserLogin(BaseModel):
login: str
password: str
class UserUpdate(BaseModel):
nickname: str | None = Field(None, min_length=2, max_length=50)
class UserPublic(UserBase):
id: int
login: str
avatar_url: str | None = None
2025-12-14 20:21:56 +07:00
role: str = "user"
2025-12-16 20:06:16 +07:00
telegram_id: int | None = None
telegram_username: str | None = None
2025-12-14 02:38:35 +07:00
created_at: datetime
class Config:
from_attributes = True
class UserWithTelegram(UserPublic):
telegram_id: int | None = None
telegram_username: str | None = None
class TokenResponse(BaseModel):
access_token: str
token_type: str = "bearer"
user: UserPublic
class TelegramLink(BaseModel):
telegram_id: int
telegram_username: str | None = None