Update return schema of query interface (#492)

* Update return model of query interface

* Update tree data return type hints

* Update code generation and task return types

* Fix inconsistency between ORM query result and schema
This commit is contained in:
Wu Clan
2025-01-18 23:33:37 +08:00
committed by GitHub
parent cf693cdce6
commit 7553ccf14d
55 changed files with 257 additions and 234 deletions
-13
View File
@@ -52,16 +52,3 @@ class AccessToken:
class RefreshToken:
refresh_token: str
refresh_token_expire_time: datetime
@dataclasses.dataclass
class TaskResult:
result: str
traceback: str
status: str
name: str
args: list | None
kwargs: dict | None
worker: str
retries: int | None
queue: str | None
+6 -8
View File
@@ -84,22 +84,20 @@ class PageData(_PageDetails, Generic[SchemaT]):
E.g. ::
@router.get('/test', response_model=ResponseSchemaModel[PageData[GetApiListDetails]])
@router.get('/test', response_model=ResponseSchemaModel[PageData[GetApiDetail]])
def test():
return ResponseSchemaModel[PageData[GetApiListDetails]](data=GetApiListDetails(...))
return ResponseSchemaModel[PageData[GetApiDetail]](data=GetApiDetail(...))
@router.get('/test')
def test() -> ResponseSchemaModel[PageData[GetApiListDetails]]:
return ResponseSchemaModel[PageData[GetApiListDetails]](data=GetApiListDetails(...))
def test() -> ResponseSchemaModel[PageData[GetApiDetail]]:
return ResponseSchemaModel[PageData[GetApiDetail]](data=GetApiDetail(...))
@router.get('/test')
def test() -> ResponseSchemaModel[PageData[GetApiListDetails]]:
def test() -> ResponseSchemaModel[PageData[GetApiDetail]]:
res = CustomResponseCode.HTTP_200
return ResponseSchemaModel[PageData[GetApiListDetails]](
code=res.code, msg=res.msg, data=GetApiListDetails(...)
)
return ResponseSchemaModel[PageData[GetApiDetail]](code=res.code, msg=res.msg, data=GetApiDetail(...))
"""
items: Sequence[SchemaT]
+6 -6
View File
@@ -49,20 +49,20 @@ class ResponseSchemaModel(ResponseModel, Generic[SchemaT]):
E.g. ::
@router.get('/test', response_model=ResponseSchemaModel[GetApiListDetails])
@router.get('/test', response_model=ResponseSchemaModel[GetApiDetail])
def test():
return ResponseSchemaModel[GetApiListDetails](data=GetApiListDetails(...))
return ResponseSchemaModel[GetApiDetail](data=GetApiDetail(...))
@router.get('/test')
def test() -> ResponseSchemaModel[GetApiListDetails]:
return ResponseSchemaModel[GetApiListDetails](data=GetApiListDetails(...))
def test() -> ResponseSchemaModel[GetApiDetail]:
return ResponseSchemaModel[GetApiDetail](data=GetApiDetail(...))
@router.get('/test')
def test() -> ResponseSchemaModel[GetApiListDetails]:
def test() -> ResponseSchemaModel[GetApiDetail]:
res = CustomResponseCode.HTTP_200
return ResponseSchemaModel[GetApiListDetails](code=res.code, msg=res.msg, data=GetApiListDetails(...))
return ResponseSchemaModel[GetApiDetail](code=res.code, msg=res.msg, data=GetApiDetail(...))
"""
data: SchemaT
+1
View File
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from pydantic import BaseModel, ConfigDict, EmailStr, validate_email
from pydantic_extra_types.phone_numbers import PhoneNumber
+2 -2
View File
@@ -12,7 +12,7 @@ from backend.core.conf import settings
from backend.utils.import_parse import dynamic_import
if TYPE_CHECKING:
from backend.app.admin.schema.data_rule import GetDataRuleListDetails
from backend.app.admin.schema.data_rule import GetDataRuleDetail
class RequestPermission:
@@ -47,7 +47,7 @@ def filter_data_permission(request: Request) -> ColumnElement[bool]:
data_rules = []
for role in request.user.roles:
data_rules.extend(role.rules)
user_data_rules: list[GetDataRuleListDetails] = list(dict.fromkeys(data_rules))
user_data_rules: list[GetDataRuleDetail] = list(dict.fromkeys(data_rules))
# 超级管理员和无规则用户不做过滤
if request.user.is_superuser or not user_data_rules: