*/ final readonly class GetPaginatedShopsQuery implements Query { public function __construct( private DataTableService $dataTable, ) { } /** * @param \App\Queries\Shops\GetPaginatedShopsQueryInput $input */ #[\Override] public function __invoke(QueryInput $input): GetPaginatedShopsQueryOutput { Assert::isInstanceOf($input, GetPaginatedShopsQueryInput::class); $query = Shop::query(); if ($input->pickupExceptionId !== null) { $query->whereHas( 'pickupExceptions', fn (Builder $q) => $q->where('id', (string) $input->pickupExceptionId) ); } $this->dataTable->sortQuery(Shop::class, $query); $paginator = $this->dataTable->paginateQuery($query, $input->pagination); $shops = $paginator->through(fn (Shop $shop): ShopDto => ShopDto::fromModel($shop)); $pickupExceptions = PickupException::query() ->get() ->map(fn (PickupException $pe): PickupExceptionDto => PickupExceptionDto::fromModel($pe)); return new GetPaginatedShopsQueryOutput( shops: $shops, pickupExceptions: $pickupExceptions, ); } }