53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Bo\Dashboard;
|
|
|
|
use App\Queries\Dashboard\GetBoDashboardQueryInput;
|
|
use Carbon\CarbonInterface;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Date;
|
|
use Infrastructure\Adapters\Services\AppAdminAuthService;
|
|
|
|
class DashboardRequest extends FormRequest
|
|
{
|
|
public function __construct(
|
|
private readonly AppAdminAuthService $authService
|
|
) {
|
|
}
|
|
|
|
public function toGetBoDashboardQueryInput(): GetBoDashboardQueryInput
|
|
{
|
|
return new GetBoDashboardQueryInput(
|
|
start: $this->getStart(),
|
|
end: $this->getEnd(),
|
|
);
|
|
}
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return $this->authService->check();
|
|
}
|
|
|
|
public function getStart(): ?CarbonInterface
|
|
{
|
|
return $this->has('start') ?
|
|
Date::parse($this->string('start')->value()) : null;
|
|
}
|
|
|
|
public function getEnd(): ?CarbonInterface
|
|
{
|
|
return $this->has('end') ?
|
|
Date::parse($this->string('end')->value()) : null;
|
|
}
|
|
|
|
/** @return array<string,mixed> */
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'start' => ['required_with:end', 'date'],
|
|
'end' => ['required_with:start', 'date'],
|
|
];
|
|
}
|
|
}
|