2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Basket;
|
|
|
|
|
|
2026-09-30 10:24:52 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-30 10:24:52 +02:00
|
|
|
public function toRemoveFromBasketInput(): RemoveQuantityFromBasketInput | RemoveProductFromBasketInput
|
2026-06-14 21:32:07 +02:00
|
|
|
{
|
2026-09-30 10:24:52 +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()
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-09-30 10:24:52 +02:00
|
|
|
|
|
|
|
|
/** @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
|
|
|
}
|