auto_agent/backend/app/repositories/audit_repository.py

22 lines
633 B
Python

from __future__ import annotations
from sqlalchemy import select
from sqlalchemy.orm import Session
from app.models.audit_log import AuditLog
class AuditRepository:
def __init__(self, db: Session) -> None:
self.db = db
def add(self, audit_log: AuditLog) -> AuditLog:
self.db.add(audit_log)
self.db.commit()
self.db.refresh(audit_log)
return audit_log
def list_by_task_id(self, task_id: str) -> list[AuditLog]:
statement = select(AuditLog).where(AuditLog.task_id == task_id).order_by(AuditLog.timestamp.asc())
return list(self.db.execute(statement).scalars())