52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Bo;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Infrastructure\Adapters\Services\AppAdminAuthService;
|
|
|
|
class ChangeOrderRequest extends FormRequest
|
|
{
|
|
public function __construct(
|
|
private readonly AppAdminAuthService $authService
|
|
) {
|
|
}
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return $this->authService->check();
|
|
}
|
|
|
|
#[\Override]
|
|
protected function prepareForValidation()
|
|
{
|
|
$this->merge([
|
|
'action' => $this->route('action'),
|
|
]);
|
|
}
|
|
|
|
#[\Override]
|
|
protected function passedValidation()
|
|
{
|
|
$this->merge([
|
|
'direction' => strval($this->route('action')) === 'up',
|
|
]);
|
|
}
|
|
|
|
/** @return array<string,mixed>*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'action' => ['required', 'string', 'in:up,down'],
|
|
];
|
|
}
|
|
|
|
public function getSortDirection(): \SortDirection
|
|
{
|
|
return strval($this->route('action')) === 'up'
|
|
? \SortDirection::Ascending
|
|
: \SortDirection::Descending;
|
|
}
|
|
}
|