44 lines
1.4 KiB
PHP
44 lines
1.4 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\Services\Private;
|
|
|
|
use App\Dto\Request\Private\Profile\Update;
|
|
use App\Dto\Request\Private\Profile\UpdatePassword;
|
|
use App\Models\User;
|
|
use App\ServiceResults\ServiceResultError;
|
|
use App\ServiceResults\ServiceResultSuccess;
|
|
use App\Services\Service;
|
|
use App\Services\User\UserCommandHandler;
|
|
|
|
final class ProfileService extends Service
|
|
{
|
|
public function __construct(
|
|
private readonly UserCommandHandler $userCommandHandler
|
|
) { }
|
|
|
|
public function update(Update $update, User $user): ServiceResultError | ServiceResultSuccess
|
|
{
|
|
try {
|
|
$data = [
|
|
'name' => $update->getName()
|
|
];
|
|
$this->userCommandHandler->handleUpdate($user, $data);
|
|
} catch (\Throwable $e) {
|
|
report($e->getMessage());
|
|
return $this->errService($e->getMessage());
|
|
}
|
|
return $this->ok(__('Profile saved successfully'));
|
|
}
|
|
|
|
public function updatePassword(UpdatePassword $update, User $user): ServiceResultError | ServiceResultSuccess
|
|
{
|
|
try {
|
|
$this->userCommandHandler->handleUpdatePassword($user, $update->getPassword());
|
|
} catch (\Throwable $e) {
|
|
report($e->getMessage());
|
|
return $this->errService($e->getMessage());
|
|
}
|
|
return $this->ok(__('The password has been changed'));
|
|
}
|
|
}
|