ref #13: in-memory metadata repositories (S02)
This commit is contained in:
parent
5381c997e2
commit
6fe484c44c
4 changed files with 236 additions and 0 deletions
24
repository/chat.py
Normal file
24
repository/chat.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue