ldc-boutique-cnc-sable/app/Http/Requests/Basket/RemoveBasketRequest.php

54 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2026-06-14 21:32:07 +02:00
<?php
declare(strict_types=1);
namespace App\Http\Requests\Basket;
use App\Actions\Basket\RemoveProductFromBasketInput;
use App\Actions\Basket\RemoveQuantityFromBasketInput;
2026-06-14 21:32:07 +02:00
use Domain\Models\ValueObjects\Entities\ProductId;
use Illuminate\Foundation\Http\FormRequest;
use Ramsey\Uuid\Uuid;
class RemoveBasketRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function toRemoveFromBasketInput(): RemoveQuantityFromBasketInput | RemoveProductFromBasketInput
2026-06-14 21:32:07 +02:00
{
$qty = $this->integer('qty');
if ($qty >= 1) {
return new RemoveQuantityFromBasketInput(
$this->getProductId(),
$qty
);
}
return new RemoveProductFromBasketInput(
$this->getProductId()
);
2026-06-14 21:32:07 +02:00
}
public function getProductId(): ProductId
{
return new ProductId(
Uuid::fromString(
$this->string('rowId')->value()
)
);
}
/** @return array<string,mixed> */
public function rules(): array
{
return [
'rowId' => ['required', 'string', 'uuid'],
'qty' => ['sometimes', 'integer', 'gt:0'],
];
}
2026-06-14 21:32:07 +02:00
}