细节优化——1
This commit is contained in:
@@ -40,6 +40,7 @@ async def list_logs(
|
||||
entity_type: str | None = None,
|
||||
entity_id: uuid.UUID | None = None,
|
||||
action: str | None = None,
|
||||
operator_id: uuid.UUID | None = None,
|
||||
skip: int = 0,
|
||||
limit: int = 100,
|
||||
) -> Sequence[AuditLog]:
|
||||
@@ -50,6 +51,18 @@ async def list_logs(
|
||||
stmt = stmt.where(AuditLog.entity_id == entity_id)
|
||||
if action:
|
||||
stmt = stmt.where(AuditLog.action == action)
|
||||
if operator_id:
|
||||
stmt = stmt.where(AuditLog.operator_id == operator_id)
|
||||
stmt = stmt.order_by(AuditLog.created_at.desc()).offset(skip).limit(limit)
|
||||
result = await db.execute(stmt)
|
||||
return result.scalars().all()
|
||||
|
||||
|
||||
async def get_log(db: AsyncSession, log_id: uuid.UUID) -> AuditLog | None:
|
||||
result = await db.execute(select(AuditLog).where(AuditLog.id == log_id))
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def delete_log(db: AsyncSession, log: AuditLog) -> None:
|
||||
await db.delete(log)
|
||||
await db.commit()
|
||||
|
||||
Reference in New Issue
Block a user