68 lines
1.7 KiB
PHP
68 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Bo\Shops;
|
|
|
|
use Domain\Models\ValueObjects\Entities\PickupExceptionId;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Infrastructure\Adapters\Services\AppAdminAuthService;
|
|
use Ramsey\Uuid\Uuid;
|
|
use Shared\Helpers\UuidHelper;
|
|
|
|
class IndexShopRequest extends FormRequest
|
|
{
|
|
public const string SESSION_KEY = 'shops.filter.pickup-exception';
|
|
|
|
public function __construct(
|
|
private readonly AppAdminAuthService $authService
|
|
) {
|
|
}
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return $this->authService->check();
|
|
}
|
|
|
|
#[\Override]
|
|
protected function prepareForValidation(): void
|
|
{
|
|
if ($this->has('pickup-exception')) {
|
|
$filterValue = $this->string('pickup-exception');
|
|
|
|
if ($filterValue->isEmpty()) {
|
|
$this->session()->forget(self::SESSION_KEY);
|
|
} else {
|
|
$this->session()->put(self::SESSION_KEY, (string) $filterValue);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function toPickupExceptionId(): ?PickupExceptionId
|
|
{
|
|
$raw = $this->session()->get(self::SESSION_KEY);
|
|
if ($raw === null || ! is_string($raw) || $raw === '' || ! Uuid::isValid($raw)) {
|
|
return null;
|
|
}
|
|
|
|
$uuid = Uuid::fromString($raw);
|
|
if (! UuidHelper::isV7($uuid)) {
|
|
return null;
|
|
}
|
|
|
|
return new PickupExceptionId($uuid);
|
|
}
|
|
|
|
public function getPickupExceptionId(): ?PickupExceptionId
|
|
{
|
|
return $this->toPickupExceptionId();
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'pickup-exception' => ['sometimes', 'nullable', 'string', 'uuid'],
|
|
];
|
|
}
|
|
}
|