Files
FastapiAdmin/backend/app/api/v1/module_system/tenant/crud.py
T
zhangtao 329dd791d2 refactor(tenant): 移除租户工具模块并优化相关代码
重构租户模块,删除不再使用的工具类文件,包括查询、写入、缓存键等功能
优化模型字段格式和CRUD方法顺序,调整前端暗黑模式颜色变量
简化租户服务逻辑,移除平台租户管理校验,改进初始管理员创建流程
2026-04-08 00:06:20 +08:00

61 lines
2.0 KiB
Python

from collections.abc import Sequence
from typing import Any
from app.api.v1.module_system.auth.schema import AuthSchema
from app.core.base_crud import CRUDBase
from .model import TenantModel
from .schema import TenantCreateSchema, TenantOutSchema, TenantUpdateSchema
class TenantCRUD(CRUDBase[TenantModel, TenantCreateSchema, TenantUpdateSchema]):
"""租户数据层"""
def __init__(self, auth: AuthSchema) -> None:
self.auth = auth
super().__init__(model=TenantModel, auth=auth)
async def get_by_id_crud(
self, id: int, preload: list[str | Any] | None = None
) -> TenantModel | None:
return await self.get(id=id, preload=preload)
async def get_list_crud(
self,
search: dict | None = None,
order_by: list[dict[str, str]] | None = None,
preload: list[str | Any] | None = None,
) -> Sequence[TenantModel]:
return await self.list(search=search, order_by=order_by, preload=preload)
async def page_crud(
self,
offset: int,
limit: int,
order_by: list[dict[str, str]] | None,
search: dict | None = None,
out_schema: type[TenantOutSchema] | None = None,
preload: list[str | Any] | None = None,
) -> dict:
return await self.page(
offset=offset,
limit=limit,
order_by=order_by or [{"id": "asc"}],
search=search or {},
out_schema=out_schema or TenantOutSchema,
preload=preload or [],
)
async def create_crud(self, data: TenantCreateSchema) -> TenantModel | None:
return await self.create(data=data)
async def update_crud(self, id: int, data: TenantUpdateSchema) -> TenantModel | None:
return await self.update(id=id, data=data)
async def delete_crud(self, ids: list[int]) -> None:
await self.delete(ids=ids)
async def set_available_crud(self, ids: list[int], status: str) -> None:
await self.set(ids=ids, status=status)