This commit is contained in:
mizhexiaoxiao 2023-10-18 15:58:09 +08:00
parent 0871ef5c1c
commit 26a7d84f7d
4 changed files with 10 additions and 12 deletions

View File

@ -35,9 +35,7 @@ async def get_role(
@router.post("/create", summary="创建角色") @router.post("/create", summary="创建角色")
async def create_role( async def create_role(role_in: RoleCreate):
role_in: RoleCreate,
):
if await role_controller.is_exist(name=role_in.name): if await role_controller.is_exist(name=role_in.name):
raise HTTPException( raise HTTPException(
status_code=400, status_code=400,

View File

@ -5,7 +5,7 @@ from app.models.enums import MethodType
class BaseApi(BaseModel): class BaseApi(BaseModel):
path: str = Field(..., description="API路径", example="/api/v1/user/list") path: str = Field(..., description="API路径", example="/api/v1/user/list")
summary: str = Field(None, description="API简介", example="查看用户列表") summary: str = Field("", description="API简介", example="查看用户列表")
method: MethodType = Field(..., description="API方法", example="GET") method: MethodType = Field(..., description="API方法", example="GET")
tags: str = Field(..., description="API标签", example="User") tags: str = Field(..., description="API标签", example="User")

View File

@ -7,23 +7,23 @@ from pydantic import BaseModel, Field
class BaseRole(BaseModel): class BaseRole(BaseModel):
id: int id: int
name: str name: str
desc: Optional[str] desc: str = ""
users: Optional[list] users: Optional[list] = []
menus: Optional[list] menus: Optional[list] = []
apis: Optional[list] apis: Optional[list] = []
created_at: Optional[datetime] created_at: Optional[datetime]
updated_at: Optional[datetime] updated_at: Optional[datetime]
class RoleCreate(BaseModel): class RoleCreate(BaseModel):
name: str = Field(example="管理员") name: str = Field(example="管理员")
desc: Optional[str] = Field(example="管理员角色") desc: str = Field("", examples="管理员角色")
class RoleUpdate(BaseModel): class RoleUpdate(BaseModel):
id: int = Field(example=1) id: int = Field(example=1)
name: Optional[str] = Field(example="管理员") name: str = Field(example="管理员")
desc: Optional[str] = Field(example="管理员角色") desc: str = Field("", example="管理员角色")
def update_dict(self): def update_dict(self):
return self.model_dump(exclude_unset=True, exclude={"id"}) return self.model_dump(exclude_unset=True, exclude={"id"})

View File

@ -5,6 +5,6 @@ from app.settings.config import settings
def create_access_token(*, data: JWTPayload): def create_access_token(*, data: JWTPayload):
payload = data.dict().copy() payload = data.model_dump().copy()
encoded_jwt = jwt.encode(payload, settings.SECRET_KEY, algorithm=settings.JWT_ALGORITHM) encoded_jwt = jwt.encode(payload, settings.SECRET_KEY, algorithm=settings.JWT_ALGORITHM)
return encoded_jwt return encoded_jwt