- Introduced EmployeeFilter value object for filtering criteria. - Updated EmployeeDirectory and EloquentEmployeeDirectory to support filtering. - Modified FindAllEmployees use case to accept filter input. - Enhanced EmployeesIndexRequest to handle filter parameters. - Added tests for filtering functionality in EmployeesIndexTest and EloquentEmployeeDirectoryTest.
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Application\Usecase\Employees\FindAll;
|
|
|
|
use Domain\Models\Entities\Employee;
|
|
use Domain\Ports\Directories\EmployeeDirectory;
|
|
use Shared\DDD\Usecase\Input as BaseInput;
|
|
use Shared\DDD\Usecase\Usecase;
|
|
use Shared\Paginated;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/** @implements Usecase<\Shared\DDD\Usecase\Input, \Shared\DDD\Usecase\Output> */
|
|
final readonly class FindAllEmployees implements Usecase
|
|
{
|
|
public function __construct(
|
|
private EmployeeDirectory $directory
|
|
) {
|
|
}
|
|
|
|
#[\Override]
|
|
public function execute(BaseInput $input): Output
|
|
{
|
|
Assert::isInstanceOf($input, Input::class);
|
|
|
|
$page = $this->directory->findAll(
|
|
$input->pagination,
|
|
$input->sorter,
|
|
$input->filter
|
|
);
|
|
|
|
return $this->toOutput($page);
|
|
}
|
|
|
|
/**
|
|
* @param Paginated<Employee> $resultPage
|
|
*/
|
|
private function toOutput(Paginated $resultPage): Output
|
|
{
|
|
$pagination = $resultPage->getPagination();
|
|
|
|
return new Output(
|
|
employees: array_map([$this, 'toPaginatedEmployee'], $resultPage->getItems()),
|
|
total: $resultPage->getTotal(),
|
|
page: $pagination->pageNumber(),
|
|
perPage: $pagination->pageSize(),
|
|
);
|
|
}
|
|
|
|
private function toPaginatedEmployee(Employee $employee): PaginatedEmployee
|
|
{
|
|
return PaginatedEmployee::fromDomain($employee);
|
|
}
|
|
}
|