43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Application\Usecase\Employees\Find;
|
|
|
|
use Domain\Exceptions\NotFoundException;
|
|
use Domain\Ports\Directories\EmployeeDirectory;
|
|
use Shared\DDD\Usecase\Input as BaseInput;
|
|
use Shared\DDD\Usecase\Usecase;
|
|
|
|
/** @implements Usecase<\Shared\DDD\Usecase\Input, \Shared\DDD\Usecase\Output> */
|
|
final readonly class FindEmployee implements Usecase
|
|
{
|
|
public function __construct(
|
|
private EmployeeDirectory $directory
|
|
) {
|
|
}
|
|
|
|
#[\Override]
|
|
public function execute(BaseInput $input): Output
|
|
{
|
|
assert($input instanceof Input);
|
|
|
|
$employee = $this->directory->find($input->id);
|
|
|
|
if ($employee === null) {
|
|
throw NotFoundException::forEntity('Employee', (string) $input->id);
|
|
}
|
|
|
|
return new Output(
|
|
id: $employee->id(),
|
|
firstName: $employee->firstName,
|
|
lastName: $employee->lastName,
|
|
establishment: $employee->establishment->value,
|
|
site: $employee->site->value,
|
|
service: $employee->service->value,
|
|
startDate: $employee->startDate,
|
|
endDate: $employee->endDate,
|
|
plannedEndDate: $employee->plannedEndDate,
|
|
);
|
|
}
|
|
}
|