File size: 1,060 Bytes
cf14c12 | 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 40 41 42 43 44 45 46 47 | <?php
declare(strict_types=1);
namespace Preset\Application\CommandHandlers;
use Preset\Application\Commands\CountPresetsCommand;
use Preset\Domain\Repositories\PresetRepositoryInterface;
class CountPresetsCommandHandler
{
public function __construct(
private PresetRepositoryInterface $repo
) {}
public function handle(CountPresetsCommand $cmd): int
{
$presets = $this->repo;
if ($cmd->status) {
$presets = $presets->filterByStatus($cmd->status);
}
if ($cmd->type) {
$presets = $presets->filterByType($cmd->type);
}
if (is_bool($cmd->isLocked)) {
$presets = $presets->filterByLock($cmd->isLocked);
}
if ($cmd->category) {
$presets = $presets->filterByCategory($cmd->category);
}
if ($cmd->query) {
$presets = $presets->search($cmd->query);
}
if ($cmd->ids) {
$presets = $presets->filterById($cmd->ids);
}
return $presets->count();
}
}
|