Skip to content

Commit

Permalink
Merge branch '1-0-0' into 'main'
Browse files Browse the repository at this point in the history
added getAggregateRootMappingsForProjectionId

See merge request fluxlabs/flux-eco/projection!3
  • Loading branch information
mstuder committed Apr 9, 2022
2 parents ca6926f + 6097825 commit 6f40fdb
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 83 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## [1.1.0]
* added getAggregateRootMappingsForProjectionId

## [1.0.0]
* added functional usage

Expand Down
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ echo "getItem: ".PHP_EOL;
$item = fluxProjection\getItem($projectionName, $projectionId);
print_r($item).PHP_EOL.PHP_EOL;
//getAggregateRootMappingsForProjectionId
echo 'getAggregateRootMappingsForProjectionId '.PHP_EOL;
$mapping = fluxProjection\getAggregateRootMappingsForProjectionId($projectionId);
print_r($mapping).PHP_EOL.PHP_EOL;
```

output
Expand All @@ -163,29 +171,35 @@ Array
(
[0] => Array
(
[projectionId] => 99e14ce0-13fd-4e84-939a-13a4cf16ef5a
[firstname] => Emmett
[lastname] => Brown
)
[1] => Array
(
[projectionId] => 9cf98d18-faf3-46a9-bdbc-57341c3b304b
[projectionId] => ec6331f0-306a-48bc-9ac3-c11114e55bbf
[firstname] => Emmett
[lastname] => Brown
)
)
getProjectionIdForAggregateId
9cf98d18-faf3-46a9-bdbc-57341c3b304b
ec6331f0-306a-48bc-9ac3-c11114e55bbf
getItem:
Array
(
[projectionId] => 9cf98d18-faf3-46a9-bdbc-57341c3b304b
[projectionId] => ec6331f0-306a-48bc-9ac3-c11114e55bbf
[firstname] => Emmett
[lastname] => Brown
)
getAggregateRootMappingsForProjectionId
Array
(
[0] => FluxEco\Projection\Adapters\AggregateRoot\AggregateRootMappingAdapter Object
(
[projectionName:FluxEco\Projection\Adapters\AggregateRoot\AggregateRootMappingAdapter:private] => account
[projectionId:FluxEco\Projection\Adapters\AggregateRoot\AggregateRootMappingAdapter:private] => ec6331f0-306a-48bc-9ac3-c11114e55bbf
[aggregateName:FluxEco\Projection\Adapters\AggregateRoot\AggregateRootMappingAdapter:private] => account
[aggregateId:FluxEco\Projection\Adapters\AggregateRoot\AggregateRootMappingAdapter:private] => 6a1e4b65-0810-4bb2-a120-6624be0a7107
[externalId:FluxEco\Projection\Adapters\AggregateRoot\AggregateRootMappingAdapter:private] =>
)
)
```

