Create User Zone

This commit is contained in:
omair saleh
2022-09-25 03:46:14 +08:00
parent 8143e2b9a2
commit b008ad5106
59 changed files with 1757 additions and 12 deletions
@@ -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);
}
}