Forward the lab 4 foundation and migrate the lab 5 pipeline to SQLAlchemy

This commit is contained in:
Artyom
2026-11-06 09:12:25 +03:00
parent ae9f60fe1f
commit 1217da5f5e
134 changed files with 8243 additions and 1409 deletions
+9 -2
View File
@@ -9,6 +9,7 @@ from messenger.messaging.application.ports import (
AttachmentStates,
ChatDirectory,
CursorCodec,
MessageLog,
MessagingUnitOfWork,
)
from messenger.messaging.application.queries import GetChat, ListChats, ReadHistory
@@ -16,6 +17,7 @@ from messenger.messaging.config import MessagingSettings
from messenger.messaging.infrastructure.cursor import SignedCursorCodec
from messenger.messaging.infrastructure.postgres import (
PostgresChatDirectory,
PostgresMessageLog,
PostgresMessagingUnitOfWork,
)
from messenger.shared.application.commands import Command
@@ -37,6 +39,10 @@ class MessagingProvider(Provider):
def directory(self, database: Database) -> ChatDirectory:
return PostgresChatDirectory(database)
@provide(scope=Scope.APP)
def log(self, database: Database, attachments: AttachmentStates) -> MessageLog:
return PostgresMessageLog(database, attachments)
@provide(scope=Scope.APP)
def cursors(self, settings: MessagingSettings) -> CursorCodec:
return SignedCursorCodec(settings.cursor_secret.get_secret_value().encode())
@@ -61,7 +67,8 @@ class MessagingProvider(Provider):
def command_bus(
self,
uow: MessagingUnitOfWork,
attachments: AttachmentStates,
log: MessageLog,
directory: ChatDirectory,
publisher: EventPublisher,
clock: Clock,
ids: IdGenerator,
@@ -70,6 +77,6 @@ class MessagingProvider(Provider):
ttl = timedelta(seconds=settings.idempotency_ttl_seconds)
handlers: dict[type[Command], CommandHandler] = {
CreateChat: CreateChatHandler(uow, clock, ids),
PostMessage: PostMessageHandler(uow, attachments, clock, ids, ttl),
PostMessage: PostMessageHandler(uow, log, directory, clock, ids, ttl=ttl),
}
return MessagingCommandBus(handlers, uow, publisher)
@@ -37,7 +37,7 @@ class CreateMessageRequest(BaseModel):
class PageQuery(BaseModel):
limit: int = Field(default=50, ge=1, le=100)
cursor: str | None = None
cursor: str | None = Field(default=None, min_length=1)
class ChatOut(BaseModel):