-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Antoine Lelaisant
committed
Nov 4, 2022
1 parent
fefd6cf
commit 95ccd9c
Showing
21 changed files
with
466 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ framework: | |
command.bus: | ||
middleware: | ||
- doctrine_transaction | ||
|
||
query.bus: ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
Domain\Query\: | ||
resource: '%kernel.project_dir%/src/Domain/Query/**/Handler.php' | ||
tags: | ||
- { name: messenger.message_handler, bus: query.bus } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/Application/Form/DataTransformer/SpeciesReadToModel.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Application\Form\DataTransformer; | ||
|
||
use Domain\Collection\SpeciesCollection; | ||
use Domain\Exception\SpeciesNotFoundException; | ||
use Domain\Model\Species as ModelSpecies; | ||
use Domain\ReadModel\Species; | ||
use Symfony\Component\Form\DataTransformerInterface; | ||
|
||
class SpeciesReadToModel implements DataTransformerInterface | ||
{ | ||
public function __construct( | ||
private SpeciesCollection $speciesCollection | ||
) { | ||
} | ||
|
||
public function transform(mixed $value) | ||
{ | ||
if (!$value instanceof Species) { | ||
return $value; | ||
} | ||
|
||
$speciesId = (string) $value->getId(); | ||
|
||
$species = $this->speciesCollection->find($speciesId); | ||
|
||
if ($species === null) { | ||
throw new SpeciesNotFoundException($speciesId); | ||
} | ||
|
||
return $species; | ||
} | ||
|
||
public function reverseTransform(mixed $value) | ||
{ | ||
if (!$value instanceof ModelSpecies) { | ||
return $value; | ||
} | ||
|
||
return new Species($value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Application\MessageBus; | ||
|
||
interface QueryBus | ||
{ | ||
public function dispatch(object $input): mixed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Domain\Query\GetAllDinosaurs; | ||
|
||
use Domain\Collection\DinosaursCollection; | ||
use Domain\Model\Dinosaur as ModelDinosaur; | ||
use Domain\ReadModel\Dinosaur; | ||
|
||
class Handler | ||
{ | ||
public function __construct( | ||
private DinosaursCollection $dinosaursCollection | ||
) { | ||
} | ||
|
||
public function __invoke(Query $query): array | ||
{ | ||
$dinosaurs = $this->dinosaursCollection->search($query->search); | ||
|
||
return array_map( | ||
fn (ModelDinosaur $dinosaur) => new Dinosaur($dinosaur), | ||
$dinosaurs | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Domain\Query\GetAllDinosaurs; | ||
|
||
final class Query | ||
{ | ||
public function __construct( | ||
public readonly ?string $search = null | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Domain\Query\GetAllSpecies; | ||
|
||
use Domain\Collection\SpeciesCollection; | ||
use Domain\Model\Species as ModelSpecies; | ||
use Domain\ReadModel\Species; | ||
|
||
class Handler | ||
{ | ||
public function __construct( | ||
private SpeciesCollection $speciesCollection | ||
) { | ||
} | ||
|
||
public function __invoke(Query $query): array | ||
{ | ||
$species = $this->speciesCollection->findAll(); | ||
|
||
return array_map( | ||
fn (ModelSpecies $species) => new Species($species), | ||
$species | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Domain\Query\GetAllSpecies; | ||
|
||
final class Query | ||
{ | ||
public function __construct( | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Domain\Query\GetSingleDinosaur; | ||
|
||
use Domain\Collection\DinosaursCollection; | ||
use Domain\Exception\DinosaurNotFoundException; | ||
use Domain\ReadModel\Dinosaur; | ||
|
||
class Handler | ||
{ | ||
public function __construct( | ||
private DinosaursCollection $dinosaursCollection | ||
) { | ||
} | ||
|
||
public function __invoke(Query $query): Dinosaur | ||
{ | ||
$dinosaur = $this->dinosaursCollection->find($query->id); | ||
|
||
if ($dinosaur === null) { | ||
throw new DinosaurNotFoundException($query->id); | ||
} | ||
|
||
return new Dinosaur($dinosaur); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Domain\Query\GetSingleDinosaur; | ||
|
||
final class Query | ||
{ | ||
public function __construct( | ||
public readonly string $id, | ||
) { | ||
} | ||
} |
Oops, something went wrong.