Skip to content

Commit c1c4c11

Browse files
committed
Add the dict type query all interface
1 parent 8420ccf commit c1c4c11

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

backend/plugin/dict/api/v1/sys/dict_type.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
router = APIRouter()
2222

2323

24+
@router.get('/all', summary='获取所有字典数据', dependencies=[DependsJwtAuth])
25+
async def get_all_dict_types() -> ResponseSchemaModel[list[GetDictTypeDetail]]:
26+
data = await dict_type_service.get_all()
27+
return response_base.success(data=data)
28+
29+
2430
@router.get('/{pk}', summary='获取字典类型详情', dependencies=[DependsJwtAuth])
2531
async def get_dict_type(
2632
pk: Annotated[int, Path(description='字典类型 ID')],

backend/plugin/dict/crud/crud_dict_type.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
3+
from typing import Sequence
4+
35
from sqlalchemy import Select
46
from sqlalchemy.ext.asyncio import AsyncSession
57
from sqlalchemy_crud_plus import CRUDPlus
@@ -21,6 +23,15 @@ async def get(self, db: AsyncSession, pk: int) -> DictType | None:
2123
"""
2224
return await self.select_model(db, pk)
2325

26+
async def get_all(self, db: AsyncSession) -> Sequence[DictType]:
27+
"""
28+
获取所有字典类型
29+
30+
:param db: 数据库会话
31+
:return:
32+
"""
33+
return await self.select_models(db, load_strategies={'datas': 'noload'})
34+
2435
async def get_list(self, *, name: str | None, code: str | None, status: int | None) -> Select:
2536
"""
2637
获取字典类型列表

backend/plugin/dict/service/dict_type_service.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
3+
from typing import Sequence
4+
35
from sqlalchemy import Select
46

57
from backend.common.exception import errors
@@ -26,6 +28,12 @@ async def get(*, pk) -> DictType:
2628
raise errors.NotFoundError(msg='字典类型不存在')
2729
return dict_type
2830

31+
@staticmethod
32+
async def get_all() -> Sequence[DictType]:
33+
async with async_db_session() as db:
34+
dict_datas = await dict_type_dao.get_all(db)
35+
return dict_datas
36+
2937
@staticmethod
3038
async def get_select(*, name: str | None, code: str | None, status: int | None) -> Select:
3139
"""

0 commit comments

Comments
 (0)