60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Application\UseCases\Brand\Update;
|
||
|
|
|
||
|
|
use Domain\Models\Entities\Brand;
|
||
|
|
use Domain\Ports\Repositories\BrandRepository;
|
||
|
|
use Shared\DDD\Exceptions\NotFoundException;
|
||
|
|
use Shared\DDD\UseCases\Input as BaseInput;
|
||
|
|
use Shared\DDD\UseCases\UseCase;
|
||
|
|
use Shared\Models\ValueObjects\Email;
|
||
|
|
use Shared\Models\ValueObjects\PicturePath;
|
||
|
|
use Shared\Models\ValueObjects\Rcs;
|
||
|
|
use Webmozart\Assert\Assert;
|
||
|
|
|
||
|
|
/** @implements UseCase<\Application\UseCases\Brand\Update\Input, \Application\UseCases\Brand\Update\Output> */
|
||
|
|
final readonly class UpdateBrand implements UseCase
|
||
|
|
{
|
||
|
|
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) {
|
||
|
|
throw new NotFoundException();
|
||
|
|
}
|
||
|
|
|
||
|
|
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 Output(
|
||
|
|
name: $brand->name,
|
||
|
|
code: $brand->code,
|
||
|
|
logo: $brand->logo,
|
||
|
|
rcs: $brand->rcs,
|
||
|
|
contact: $brand->contact,
|
||
|
|
createdAt: $brand->createdAt(),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|