- Refactor Bo\ProductsController to use ActionExecutor and Queries - Refactor Fo\Pages\ProductsController and Fo\Ajax\ProductsController to CQS - Add Actions: CreateProduct, UpdateProduct, DeleteProduct with Inputs - Add Queries: GetBoPaginatedProductsQuery, GetProductFormDataQuery, GetFoProductIndexPageQuery, GetFoFilteredProductsQuery - Add DTOs: ProductFormDataDto and enrich ProductDto - Encapsulate Action/Query inputs conversion in FormRequests - Remove obsolete ProductDirectory and EloquentProductDirectory - Add tests for Fo\Ajax\ProductsController
55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions\Products;
|
|
|
|
use App\Contracts\ActionInput;
|
|
use Carbon\CarbonInterface;
|
|
use Domain\Enums\ProductBrand;
|
|
use Domain\Enums\SellUnit;
|
|
use Domain\Enums\TaxRate;
|
|
use Domain\Enums\Units\InvoicingUnit;
|
|
use Domain\Enums\Units\OrderUnit;
|
|
use Money\Money;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
final readonly class CreateProductInput implements ActionInput
|
|
{
|
|
/**
|
|
* @param array<array{id?: int|string, label: string}> $tags
|
|
* @param list<string> $associatedProductsIds
|
|
*/
|
|
public function __construct(
|
|
public string $name,
|
|
public string $shortDescription,
|
|
public string $description,
|
|
public Money $price,
|
|
public InvoicingUnit $invoicingUnit,
|
|
public int $stock,
|
|
public int $rangeId,
|
|
public SellUnit $sellUnit,
|
|
public OrderUnit $orderUnit,
|
|
public TaxRate $taxRate,
|
|
public ProductBrand $brand,
|
|
public ?int $weight = null,
|
|
public bool $weightVariable = false,
|
|
public ?CarbonInterface $orderableStart = null,
|
|
public ?CarbonInterface $orderableEnd = null,
|
|
public bool $star = false,
|
|
public bool $status = false,
|
|
public mixed $picture = null,
|
|
public ?string $pictureAlt = null,
|
|
public ?string $pictureTitle = null,
|
|
public mixed $pictureLarge = null,
|
|
public ?string $pictureLargeAlt = null,
|
|
public ?string $pictureLargeTitle = null,
|
|
public array $tags = [],
|
|
public array $associatedProductsIds = [],
|
|
) {
|
|
Assert::stringNotEmpty(trim($this->name));
|
|
Assert::maxLength($this->name, 255);
|
|
Assert::greaterThanEq($this->stock, 0);
|
|
Assert::greaterThanEq($this->rangeId, 1);
|
|
}
|
|
}
|