47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\Cqs\Queries\ProductIncos;
|
||
|
|
|
||
|
|
use App\Contracts\Query;
|
||
|
|
use App\Contracts\QueryInput;
|
||
|
|
use App\Dto\ProductIncoDto;
|
||
|
|
use App\Models\Product;
|
||
|
|
use App\Models\ProductInco;
|
||
|
|
use App\Services\ProductDtoAssemblerService;
|
||
|
|
use Webmozart\Assert\Assert;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @implements \App\Contracts\Query<
|
||
|
|
* \App\Cqs\Queries\ProductIncos\GetProductIncoForEditQueryInput,
|
||
|
|
* \App\Cqs\Queries\ProductIncos\GetProductIncoForEditQueryOutput
|
||
|
|
* >
|
||
|
|
*/
|
||
|
|
final readonly class GetProductIncoForEditQuery implements Query
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
private ProductDtoAssemblerService $assembler,
|
||
|
|
) {
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param \App\Cqs\Queries\ProductIncos\GetProductIncoForEditQueryInput $input
|
||
|
|
*/
|
||
|
|
#[\Override]
|
||
|
|
public function __invoke(QueryInput $input): GetProductIncoForEditQueryOutput
|
||
|
|
{
|
||
|
|
Assert::isInstanceOf($input, GetProductIncoForEditQueryInput::class);
|
||
|
|
|
||
|
|
$product = Product::query()
|
||
|
|
->with(['inco', 'validDiscount', 'range'])
|
||
|
|
->where('id', $input->productId->value->toString())
|
||
|
|
->firstOrFail();
|
||
|
|
|
||
|
|
return new GetProductIncoForEditQueryOutput(
|
||
|
|
product: $this->assembler->toDto($product),
|
||
|
|
inco: $product->inco instanceof ProductInco ? ProductIncoDto::fromModel($product->inco) : null,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|