6cd959c528
- Add GET /api/v1/users/check-id/{user_id} endpoint for real-time validation
- Replace frontend local validation with debounced API calls (500ms)
- Support exclude_user_id parameter for edit scenarios
- Add UserIdCheckResponse schema
- Maintain format validation (alphanumeric + underscore) on frontend
- Clean up timeout on component unmount
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
55 lines
1.3 KiB
Python
55 lines
1.3 KiB
Python
from datetime import datetime
|
|
from typing import Literal
|
|
|
|
from pydantic import BaseModel, Field, field_validator
|
|
|
|
|
|
class UserPublic(BaseModel):
|
|
id: str
|
|
email: str
|
|
username: str
|
|
status: str
|
|
role_codes: list[str]
|
|
permission_codes: list[str]
|
|
created_at: datetime
|
|
last_login_at: datetime | None = None
|
|
|
|
|
|
class UserListResponse(BaseModel):
|
|
items: list[UserPublic]
|
|
total: int
|
|
|
|
|
|
class UserIdCheckResponse(BaseModel):
|
|
available: bool
|
|
message: str
|
|
|
|
|
|
class UserUpdateRequest(BaseModel):
|
|
email: str | None = None
|
|
username: str | None = Field(default=None, min_length=3, max_length=64)
|
|
status: Literal["active", "disabled", "enabled"] | None = None
|
|
|
|
|
|
class UserRoleUpdateRequest(BaseModel):
|
|
role_codes: list[str] = Field(min_length=1)
|
|
|
|
|
|
class UserPasswordResetRequest(BaseModel):
|
|
new_password: str = Field(min_length=8, max_length=128)
|
|
|
|
|
|
class UserCreateRequest(BaseModel):
|
|
user_id: str = Field(min_length=3, max_length=64)
|
|
email: str | None = None
|
|
username: str = Field(min_length=3, max_length=64)
|
|
password: str = Field(min_length=8, max_length=128)
|
|
|
|
@field_validator("user_id")
|
|
@classmethod
|
|
def validate_user_id(cls, value: str) -> str:
|
|
normalized = value.strip()
|
|
if not normalized:
|
|
raise ValueError("user_id cannot be empty")
|
|
return normalized
|