mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-09-21 21:15:13 +00:00
Add dictionary type and datas queries (#679)
This commit is contained in:
@@ -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
|
||||
@@ -27,6 +29,12 @@ class DictDataService:
|
||||
raise errors.NotFoundError(msg='字典数据不存在')
|
||||
return dict_data
|
||||
|
||||
@staticmethod
|
||||
async def get_all() -> Sequence[DictData]:
|
||||
async with async_db_session() as db:
|
||||
dict_datas = await dict_data_dao.get_all(db)
|
||||
return dict_datas
|
||||
|
||||
@staticmethod
|
||||
async def get_select(*, label: str | None, value: str | None, status: int | None) -> Select:
|
||||
"""
|
||||
|
||||
@@ -5,12 +5,27 @@ from sqlalchemy import Select
|
||||
from backend.common.exception import errors
|
||||
from backend.database.db import async_db_session
|
||||
from backend.plugin.dict.crud.crud_dict_type import dict_type_dao
|
||||
from backend.plugin.dict.model import DictType
|
||||
from backend.plugin.dict.schema.dict_type import CreateDictTypeParam, DeleteDictTypeParam, UpdateDictTypeParam
|
||||
|
||||
|
||||
class DictTypeService:
|
||||
"""字典类型服务类"""
|
||||
|
||||
@staticmethod
|
||||
async def get(*, pk) -> DictType:
|
||||
"""
|
||||
获取字典类型详情
|
||||
|
||||
:param pk: 字典类型 ID
|
||||
:return:
|
||||
"""
|
||||
async with async_db_session() as db:
|
||||
dict_type = await dict_type_dao.get(db, pk)
|
||||
if not dict_type:
|
||||
raise errors.NotFoundError(msg='字典类型不存在')
|
||||
return dict_type
|
||||
|
||||
@staticmethod
|
||||
async def get_select(*, name: str | None, code: str | None, status: int | None) -> Select:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user