61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Application\UseCases\Brand\Update;
|
|
|
|
use Application\UseCases\Brand\Update\Output\BrandNotFound;
|
|
use Application\UseCases\Brand\Update\Output\BrandUpdated;
|
|
use Application\UseCases\Brand\Update\Output\Output;
|
|
use Domain\Models\Entities\Brand;
|
|
use Domain\Models\ValueObjects\PicturePath;
|
|
use Domain\Ports\Repositories\BrandRepository;
|
|
use Shared\DDD\UseCases\Input as BaseInput;
|
|
use Shared\DDD\UseCases\Transactional;
|
|
use Shared\DDD\UseCases\UseCase;
|
|
use Shared\ValueObjects\Email;
|
|
use Shared\ValueObjects\Rcs;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/** @implements UseCase<\Application\UseCases\Brand\Update\Input, \Application\UseCases\Brand\Update\Output\Output> */
|
|
final readonly class UpdateBrand implements UseCase, Transactional
|
|
{
|
|
public function __construct(
|
|
private BrandRepository $repository,
|
|
) {
|
|
}
|
|
|
|
#[\Override]
|
|
public function execute(BaseInput $input): Output
|
|
{
|
|
Assert::isInstanceOf($input, Input::class);
|
|
|
|
$brand = $this->repository->findByCode($input->code);
|
|
|
|
if (! $brand instanceof Brand) {
|
|
return new BrandNotFound();
|
|
}
|
|
|
|
if ($input->logo instanceof PicturePath) {
|
|
$brand = $brand->changeLogo($input->logo);
|
|
}
|
|
|
|
if ($input->rcs instanceof Rcs) {
|
|
$brand = $brand->changeRcs($input->rcs);
|
|
}
|
|
|
|
if ($input->contact instanceof Email) {
|
|
$brand = $brand->changeContact($input->contact);
|
|
}
|
|
|
|
$this->repository->save($brand);
|
|
|
|
return new BrandUpdated(
|
|
name: $brand->name,
|
|
code: $brand->code,
|
|
logo: $brand->logo,
|
|
rcs: $brand->rcs,
|
|
contact: $brand->contact,
|
|
);
|
|
}
|
|
}
|