user.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from datetime import datetime
  4. from typing import List
  5. from typing import Optional
  6. from pydantic import Field
  7. from pydantic.main import BaseModel
  8. from schemas.base import ListMixin, DetailMixin, Datetime2Str
  9. class CreateAdminUser(BaseModel):
  10. username: str = Field(..., max_length=64)
  11. password: str = Field(..., max_length=64)
  12. phone: str = Field(..., max_length=32)
  13. name: str = Field(None, max_length=32)
  14. role_id: int
  15. is_active: bool = None
  16. last_login_time: Optional[datetime] = Field(datetime.now())
  17. last_login_ip: Optional[str] = Field("", max_length=15)
  18. class UpdateAdminUser(BaseModel):
  19. phone: Optional[str] = Field(None, max_length=32, description="手机号")
  20. name: Optional[str] = Field(None, max_length=32, description="姓名")
  21. is_active: Optional[bool] = Field(None, description="是否激活")
  22. class AdminUserInfo(BaseModel):
  23. id: Optional[int] = None
  24. username: str = Field(None, max_length=64)
  25. phone: str = Field(None, max_length=32)
  26. name: str = Field(None, max_length=32)
  27. role_id: int = Field(None)
  28. is_active: bool = None
  29. last_login_time: Datetime2Str = None
  30. last_login_ip: str = Field(None, max_length=15)
  31. creator_name: Optional[str] = None
  32. created_at: Datetime2Str = None
  33. class Config:
  34. orm_mode = True
  35. class AdminUserDetail(DetailMixin):
  36. data: Optional[AdminUserInfo] = None
  37. class AdminUserList(ListMixin):
  38. data: List[AdminUserInfo] = []