You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
# backend/app/connectors/finance/mock.py — 시드 기반 finance sync (phase-13)
|
|
from datetime import UTC, datetime
|
|
|
|
from sqlmodel import Session
|
|
|
|
from ..base import BaseConnector, NormalizedRecord, RawRecord
|
|
from .normalize import normalize_tx, upsert_tx
|
|
|
|
_SIM = [
|
|
{
|
|
"id": "sim-ftx1",
|
|
"date": "2026-06-08",
|
|
"merchant": "스타벅스 강남R점",
|
|
"amount": 6300,
|
|
"category": "카페·간식",
|
|
}
|
|
]
|
|
|
|
|
|
class MockFinanceConnector(BaseConnector):
|
|
domain = "finance"
|
|
entity_type = "finance_tx"
|
|
|
|
def fetch(self, session: Session, *, full: bool = False):
|
|
for p in getattr(self, "_sim_payloads", []):
|
|
yield RawRecord(
|
|
external_id=p["id"],
|
|
payload=p,
|
|
etag=str(p.get("amount", "")),
|
|
external_updated_at=datetime.now(UTC),
|
|
)
|
|
|
|
def simulate_new(self) -> "MockFinanceConnector":
|
|
self._sim_payloads = _SIM
|
|
return self
|
|
|
|
def normalize(self, raw: RawRecord) -> NormalizedRecord:
|
|
return normalize_tx(self.account, raw)
|
|
|
|
def write(self, session: Session, norm: NormalizedRecord):
|
|
return upsert_tx(session, norm)
|
|
|
|
def event_for(self, norm, entity_id):
|
|
return "finance.transaction"
|