31 lines
949 B
Python
31 lines
949 B
Python
from __future__ import annotations
|
|
|
|
from collections.abc import Sequence
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.db.models import ExternalRequestLog
|
|
from app.integrations.gateway import RequestRecord
|
|
|
|
|
|
class RequestLogRepository:
|
|
def __init__(self, session: AsyncSession) -> None:
|
|
self.session = session
|
|
|
|
async def add_many(self, records: Sequence[RequestRecord], user: str) -> None:
|
|
self.session.add_all(
|
|
ExternalRequestLog(
|
|
source=record.source,
|
|
endpoint=record.endpoint,
|
|
params=record.params,
|
|
http_status=record.http_status,
|
|
duration_ms=record.duration_ms,
|
|
ok=record.ok,
|
|
error=record.error,
|
|
gateway_transaction_id=record.transaction_id,
|
|
created_by=user,
|
|
)
|
|
for record in records
|
|
)
|
|
await self.session.flush()
|