mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-09-21 21:15:13 +00:00
Add the dict type query all interface (#794)
This commit is contained in:
@@ -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')],
|
||||
|
||||
@@ -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:
|
||||
"""
|
||||
获取字典类型列表
|
||||
|
||||
@@ -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:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user