## Contributing :purple_heart:
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "flux-eco/projection",
"description": "Creates projections of aggregate root objects",
"version": "1.0.0",
"version": "1.1.0",
"type": "flux-app",
"keywords": [
"flux-eco",
Expand Down Expand Up @@ -49,7 +49,8 @@
"fn/getItemList.php",
"fn/getProjectionIdForExternalIdIfExists.php",
"fn/initialize.php",
"fn/receiveAggregateRootStatePublished.php"
"fn/receiveAggregateRootStatePublished.php",
"fn/getAggregateRootMappingsForProjectionId.php"
],
"psr-4": {
"FluxEco\\Projection\\": [
Expand Down
8 changes: 8 additions & 0 deletions examples/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@

print_r($item).PHP_EOL.PHP_EOL;


//getAggregateRootMappingsForProjectionId
echo 'getAggregateRootMappingsForProjectionId '.PHP_EOL;

$mapping = fluxProjection\getAggregateRootMappingsForProjectionId($projectionId);

print_r($mapping).PHP_EOL.PHP_EOL;

11 changes: 11 additions & 0 deletions fn/getAggregateRootMappingsForProjectionId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace fluxProjection;

use FluxEco\{Projection, Projection\Adapters};

/** @return Adapters\AggregateRoot\AggregateRootMappingAdapter[] */
function getAggregateRootMappingsForProjectionId(string $projectionId): array
{
return Projection\Api::newFromEnv()->getAggregateRootMappingsForProjectionId($projectionId);
}
68 changes: 68 additions & 0 deletions src/Adapters/AggregateRoot/AggregateRootMappingAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php


namespace FluxEco\Projection\Adapters\AggregateRoot;

use FluxEco\Projection\{Core\Domain};

class AggregateRootMappingAdapter
{
private string $projectionName;
private string $projectionId;
private string $aggregateName;
private string $aggregateId;
private ?string $externalId;

private function __construct(
string $projectionName,
string $projectionId,
string $aggregateName,
string $aggregateId,
?string $externalId
)
{
$this->projectionName = $projectionName;
$this->projectionId = $projectionId;
$this->aggregateName = $aggregateName;
$this->aggregateId = $aggregateId;
$this->externalId = $externalId;
}

public static function fromDomain(
Domain\Models\AggregateRootMapping $aggregateRootMapping
): self
{
return new self(
$aggregateRootMapping->getProjectionName(),
$aggregateRootMapping->getProjectionId(),
$aggregateRootMapping->getAggregateName(),
$aggregateRootMapping->getAggregateId(),
$aggregateRootMapping->getExternalId()
);
}

final public function getAggregateName(): string
{
return $this->aggregateName;
}

final public function getAggregateId(): string
{
return $this->aggregateId;
}

public function getProjectionName() : string
{
return $this->projectionName;
}

public function getProjectionId() : string
{
return $this->projectionId;
}

public function getExternalId() : ?string
{
return $this->externalId;
}
}
63 changes: 0 additions & 63 deletions src/Adapters/AggregateRoot/RootObjectMapping.php

This file was deleted.

12 changes: 10 additions & 2 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@ final public function initialize(): void
$this->projectionService->initalizeProjectionStorages();
}

final public function getAggregateRootMappingsForProjectionId(string $projectionId): ?array {
return $this->projectionService->getAggregateRootMappingsForProjectionId($projectionId);
/** @return Adapters\AggregateRoot\AggregateRootMappingAdapter[] */
final public function getAggregateRootMappingsForProjectionId(string $projectionId): array {
$aggregateRootMappings = $this->projectionService->getAggregateRootMappingsForProjectionId($projectionId);

$return = [];
foreach($aggregateRootMappings as $aggregateRootMapping) {
$return[] = Adapters\AggregateRoot\AggregateRootMappingAdapter::fromDomain($aggregateRootMapping);
}

return $return;
}

final public function receiveAggregateRootStatePublished(
Expand Down
13 changes: 7 additions & 6 deletions src/Core/Ports/ProjectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,18 @@ final public function getAggregateRootMappingsForAggregateId(string $aggregateId
/** @return ?Domain\Models\AggregateRootMapping[] */
final public function getAggregateRootMappingsForProjectionId(string $projectionId) : ?array
{
$projectionName = $this->outbounds->getAggregateRootMappingProjectionName();
$projectionSchema = $this->getProjectionSchema($projectionName);
$mappingProjectionName = $this->outbounds->getAggregateRootMappingProjectionName();
$mappingProjectionSchema = $this->getProjectionSchema($mappingProjectionName);
$filter = ['projectionId' => $projectionId];
$result = $this->outbounds->queryProjectionStorage($projectionName, $projectionSchema, $filter);
$result = $this->outbounds->queryProjectionStorage($mappingProjectionName, $mappingProjectionSchema, $filter);
if (count($result) > 0) {
$aggregateRootMappings = [];
foreach ($result as $key => $value) {
$aggregateRootMappings[] = RootObjectMapping::new(
$aggregateRootMappings[] = Domain\Models\AggregateRootMapping::new(
$value['projectionName'],
$value['projectionId'],
$value['aggregateName'],
$value['aggregateId'],
[]
$value['aggregateId']
);
}
return $aggregateRootMappings;
Expand Down

0 comments on commit 6f40fdb

Please sign in to comment.