diff --git a/microservice/language/python/init/config.yml.jinja b/microservice/language/python/init/config.yml.jinja index 6ca480e..af0d649 100644 --- a/microservice/language/python/init/config.yml.jinja +++ b/microservice/language/python/init/config.yml.jinja @@ -4,17 +4,15 @@ service: injections: lock_pool: minos.common.PostgreSqlLockPool postgresql_pool: minos.common.PostgreSqlPool - broker_publisher: minos.networks.BrokerPublisher - broker_consumer: minos.networks.BrokerConsumer - broker_pool: minos.networks.DynamicBrokerPool + broker_publisher: minos.plugins.kafka.InMemoryQueuedKafkaBrokerPublisher + broker_subscriber_builder: minos.plugins.kafka.InMemoryQueuedKafkaBrokerSubscriberBuilder + broker_pool: minos.networks.BrokerClientPool transaction_repository: minos.aggregate.PostgreSqlTransactionRepository event_repository: minos.aggregate.PostgreSqlEventRepository snapshot_repository: minos.aggregate.PostgreSqlSnapshotRepository saga_manager: minos.saga.SagaManager discovery: minos.networks.DiscoveryConnector services: - - minos.networks.BrokerProducerService - - minos.networks.BrokerConsumerService - minos.networks.BrokerHandlerService - minos.networks.RestService - minos.networks.PeriodicTaskSchedulerService @@ -56,6 +54,6 @@ saga: storage: path: ./{{ name }}.lmdb discovery: - client: minos.networks.MinosDiscoveryClient + client: minos.plugins.minos_discovery.MinosDiscoveryClient host: localhost port: 5567 diff --git a/microservice/language/python/init/src/aggregates.py.jinja b/microservice/language/python/init/src/aggregates.py.jinja index 90e0d5a..5dddb6a 100644 --- a/microservice/language/python/init/src/aggregates.py.jinja +++ b/microservice/language/python/init/src/aggregates.py.jinja @@ -1,7 +1,22 @@ +from uuid import ( + UUID, +) + from minos.aggregate import ( Aggregate, + RootEntity, ) -class {{ aggregate }}(Aggregate): - """{{ aggregate }} Aggregate class.""" +class {{ aggregate }}(RootEntity): + """{{ aggregate }} RootEntity class.""" + + +class {{ aggregate }}Aggregate(Aggregate[{{ aggregate }}]): + """{{ aggregate }}Aggregate class.""" + + @staticmethod + async def create() -> UUID: + """Create a new instance.""" + root = await {{ aggregate }}.create() + return root.uuid diff --git a/microservice/language/python/init/src/commands/services.py.jinja b/microservice/language/python/init/src/commands/services.py.jinja index 16619f1..efa7a36 100644 --- a/microservice/language/python/init/src/commands/services.py.jinja +++ b/microservice/language/python/init/src/commands/services.py.jinja @@ -9,7 +9,7 @@ from minos.networks import ( ) from ..aggregates import ( - {{ aggregate }}, + {{ aggregate }}Aggregate, ) @@ -25,7 +25,7 @@ class {{ aggregate }}CommandService(CommandService): :return: A ``Response`` instance. """ try: - instance = await {{ aggregate }}.create() - return Response({"uuid": instance.uuid }) + uuid = await {{ aggregate }}Aggregate.create() + return Response({"uuid": uuid}) except Exception as exc: raise ResponseException(f"An error occurred during {{ aggregate }} creation: {exc}") diff --git a/microservice/language/python/init/src/queries/services.py.jinja b/microservice/language/python/init/src/queries/services.py.jinja index 6c0bd9c..52af62f 100644 --- a/microservice/language/python/init/src/queries/services.py.jinja +++ b/microservice/language/python/init/src/queries/services.py.jinja @@ -1,5 +1,5 @@ from minos.aggregate import ( - AggregateDiff, + Event, ) from minos.cqrs import ( QueryService, @@ -31,8 +31,8 @@ class {{ aggregate }}QueryService(QueryService): :param request: A request instance containing the aggregate difference. :return: This method does not return anything. """ - diff: AggregateDiff = await request.content() - print(diff) + event: Event = await request.content() + print(event) @enroute.broker.event("{{ aggregate }}Updated") async def {{ aggregate.lower() }}_updated(self, request: Request) -> None: @@ -41,8 +41,8 @@ class {{ aggregate }}QueryService(QueryService): :param request: A request instance containing the aggregate difference. :return: This method does not return anything. """ - diff: AggregateDiff = await request.content() - print(diff) + event: Event = await request.content() + print(event) @enroute.broker.event("{{ aggregate }}Deleted") async def {{ aggregate.lower() }}_deleted(self, request: Request) -> None: @@ -51,5 +51,5 @@ class {{ aggregate }}QueryService(QueryService): :param request: A request instance containing the aggregate difference. :return: This method does not return anything. """ - diff: AggregateDiff = await request.content() - print(diff) + event: Event = await request.content() + print(event) diff --git a/microservice/language/python/init/tests/test_commands/test_services.py.jinja b/microservice/language/python/init/tests/test_commands/test_services.py.jinja index ee705b8..45358a5 100644 --- a/microservice/language/python/init/tests/test_commands/test_services.py.jinja +++ b/microservice/language/python/init/tests/test_commands/test_services.py.jinja @@ -7,10 +7,10 @@ from src import ( ) from minos.networks import ( + InMemoryRequest, Response, ) from tests.utils import ( - _FakeRequest, build_dependency_injector, ) @@ -33,7 +33,7 @@ class Test{{aggregate}}CommandService(unittest.IsolatedAsyncioTestCase): async def test_create_{{ aggregate.lower() }}(self): service = {{ aggregate }}CommandService() - request = _FakeRequest({}) + request = InMemoryRequest({}) response = await service.create_{{ aggregate.lower() }}(request) self.assertIsInstance(response, Response) diff --git a/microservice/language/python/init/tests/utils.py b/microservice/language/python/init/tests/utils.py index 66e44aa..f066443 100644 --- a/microservice/language/python/init/tests/utils.py +++ b/microservice/language/python/init/tests/utils.py @@ -1,61 +1,24 @@ from __future__ import ( - annotations, ) + annotations, +) from pathlib import ( - Path, ) -from typing import ( - Optional, ) -from uuid import UUID -from uuid import uuid4 - -from minos.common import CommandReply -from minos.common import DependencyInjector -from minos.common import InMemoryRepository -from minos.common import InMemorySnapshot -from minos.common import MinosBroker -from minos.common import MinosConfig -from minos.common import MinosSagaManager -from minos.common import Model + Path, +) + +from minos.aggregate import ( + InMemoryTransactionRepository, + InMemoryEventRepository, + InMemorySnapshotRepository, +) +from minos.common import ( + DependencyInjector, + MinosConfig, +) from minos.networks import ( - Request, ) - - -class _FakeRequest(Request): - """For testing purposes""" - def __init__(self, content): - super().__init__() - self._content = content - self._user = uuid4() - - @property - def user(self) -> Optional[UUID]: - """For testing purposes""" - return self._user - - async def content(self, **kwargs): - """For testing purposes""" - return self._content - - def __eq__(self, other: _FakeRequest) -> bool: - return self._content == other._content and self.user == other.user - - def __repr__(self) -> str: - return str() - - -class _FakeBroker(MinosBroker): - """For testing purposes.""" - async def send(self, items: list[Model], **kwargs) -> None: - """For testing purposes.""" - - -class _FakeSagaManager(MinosSagaManager): - """For testing purposes.""" - async def _run_new(self, name: str, **kwargs) -> UUID: - """For testing purposes.""" - - async def _load_and_run(self, reply: CommandReply, **kwargs) -> UUID: - """For testing purposes.""" + InMemoryBrokerPublisher, + InMemoryBrokerSubscriberBuilder, +) def build_dependency_injector() -> DependencyInjector: @@ -63,10 +26,10 @@ def build_dependency_injector() -> DependencyInjector: return DependencyInjector( build_config(), - saga_manager=_FakeSagaManager, - event_broker=_FakeBroker, - repository=InMemoryRepository, - snapshot=InMemorySnapshot, + broker_publisher=InMemoryBrokerPublisher, + transaction_repository=InMemoryTransactionRepository, + event_repository=InMemoryEventRepository, + snapshot_snapshot=InMemorySnapshotRepository, ) diff --git a/microservice/language/python/package-manager/poetry/pyproject.toml.jinja b/microservice/language/python/package-manager/poetry/pyproject.toml.jinja index 52650aa..cb7c831 100644 --- a/microservice/language/python/package-manager/poetry/pyproject.toml.jinja +++ b/microservice/language/python/package-manager/poetry/pyproject.toml.jinja @@ -7,11 +7,13 @@ packages = [{ include = "src" }] [tool.poetry.dependencies] python = "^3.9" -minos-microservice-common = "^0.3.2" -minos-microservice-networks = "^0.3.2" -minos-microservice-aggregate = "^0.2.2" -minos-microservice-saga = "^0.3.5" -minos-microservice-cqrs = "^0.2.1" +minos-microservice-common = "^0.5.0" +minos-microservice-networks = "^0.5.0" +minos-microservice-aggregate = "^0.5.0" +minos-microservice-saga = "^0.5.0" +minos-microservice-cqrs = "^0.5.0" +minos-broker-kafka = "^0.5.0" +minos-discovery-minos = "^0.5.0" typer = "^0.3.2" [tool.poetry.dev-dependencies]