1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- from typing import Sequence
- from app.admin.crud.crud_org import org_dao
- from model.org import Org
- from app.admin.schema.org import CreateOrgParam, UpdateOrgParam
- from common.exception import errors
- from database.db_mysql import async_db_session
- from sqlalchemy import Select
- class OrgService:
- @staticmethod
- async def get(*, pk: int) -> Org:
- async with async_db_session() as db:
- org = await org_dao.get(db, pk)
- if not org:
- raise errors.NotFoundError(msg='org 不存在')
- return org
- @staticmethod
- async def get_select() -> Select:
- return await org_dao.get_list()
- @staticmethod
- async def get_all() -> Sequence[Org]:
- async with async_db_session() as db:
- org = await org_dao.get_all(db)
- return org
- @staticmethod
- async def create(*, obj: CreateOrgParam) -> None:
- async with async_db_session.begin() as db:
- await org_dao.create(db, obj)
- @staticmethod
- async def update(*, pk: int, obj: UpdateOrgParam) -> int:
- async with async_db_session.begin() as db:
- count = await org_dao.update(db, pk, obj)
- return count
- @staticmethod
- async def delete(*, pk: list[int]) -> int:
- async with async_db_session.begin() as db:
- count = await org_dao.delete(db, pk)
- return count
- org_service: OrgService = OrgService()
|