45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Queries\Orders;
|
|
|
|
use App\Contracts\Query;
|
|
use App\Contracts\QueryInput;
|
|
use App\Dto\OrderDto;
|
|
use App\Models\Order;
|
|
use App\Services\DataTableService;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
use Illuminate\Support\Facades\Date;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* @implements \App\Contracts\Query<\App\Queries\Orders\GetBoTodayOrdersQueryInput, \Illuminate\Contracts\Pagination\LengthAwarePaginator<int, \App\Dto\OrderDto>>
|
|
*/
|
|
final readonly class GetBoTodayOrdersQuery implements Query
|
|
{
|
|
public function __construct(
|
|
private DataTableService $dataTable,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @param \App\Queries\Orders\GetBoTodayOrdersQueryInput $input
|
|
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator<int, \App\Dto\OrderDto>
|
|
*/
|
|
#[\Override]
|
|
public function __invoke(QueryInput $input): LengthAwarePaginator
|
|
{
|
|
Assert::isInstanceOf($input, GetBoTodayOrdersQueryInput::class);
|
|
|
|
$query = Order::query()->with(['shop']);
|
|
|
|
$query->where('pickup_day', Date::now()->toDateString());
|
|
|
|
$this->dataTable->sortQuery(Order::class, $query);
|
|
|
|
$paginator = $this->dataTable->paginateQuery($query, $input->pagination);
|
|
|
|
return $paginator->through(fn (Order $order): OrderDto => OrderDto::fromModel($order));
|
|
}
|
|
}
|