diff --git a/CHANGELOG.md b/CHANGELOG.md index 90519af..4bdd0be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +## [1.1.0] +* added getAggregateRootMappingsForProjectionId + ## [1.0.0] * added functional usage diff --git a/README.md b/README.md index 477669c..7b990ab 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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: diff --git a/composer.json b/composer.json index 370cf67..680a159 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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\\": [ diff --git a/examples/example.php b/examples/example.php index a4fd6a1..32995ef 100644 --- a/examples/example.php +++ b/examples/example.php @@ -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; + diff --git a/fn/getAggregateRootMappingsForProjectionId.php b/fn/getAggregateRootMappingsForProjectionId.php new file mode 100644 index 0000000..8b5a181 --- /dev/null +++ b/fn/getAggregateRootMappingsForProjectionId.php @@ -0,0 +1,11 @@ +getAggregateRootMappingsForProjectionId($projectionId); +} \ No newline at end of file diff --git a/src/Adapters/AggregateRoot/AggregateRootMappingAdapter.php b/src/Adapters/AggregateRoot/AggregateRootMappingAdapter.php new file mode 100644 index 0000000..65c8a84 --- /dev/null +++ b/src/Adapters/AggregateRoot/AggregateRootMappingAdapter.php @@ -0,0 +1,68 @@ +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; + } +} \ No newline at end of file diff --git a/src/Adapters/AggregateRoot/RootObjectMapping.php b/src/Adapters/AggregateRoot/RootObjectMapping.php deleted file mode 100644 index b91148a..0000000 --- a/src/Adapters/AggregateRoot/RootObjectMapping.php +++ /dev/null @@ -1,63 +0,0 @@ -aggregateName = $aggregateName; - $this->aggregateId = $aggregateId; - $this->properties = $properties; - } - - public static function new( - string $aggregateName, - string $aggregateId, - array $properties): self - { - return new self( - $aggregateName, - $aggregateId, - $properties - ); - } - - public static function fromDomain( - Domain\Models\RootObjectMapping $aggregateRootMapping - ): self - { - return new self( - $aggregateRootMapping->getAggregateName(), - $aggregateRootMapping->getAggregateId(), - $aggregateRootMapping->getProperties() - ); - } - - final public function getAggregateName(): string - { - return $this->aggregateName; - } - - final public function getAggregateId(): string - { - return $this->aggregateId; - } - - final public function getProperties(): array - { - return $this->properties; - } -} \ No newline at end of file diff --git a/src/Api.php b/src/Api.php index 406d026..a553d57 100644 --- a/src/Api.php +++ b/src/Api.php @@ -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( diff --git a/src/Core/Ports/ProjectionService.php b/src/Core/Ports/ProjectionService.php index 7317ccb..1083b73 100644 --- a/src/Core/Ports/ProjectionService.php +++ b/src/Core/Ports/ProjectionService.php @@ -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;