-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindSpecifiedPersonsHandler.php
33 lines (28 loc) · 1.07 KB
/
FindSpecifiedPersonsHandler.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
<?php
namespace App\Module\Person\Application\Interaction\Query\FindSpecifiedPersons\Handler;
use App\Module\Person\Application\Interaction\Query\FindSpecifiedPersons\FindSpecifiedPersonsQuery;
use App\Module\Person\Domain\Document\Person;
use App\Module\Person\Infrastructure\Repository\PersonRepository;
use App\Module\Person\UI\Dto\Converter\PersonToDtoConverter;
use App\Shared\UI\Dto\Person\PersonDto;
use Doctrine\ODM\MongoDB\MongoDBException;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
readonly class FindSpecifiedPersonsHandler
{
public function __construct(
private PersonRepository $repository,
private PersonToDtoConverter $converter,
) {
}
/**
* @return PersonDto[]
*
* @throws MongoDBException
*/
#[AsMessageHandler(bus: 'query_bus')]
public function __invoke(FindSpecifiedPersonsQuery $query): array
{
$persons = $this->repository->findSpecified($query->personIds);
return array_map(fn (Person $person) => $this->converter->convertToDto($person), $persons->toArray());
}
}