mirror of
https://gitlab.com/izyim/prototypes/ddd-example.git
synced 2026-08-22 05:54:21 +00:00
Create User Zone
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Src\Zone\User\Application\UseCases\Commands;
|
||||
|
||||
use Src\Zone\User\Domain\Model\User;
|
||||
use Src\Zone\User\Domain\Model\ValueObjects\Password;
|
||||
use Src\Zone\User\Domain\Policies\UserPolicy;
|
||||
use Src\Zone\User\Domain\Repositories\AvatarRepositoryInterface;
|
||||
use Src\Zone\User\Domain\Repositories\UserRepositoryInterface;
|
||||
use Src\Common\Domain\CommandInterface;
|
||||
|
||||
class UpdateUserCommand implements CommandInterface
|
||||
{
|
||||
private UserRepositoryInterface $repository;
|
||||
private AvatarRepositoryInterface $avatarRepository;
|
||||
private UserPolicy $policy;
|
||||
|
||||
public function __construct(
|
||||
private readonly User $user,
|
||||
private readonly Password $password
|
||||
)
|
||||
{
|
||||
$this->repository = app()->make(UserRepositoryInterface::class);
|
||||
$this->avatarRepository = app()->make(AvatarRepositoryInterface::class);
|
||||
$this->policy = new UserPolicy();
|
||||
}
|
||||
|
||||
public function execute(): void
|
||||
{
|
||||
authorize('update', $this->policy, ['user' => $this->user]);
|
||||
// if (UserEloquentModel::query()->where('email', $this->user->email)->exists()) {
|
||||
// throw new EmailAlreadyUsedException();
|
||||
// }
|
||||
|
||||
$avatar = $this->user->avatar;
|
||||
if ($avatar->isBinaryFile()) {
|
||||
$filename = $this->avatarRepository->storeAvatarFile($avatar, $this->user->name);
|
||||
$this->user->setAvatar($filename);
|
||||
}
|
||||
|
||||
$this->repository->update($this->user, $this->password);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user