46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Queries\Ranges;
|
|
|
|
use App\Contracts\Query;
|
|
use App\Contracts\QueryInput;
|
|
use App\Dto\RangeDto;
|
|
use App\Models\Range;
|
|
use App\Services\DataTableService;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* phpcs:disable Generic.Files.LineLength.TooLong
|
|
*
|
|
* @implements \App\Contracts\Query<\App\Queries\Ranges\GetPaginatedRangesQueryInput, \Illuminate\Contracts\Pagination\LengthAwarePaginator<int, \App\Dto\RangeDto>>
|
|
*/
|
|
final readonly class GetPaginatedRangesQuery implements Query
|
|
{
|
|
public function __construct(
|
|
private DataTableService $dataTable,
|
|
) {
|
|
}
|
|
|
|
public function __invoke(QueryInput $input): LengthAwarePaginator
|
|
{
|
|
Assert::isAOf(
|
|
$input,
|
|
GetPaginatedRangesQueryInput::class,
|
|
);
|
|
|
|
$query = Range::query();
|
|
|
|
if ($input->publishedOnly) {
|
|
$query->where('status', true);
|
|
}
|
|
|
|
$this->dataTable->sortQuery(Range::class, $query);
|
|
|
|
$paginator = $this->dataTable->paginateQuery($query, $input->pagination);
|
|
|
|
return $paginator->through(fn (Range $range): RangeDto => RangeDto::fromModel($range));
|
|
}
|
|
}
|