2026-09-29 14:53:02 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Queries\Faqs;
|
|
|
|
|
|
|
|
|
|
use App\Contracts\Query;
|
2026-09-29 16:59:07 +02:00
|
|
|
use App\Contracts\QueryInput;
|
2026-09-29 14:53:02 +02:00
|
|
|
use App\Dto\FaqDto;
|
|
|
|
|
use App\Models\Faq;
|
|
|
|
|
use App\Services\DataTableService;
|
|
|
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
2026-09-29 16:59:07 +02:00
|
|
|
use Webmozart\Assert\Assert;
|
2026-09-29 14:53:02 +02:00
|
|
|
|
|
|
|
|
/**
|
2026-09-29 16:59:07 +02:00
|
|
|
* phpcs:disable Generic.Files.LineLength.TooLong
|
|
|
|
|
*
|
|
|
|
|
* @implements \App\Contracts\Query<\App\Queries\Faqs\GetPaginatedFaqsQueryInput, \Illuminate\Contracts\Pagination\LengthAwarePaginator<int, \App\Dto\FaqDto>>
|
2026-09-29 14:53:02 +02:00
|
|
|
*/
|
|
|
|
|
final readonly class GetPaginatedFaqsQuery implements Query
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
private DataTableService $dataTable,
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-29 16:59:07 +02:00
|
|
|
public function __invoke(QueryInput $input): LengthAwarePaginator
|
2026-09-29 14:53:02 +02:00
|
|
|
{
|
2026-09-29 16:59:07 +02:00
|
|
|
Assert::isAOf(
|
|
|
|
|
$input,
|
|
|
|
|
GetPaginatedFaqsQueryInput::class,
|
|
|
|
|
);
|
|
|
|
|
|
2026-09-29 14:53:02 +02:00
|
|
|
$query = Faq::query();
|
|
|
|
|
|
|
|
|
|
$this->dataTable->sortQuery(Faq::class, $query);
|
|
|
|
|
|
2026-09-29 16:59:07 +02:00
|
|
|
$paginator = $this->dataTable->paginateQuery($query, $input->pagination);
|
2026-09-29 14:53:02 +02:00
|
|
|
|
|
|
|
|
return $paginator->through(fn (Faq $faq): FaqDto => FaqDto::fromModel($faq));
|
|
|
|
|
}
|
|
|
|
|
}
|