You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.7 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
  1. from pydantic import BaseModel,Field
  2. from typing import Annotated
  3. from datetime import datetime
  4. # Token相关的模型
  5. class Token(BaseModel):
  6. access_token: str
  7. token_type: str
  8. class TokenData(BaseModel):
  9. username: str = None
  10. # User相关的模型
  11. class User(BaseModel):
  12. username: Annotated[str,Field(
  13. title="用户",
  14. examples=["admin"],
  15. pattern=r'^.{4,20}$',
  16. description="允许4-20的字符"
  17. )]
  18. email: Annotated[str,Field(
  19. examples=["examples@example.com"],
  20. max_length=50,
  21. pattern=r'^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$',
  22. description="邮箱需要满足正则标准"
  23. )]
  24. full_name: Annotated[str,Field(
  25. examples=["admin"],
  26. pattern=r'^.{2,20}$',
  27. description="允许2-20个字符"
  28. )]
  29. disabled: bool = True
  30. class UserInDB(User):
  31. hashed_password: str = None
  32. class BlogList(BaseModel):
  33. blogname:Annotated[str,Field(
  34. title="博客名",
  35. examples=['blogname'],
  36. pattern=r'^.{2,50}$',
  37. description="允许2-50个字符"
  38. )]
  39. blogtype:Annotated[str,Field(
  40. title="博客类型",
  41. examples=['blogtype'],
  42. description="博客类型允许为空"
  43. )]
  44. addtime:Annotated[datetime,Field(
  45. title="发布时间",
  46. description="数据库中提供了默认值"
  47. )]
  48. descr:Annotated[str,Field(
  49. title="备注",
  50. examples=['descr'],
  51. description="备注允许为空"
  52. )]
  53. class BlogAdd(BlogList):
  54. blogcontent:Annotated[str,Field(
  55. title="博客内容",
  56. examples=['blogcontent'],
  57. pattern=r'^.{2,}$',
  58. description="不能为空,允许2个或更多字符"
  59. )]