Refactored the codebase to change the namespaces of various actions and queries from `App\Actions` to `App\Cqs\Actions` and `App\Queries` to `App\Cqs\Queries`. This restructuring improves organization and clarity in the codebase.
42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Cqs\Queries\Faqs;
|
|
|
|
use App\Contracts\Query;
|
|
use App\Contracts\QueryInput;
|
|
use App\Dto\FaqDto;
|
|
use App\Models\Faq;
|
|
use App\Services\DataTableService;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* phpcs:disable Generic.Files.LineLength.TooLong
|
|
*
|
|
* @implements \App\Contracts\Query<\App\Cqs\Queries\Faqs\GetPaginatedFaqsQueryInput, \Illuminate\Contracts\Pagination\LengthAwarePaginator<int, \App\Dto\FaqDto>>
|
|
*/
|
|
final readonly class GetPaginatedFaqsQuery implements Query
|
|
{
|
|
public function __construct(
|
|
private DataTableService $dataTable,
|
|
) {
|
|
}
|
|
|
|
public function __invoke(QueryInput $input): LengthAwarePaginator
|
|
{
|
|
Assert::isAOf(
|
|
$input,
|
|
GetPaginatedFaqsQueryInput::class,
|
|
);
|
|
|
|
$query = Faq::query();
|
|
|
|
$this->dataTable->sortQuery(Faq::class, $query);
|
|
|
|
$paginator = $this->dataTable->paginateQuery($query, $input->pagination);
|
|
|
|
return $paginator->through(fn (Faq $faq): FaqDto => FaqDto::fromModel($faq));
|
|
}
|
|
}
|