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.
69 lines
1.8 KiB
69 lines
1.8 KiB
from pydantic import BaseModel,Field
|
|
from typing import Annotated
|
|
from datetime import datetime
|
|
# Token相关的模型
|
|
class Token(BaseModel):
|
|
access_token: str
|
|
token_type: str
|
|
|
|
class TokenData(BaseModel):
|
|
username: str = None
|
|
|
|
# User相关的模型
|
|
class User(BaseModel):
|
|
username: Annotated[str,Field(
|
|
title="用户",
|
|
examples=["admin"],
|
|
pattern=r'^.{4,20}$',
|
|
description="允许4-20的字符"
|
|
)]
|
|
email: Annotated[str,Field(
|
|
examples=["examples@example.com"],
|
|
max_length=50,
|
|
pattern=r'^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$',
|
|
description="邮箱需要满足正则标准"
|
|
)]
|
|
full_name: Annotated[str,Field(
|
|
examples=["admin"],
|
|
pattern=r'^.{2,20}$',
|
|
description="允许2-20个字符"
|
|
)]
|
|
disabled: bool = True
|
|
|
|
class UserInDB(User):
|
|
hashed_password: str = None
|
|
|
|
class BlogList(BaseModel):
|
|
blogname:Annotated[str,Field(
|
|
title="博客名",
|
|
examples=['blogname'],
|
|
pattern=r'^.{2,50}$',
|
|
description="允许2-50个字符"
|
|
)]
|
|
blogtype:Annotated[str,Field(
|
|
title="博客类型",
|
|
default=None,
|
|
description="博客类型允许为空"
|
|
)]
|
|
viewsnum:Annotated[int,Field(
|
|
title="访问量",
|
|
default=None,
|
|
description="访问量可以为空"
|
|
)]
|
|
addtime:Annotated[datetime,Field(
|
|
title="发布时间",
|
|
description="数据库中提供了默认值"
|
|
)]
|
|
descr:Annotated[str,Field(
|
|
title="备注",
|
|
default=None,
|
|
description="备注允许为空"
|
|
)]
|
|
|
|
class BlogAdd(BlogList):
|
|
blogcontent:Annotated[str,Field(
|
|
title="博客内容",
|
|
examples=['blogcontent'],
|
|
pattern=r'^.{2,}$',
|
|
description="不能为空,允许2个或更多字符"
|
|
)]
|