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.3 KiB
Python
45 lines
1.3 KiB
Python
# backend/app/connectors/chat/mock.py — 시드 기반 chat sync (phase-13)
|
|
from datetime import UTC, datetime
|
|
|
|
from sqlmodel import Session
|
|
|
|
from ..base import BaseConnector, NormalizedRecord, RawRecord
|
|
from .normalize import normalize_chat, upsert_chat
|
|
|
|
_SIM = [
|
|
{
|
|
"id": "sim-c1",
|
|
"sender": "minseo",
|
|
"text": "지우님, 분기 전략 미팅 자료 공유 가능할까요?",
|
|
"channel": "#팀-운영",
|
|
"at": "오늘 14:02",
|
|
}
|
|
]
|
|
|
|
|
|
class MockChatConnector(BaseConnector):
|
|
domain = "chat"
|
|
entity_type = "chat_message"
|
|
|
|
def fetch(self, session: Session, *, full: bool = False):
|
|
for p in getattr(self, "_sim_payloads", []):
|
|
yield RawRecord(
|
|
external_id=p["id"],
|
|
payload=p,
|
|
etag=p.get("at", ""),
|
|
external_updated_at=datetime.now(UTC),
|
|
)
|
|
|
|
def simulate_new(self) -> "MockChatConnector":
|
|
self._sim_payloads = _SIM
|
|
return self
|
|
|
|
def normalize(self, raw: RawRecord) -> NormalizedRecord:
|
|
return normalize_chat(self.account, raw)
|
|
|
|
def write(self, session: Session, norm: NormalizedRecord):
|
|
return upsert_chat(session, norm)
|
|
|
|
def event_for(self, norm, entity_id):
|
|
return "chat.message"
|