Skip to content
This repository has been archived by the owner on Jan 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #56 from Clariteia/0.2.0
Browse files Browse the repository at this point in the history
0.2.0
  • Loading branch information
Sergio García Prado authored Nov 15, 2021
2 parents 6f509b4 + 70ca1cb commit ca87440
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 390 deletions.
10 changes: 9 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@

* Be compatible with the `^0.1.1` version of `minos-microservice-saga`.

## 0.0.7 (2021-11-08)
## 0.1.0 (2021-11-08)

* Add `minos-microservice-common>=0.2.0` compatibility.

## 0.2.0 (2021-11-15)

* Migrate "Get Aggregate" handler functions (previously defined on `CommandService`) to `minos.aggregate.SnapshotService`.
* Add compatibility with `minos-microservice-common^=0.3.0`
* Add compatibility with `minos-microservice-networks^=0.2.0`
* Add compatibility with `minos-microservice-saga^=0.3.0`
* Add compatibility with `minos-microservice-aggregate^=0.2.0`
2 changes: 1 addition & 1 deletion minos/cqrs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__author__ = """Clariteia Devs"""
__email__ = "[email protected]"
__version__ = "0.1.0"
__version__ = "0.2.0"

from .exceptions import (
MinosCqrsException,
Expand Down
6 changes: 4 additions & 2 deletions minos/cqrs/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ModelRefInjector,
)
from minos.saga import (
LocalSagaStep,
RemoteSagaStep,
Saga,
SagaContext,
Expand Down Expand Up @@ -81,9 +82,10 @@ def build_saga(cls, diff: AggregateDiff) -> Saga:
)
for name, uuids in missing.items()
]
commit = SagaOperation(cls.commit, diff=diff)
# noinspection PyTypeChecker
steps.append(LocalSagaStep(on_execute=SagaOperation(cls.commit, diff=diff)))

saga = Saga(steps=steps, commit=commit)
saga = Saga(steps=steps, committed=True)

return saga

Expand Down
70 changes: 0 additions & 70 deletions minos/cqrs/services.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from abc import (
ABC,
)
from asyncio import (
gather,
)
from functools import (
partial,
)
Expand All @@ -12,36 +9,19 @@
isfunction,
ismethod,
)
from typing import (
Type,
)
from uuid import (
UUID,
)

from cached_property import (
cached_property,
)
from dependency_injector.wiring import (
Provide,
inject,
)

from minos.aggregate import (
Aggregate,
)
from minos.common import (
MinosConfig,
ModelType,
import_module,
)
from minos.networks import (
EnrouteDecorator,
Request,
Response,
ResponseException,
WrappedRequest,
enroute,
)
from minos.saga import (
SagaManager,
Expand Down Expand Up @@ -94,56 +74,6 @@ def _pre_event_handle(self, request: Request) -> Request:
fn = partial(PreEventHandler.handle, saga_manager=self.saga_manager, user=request.user)
return WrappedRequest(request, fn)

@classmethod
def __get_enroute__(cls, config: MinosConfig) -> dict[str, set[EnrouteDecorator]]:
aggregate_name = config.service.aggregate.rsplit(".", 1)[-1]
additional = {
cls.__get_aggregate__.__name__: {enroute.broker.command(f"Get{aggregate_name}")},
cls.__get_aggregates__.__name__: {enroute.broker.command(f"Get{aggregate_name}s")},
}
return super().__get_enroute__(config) | additional

async def __get_aggregate__(self, request: Request) -> Response:
"""Get aggregate.
:param request: The ``Request`` instance that contains the aggregate identifier.
:return: A ``Response`` instance containing the requested aggregate.
"""
try:
content = await request.content(model_type=ModelType.build("Query", {"uuid": UUID}))
except Exception as exc:
raise ResponseException(f"There was a problem while parsing the given request: {exc!r}")

try:
aggregate = await self.__aggregate_cls__.get(content["uuid"])
except Exception as exc:
raise ResponseException(f"There was a problem while getting the aggregate: {exc!r}")

return Response(aggregate)

async def __get_aggregates__(self, request: Request) -> Response:
"""Get aggregates.
:param request: The ``Request`` instance that contains the product identifiers.
:return: A ``Response`` instance containing the requested aggregates.
"""
try:
content = await request.content(model_type=ModelType.build("Query", {"uuids": list[UUID]}))
except Exception as exc:
raise ResponseException(f"There was a problem while parsing the given request: {exc!r}")

try:
aggregates = await gather(*(self.__aggregate_cls__.get(uuid) for uuid in content["uuids"]))
except Exception as exc:
raise ResponseException(f"There was a problem while getting aggregates: {exc!r}")

return Response(aggregates)

@cached_property
def __aggregate_cls__(self) -> Type[Aggregate]:
# noinspection PyTypeChecker
return import_module(self.config.service.aggregate)


class QueryService(Service, ABC):
"""Query Service class"""
Expand Down
Loading

0 comments on commit ca87440

Please sign in to comment.