diff --git a/backend/plugin/dict/api/v1/sys/dict_type.py b/backend/plugin/dict/api/v1/sys/dict_type.py index 64ab0ed1..df36713c 100644 --- a/backend/plugin/dict/api/v1/sys/dict_type.py +++ b/backend/plugin/dict/api/v1/sys/dict_type.py @@ -21,6 +21,12 @@ from backend.plugin.dict.service.dict_type_service import dict_type_service router = APIRouter() +@router.get('/all', summary='获取所有字典数据', dependencies=[DependsJwtAuth]) +async def get_all_dict_types() -> ResponseSchemaModel[list[GetDictTypeDetail]]: + data = await dict_type_service.get_all() + return response_base.success(data=data) + + @router.get('/{pk}', summary='获取字典类型详情', dependencies=[DependsJwtAuth]) async def get_dict_type( pk: Annotated[int, Path(description='字典类型 ID')], diff --git a/backend/plugin/dict/crud/crud_dict_type.py b/backend/plugin/dict/crud/crud_dict_type.py index b74c3470..57569cdf 100644 --- a/backend/plugin/dict/crud/crud_dict_type.py +++ b/backend/plugin/dict/crud/crud_dict_type.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +from typing import Sequence + from sqlalchemy import Select from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy_crud_plus import CRUDPlus @@ -21,6 +23,15 @@ class CRUDDictType(CRUDPlus[DictType]): """ return await self.select_model(db, pk) + async def get_all(self, db: AsyncSession) -> Sequence[DictType]: + """ + 获取所有字典类型 + + :param db: 数据库会话 + :return: + """ + return await self.select_models(db, load_strategies={'datas': 'noload'}) + async def get_list(self, *, name: str | None, code: str | None, status: int | None) -> Select: """ 获取字典类型列表 diff --git a/backend/plugin/dict/service/dict_type_service.py b/backend/plugin/dict/service/dict_type_service.py index 827276ee..1fecfb7e 100644 --- a/backend/plugin/dict/service/dict_type_service.py +++ b/backend/plugin/dict/service/dict_type_service.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +from typing import Sequence + from sqlalchemy import Select from backend.common.exception import errors @@ -26,6 +28,12 @@ class DictTypeService: raise errors.NotFoundError(msg='字典类型不存在') return dict_type + @staticmethod + async def get_all() -> Sequence[DictType]: + async with async_db_session() as db: + dict_datas = await dict_type_dao.get_all(db) + return dict_datas + @staticmethod async def get_select(*, name: str | None, code: str | None, status: int | None) -> Select: """