42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
"""Pydantic request/response models."""
|
|
from __future__ import annotations
|
|
|
|
from typing import Literal
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
# ── Auth ─────────────────────────────────────────────────────────────────────
|
|
|
|
class LoginRequest(BaseModel):
|
|
username: str = Field(min_length=3, max_length=120)
|
|
password: str = Field(min_length=1, max_length=72)
|
|
|
|
|
|
class TokenResponse(BaseModel):
|
|
access_token: str
|
|
token_type: str = "bearer"
|
|
|
|
|
|
# ── User management ──────────────────────────────────────────────────────────
|
|
|
|
DataPermission = Literal["data_manage", "data_view"]
|
|
UserStatus = Literal["active", "disabled"]
|
|
|
|
|
|
class UserCreate(BaseModel):
|
|
username: str = Field(min_length=3, max_length=120)
|
|
password: str = Field(min_length=12, max_length=72)
|
|
full_name: str | None = None
|
|
phone: str | None = None
|
|
status: UserStatus = "active"
|
|
permission: DataPermission = "data_view"
|
|
|
|
|
|
class UserUpdate(BaseModel):
|
|
full_name: str | None = None
|
|
phone: str | None = None
|
|
status: UserStatus | None = None
|
|
password: str | None = Field(default=None, min_length=12, max_length=72)
|
|
permission: DataPermission | None = None
|