-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindPersonCollectionHandler.php
39 lines (34 loc) · 1.32 KB
/
FindPersonCollectionHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace App\Module\Message\Application\Interaction\Query\FindPersonCollection\Handler;
use App\Core\Infrastructure\Bus\SharedQueryBusInterface;
use App\Module\Message\Application\Interaction\Query\FindPersonCollection\FindPersonCollectionQuery;
use App\Shared\Application\Interaction\SharedQuery\AskForPersonFilteredListSharedQuery;
use App\Shared\UI\Dto\Person\PersonDto;
use Ramsey\Collection\Collection;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\HandlerFailedException;
use UnexpectedValueException;
readonly class FindPersonCollectionHandler
{
public function __construct(
private SharedQueryBusInterface $sharedQueryBus,
) {
}
/**
* @return Collection<PersonDto>
*/
#[AsMessageHandler('query_bus')]
public function handle(FindPersonCollectionQuery $query): Collection
{
try {
$senders = $this->sharedQueryBus->dispatch(new AskForPersonFilteredListSharedQuery($query->filter));
} catch (HandlerFailedException $exception) {
if ($exception->getPrevious()?->getPrevious() instanceof UnexpectedValueException) {
$senders = [];
} else {
throw $exception;
}
}
return new Collection(PersonDto::class, $senders);
}
}