refactor: move services to a unit of work over repository ports
Services depend only on src/core/ports: async with self.uow is one transaction, commit is explicit, leaving without it rolls back. A connection is held per step, the JSON routers keep a shared request deadline, and rollback runs under the block deadline. Adds service-tests with fakes, a repo contract run on both the fake and SQL, and make service_test / service_test_db. API, schema and settings are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import abc
|
||||
from uuid import UUID
|
||||
|
||||
from src.schemas import dataclasses
|
||||
from src.utils.cursor import CursorKey
|
||||
|
||||
|
||||
class AbstractChatRepository(abc.ABC):
|
||||
@abc.abstractmethod
|
||||
async def insert_chat(
|
||||
self,
|
||||
*,
|
||||
chat: dataclasses.ChatFullDTO,
|
||||
) -> dataclasses.ChatFullDTO:
|
||||
"""Только строка чата; участников пишет `insert_chat_members`."""
|
||||
|
||||
@abc.abstractmethod
|
||||
async def insert_chat_members(
|
||||
self,
|
||||
*,
|
||||
chat: dataclasses.ChatFullDTO,
|
||||
) -> int:
|
||||
"""Все участники одной вставкой, позиция — порядок в `member_ids`;
|
||||
результат — число строк."""
|
||||
|
||||
@abc.abstractmethod
|
||||
async def get_chat(
|
||||
self,
|
||||
*,
|
||||
chat_id: UUID,
|
||||
) -> dataclasses.ChatFullDTO | None:
|
||||
"""Чат с участниками в порядке создания; `None` — чата нет."""
|
||||
|
||||
@abc.abstractmethod
|
||||
async def get_user_chats_page(
|
||||
self,
|
||||
*,
|
||||
user_id: UUID,
|
||||
after: CursorKey | None,
|
||||
limit: int,
|
||||
) -> list[dataclasses.ChatFullDTO]:
|
||||
"""До `limit + 1` чатов пользователя строго после ключа `after`, в
|
||||
порядке `(created_at, id)`."""
|
||||
Reference in New Issue
Block a user