Skip to content

Commit 951fdc9

Browse files
authored
Optimize the return of relationship interfaces (#545)
* Optimize the return of relationship interfaces * Fix gen business detail schema
1 parent 18ffa06 commit 951fdc9

File tree

9 files changed

+14
-38
lines changed

9 files changed

+14
-38
lines changed

backend/app/admin/api/v1/sys/data_rule.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from backend.common.security.permission import RequestPermission
1313
from backend.common.security.rbac import DependsRBAC
1414
from backend.database.db import CurrentSession
15-
from backend.utils.serializers import select_as_dict, select_list_serialize
1615

1716
router = APIRouter()
1817

@@ -31,15 +30,13 @@ async def get_data_rule_model_columns(model: Annotated[str, Path()]) -> Response
3130

3231
@router.get('/all', summary='获取所有数据规则', dependencies=[DependsJwtAuth])
3332
async def get_all_data_rule() -> ResponseSchemaModel[list[GetDataRuleDetail]]:
34-
data_rules = await data_rule_service.get_all()
35-
data = select_list_serialize(data_rules)
33+
data = await data_rule_service.get_all()
3634
return response_base.success(data=data)
3735

3836

3937
@router.get('/{pk}', summary='获取数据权限规则详情', dependencies=[DependsJwtAuth])
4038
async def get_data_rule(pk: Annotated[int, Path(...)]) -> ResponseSchemaModel[GetDataRuleDetail]:
41-
data_rule = await data_rule_service.get(pk=pk)
42-
data = GetDataRuleDetail(**select_as_dict(data_rule))
39+
data = await data_rule_service.get(pk=pk)
4340
return response_base.success(data=data)
4441

4542

backend/app/admin/api/v1/sys/dept.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010
from backend.common.security.jwt import DependsJwtAuth
1111
from backend.common.security.permission import RequestPermission
1212
from backend.common.security.rbac import DependsRBAC
13-
from backend.utils.serializers import select_as_dict
1413

1514
router = APIRouter()
1615

1716

1817
@router.get('/{pk}', summary='获取部门详情', dependencies=[DependsJwtAuth])
1918
async def get_dept(pk: Annotated[int, Path(...)]) -> ResponseSchemaModel[GetDeptDetail]:
20-
dept = await dept_service.get(pk=pk)
21-
data = GetDeptDetail(**select_as_dict(dept))
19+
data = await dept_service.get(pk=pk)
2220
return response_base.success(data=data)
2321

2422

backend/app/admin/api/v1/sys/dict_data.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
from backend.common.security.permission import RequestPermission
1313
from backend.common.security.rbac import DependsRBAC
1414
from backend.database.db import CurrentSession
15-
from backend.utils.serializers import select_as_dict
1615

1716
router = APIRouter()
1817

1918

2019
@router.get('/{pk}', summary='获取字典详情', dependencies=[DependsJwtAuth])
2120
async def get_dict_data(pk: Annotated[int, Path(...)]) -> ResponseSchemaModel[GetDictDataDetail]:
22-
dict_data = await dict_data_service.get(pk=pk)
23-
data = GetDictDataDetail(**select_as_dict(dict_data))
21+
data = await dict_data_service.get(pk=pk)
2422
return response_base.success(data=data)
2523

2624

backend/app/admin/api/v1/sys/menu.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from backend.common.security.jwt import DependsJwtAuth
1111
from backend.common.security.permission import RequestPermission
1212
from backend.common.security.rbac import DependsRBAC
13-
from backend.utils.serializers import select_as_dict
1413

1514
router = APIRouter()
1615

@@ -23,8 +22,7 @@ async def get_user_sidebar_tree(request: Request) -> ResponseSchemaModel[list[di
2322

2423
@router.get('/{pk}', summary='获取菜单详情', dependencies=[DependsJwtAuth])
2524
async def get_menu(pk: Annotated[int, Path(...)]) -> ResponseSchemaModel[GetMenuDetail]:
26-
menu = await menu_service.get(pk=pk)
27-
data = GetMenuDetail(**select_as_dict(menu))
25+
data = await menu_service.get(pk=pk)
2826
return response_base.success(data=data)
2927

3028

backend/app/admin/api/v1/sys/role.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,19 @@
2020
from backend.common.security.permission import RequestPermission
2121
from backend.common.security.rbac import DependsRBAC
2222
from backend.database.db import CurrentSession
23-
from backend.utils.serializers import select_as_dict, select_list_serialize
2423

2524
router = APIRouter()
2625

2726

2827
@router.get('/all', summary='获取所有角色', dependencies=[DependsJwtAuth])
2928
async def get_all_roles() -> ResponseSchemaModel[list[GetRoleDetail]]:
30-
roles = await role_service.get_all()
31-
data = select_list_serialize(roles)
29+
data = await role_service.get_all()
3230
return response_base.success(data=data)
3331

3432

3533
@router.get('/{pk}/all', summary='获取用户所有角色', dependencies=[DependsJwtAuth])
3634
async def get_user_all_roles(pk: Annotated[int, Path(...)]) -> ResponseSchemaModel[list[GetRoleDetail]]:
37-
roles = await role_service.get_by_user(pk=pk)
38-
data = select_list_serialize(roles)
35+
data = await role_service.get_by_user(pk=pk)
3936
return response_base.success(data=data)
4037

4138

@@ -53,8 +50,7 @@ async def get_role_all_rules(pk: Annotated[int, Path(...)]) -> ResponseSchemaMod
5350

5451
@router.get('/{pk}', summary='获取角色详情', dependencies=[DependsJwtAuth])
5552
async def get_role(pk: Annotated[int, Path(...)]) -> ResponseSchemaModel[GetRoleDetail]:
56-
role = await role_service.get(pk=pk)
57-
data = GetRoleDetail(**select_as_dict(role))
53+
data = await role_service.get(pk=pk)
5854
return response_base.success(data=data)
5955

6056

backend/app/admin/api/v1/sys/user.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from backend.common.security.permission import RequestPermission
2222
from backend.common.security.rbac import DependsRBAC
2323
from backend.database.db import CurrentSession
24-
from backend.utils.serializers import select_as_dict
2524

2625
router = APIRouter()
2726

@@ -35,8 +34,7 @@ async def register_user(obj: RegisterUserParam) -> ResponseModel:
3534
@router.post('/add', summary='添加用户', dependencies=[DependsRBAC])
3635
async def add_user(request: Request, obj: AddUserParam) -> ResponseSchemaModel[GetUserInfoDetail]:
3736
await user_service.add(request=request, obj=obj)
38-
current_user = await user_service.get_userinfo(username=obj.username)
39-
data = GetUserInfoDetail(**select_as_dict(current_user))
37+
data = await user_service.get_userinfo(username=obj.username)
4038
return response_base.success(data=data)
4139

4240

@@ -56,8 +54,7 @@ async def get_current_user(request: Request) -> ResponseSchemaModel[GetCurrentUs
5654

5755
@router.get('/{username}', summary='查看用户信息', dependencies=[DependsJwtAuth])
5856
async def get_user(username: Annotated[str, Path(...)]) -> ResponseSchemaModel[GetUserInfoDetail]:
59-
current_user = await user_service.get_userinfo(username=username)
60-
data = GetUserInfoDetail(**select_as_dict(current_user))
57+
data = await user_service.get_userinfo(username=username)
6158
return response_base.success(data=data)
6259

6360

backend/app/generator/api/v1/gen_business.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,25 @@
1616
from backend.common.security.jwt import DependsJwtAuth
1717
from backend.common.security.permission import RequestPermission
1818
from backend.common.security.rbac import DependsRBAC
19-
from backend.utils.serializers import select_as_dict, select_list_serialize
2019

2120
router = APIRouter()
2221

2322

2423
@router.get('/all', summary='获取所有代码生成业务', dependencies=[DependsJwtAuth])
2524
async def get_all_businesses() -> ResponseSchemaModel[list[GetGenBusinessDetail]]:
26-
businesses = await gen_business_service.get_all()
27-
data = select_list_serialize(businesses)
25+
data = await gen_business_service.get_all()
2826
return response_base.success(data=data)
2927

3028

3129
@router.get('/{pk}', summary='获取代码生成业务详情', dependencies=[DependsJwtAuth])
3230
async def get_business(pk: Annotated[int, Path(...)]) -> ResponseSchemaModel[GetGenBusinessDetail]:
33-
business = await gen_business_service.get(pk=pk)
34-
data = GetGenBusinessDetail(**select_as_dict(business))
31+
data = await gen_business_service.get(pk=pk)
3532
return response_base.success(data=data)
3633

3734

3835
@router.get('/{pk}/models', summary='获取代码生成业务所有模型', dependencies=[DependsJwtAuth])
3936
async def get_business_all_models(pk: Annotated[int, Path(...)]) -> ResponseSchemaModel[list[GetGenModelDetail]]:
40-
models = await gen_model_service.get_by_business(business_id=pk)
41-
data = select_list_serialize(models)
37+
data = await gen_model_service.get_by_business(business_id=pk)
4238
return response_base.success(data=data)
4339

4440

backend/app/generator/api/v1/gen_model.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from backend.common.security.jwt import DependsJwtAuth
1111
from backend.common.security.permission import RequestPermission
1212
from backend.common.security.rbac import DependsRBAC
13-
from backend.utils.serializers import select_as_dict
1413

1514
router = APIRouter()
1615

@@ -23,8 +22,7 @@ async def get_model_types() -> ResponseSchemaModel[list[str]]:
2322

2423
@router.get('/{pk}', summary='获取代码生成模型详情', dependencies=[DependsJwtAuth])
2524
async def get_model(pk: Annotated[int, Path(...)]) -> ResponseSchemaModel[GetGenModelDetail]:
26-
model = await gen_model_service.get(pk=pk)
27-
data = GetGenModelDetail(**select_as_dict(model))
25+
data = await gen_model_service.get(pk=pk)
2826
return response_base.success(data=data)
2927

3028

backend/app/generator/schema/gen_business.py

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from pydantic import ConfigDict, Field, model_validator
66
from typing_extensions import Self
77

8-
from backend.app.generator.schema.gen_model import GetGenModelDetail
98
from backend.common.schema import SchemaBase
109

1110

@@ -42,4 +41,3 @@ class GetGenBusinessDetail(GenBusinessSchemaBase):
4241
id: int
4342
created_time: datetime
4443
updated_time: datetime | None = None
45-
gen_model: list[GetGenModelDetail] | None = None

0 commit comments

Comments
 (0)