Files
FastapiAdmin/backend/app/api/v1/module_system/tenant/crud.py
T
zhangtao a462ab5793 feat: 实现软删除功能并添加相关字段
在全局类型定义、模型、CRUD操作中添加软删除支持
- 在BaseModel中添加is_deleted和deleted_time字段
- 在UserMixin中添加deleted_id和deleted_by关联
- 修改CRUDBase的delete和clear方法实现软删除逻辑
- 更新所有相关模型添加deleted_by字段
- 修改前端接口定义添加deleted_by字段
- 移除冗余的成功提示消息
2026-04-19 23:08:27 +08:00

60 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)