Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions backend/app/admin/api/v1/sys/data_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
router = APIRouter()


@router.get('/all', summary='获取所有数据范围', dependencies=[DependsJwtAuth])
async def get_all_data_scope() -> ResponseSchemaModel[list[GetDataScopeDetail]]:
data = await data_scope_service.get_all()
return response_base.success(data=data)


@router.get('/{pk}', summary='获取数据范围详情', dependencies=[DependsJwtAuth])
async def get_data_scope(
pk: Annotated[int, Path(description='数据范围 ID')],
Expand Down
11 changes: 11 additions & 0 deletions backend/app/admin/crud/crud_data_scope.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Sequence

from sqlalchemy import Select, and_, desc, select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import noload, selectinload
Expand Down Expand Up @@ -44,6 +46,15 @@ async def get_with_relation(self, db: AsyncSession, pk: int) -> DataScope:
data_scope = await db.execute(stmt)
return data_scope.scalars().first()

async def get_all(self, db: AsyncSession) -> Sequence[DataScope]:
"""
获取所有数据范围

:param db: 数据库会话
:return:
"""
return await self.select_models(db)

async def get_list(self, name: str | None, status: int | None) -> Select:
"""
获取数据范围列表
Expand Down
9 changes: 9 additions & 0 deletions backend/app/admin/service/data_scope_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Sequence

from sqlalchemy import Select

from backend.app.admin.crud.crud_data_scope import data_scope_dao
Expand Down Expand Up @@ -28,6 +30,13 @@ async def get(*, pk: int) -> DataScope:
raise errors.NotFoundError(msg='数据范围不存在')
return data_scope

@staticmethod
async def get_all() -> Sequence[DataScope]:
"""获取所有数据范围"""
async with async_db_session() as db:
data_scopes = await data_scope_dao.get_all(db)
return data_scopes

@staticmethod
async def get_rules(*, pk: int) -> DataScope:
"""
Expand Down