master/repository/chat.py
2026-04-07 20:58:30 +03:00

24 lines
715 B
Python

from uuid import UUID
from domain.chat import Chat
from usecase.interface import ChatRepository
class InMemoryChatRepository(ChatRepository):
def __init__(self) -> None:
self._by_id: dict[UUID, Chat] = {}
def get(self, chat_id: UUID) -> Chat | None:
return self._by_id.get(chat_id)
def list_by_workspace_id(self, workspace_id: UUID) -> list[Chat]:
return sorted(
(c for c in self._by_id.values() if c.workspace_id == workspace_id),
key=lambda c: (c.created_at, c.chat_id),
)
def save(self, chat: Chat) -> None:
self._by_id[chat.chat_id] = chat
def delete(self, chat_id: UUID) -> None:
self._by_id.pop(chat_id, None)