Implement adding aliases for accounts
This commit is contained in:
parent
19b8075e3c
commit
37ada99f74
7 changed files with 109 additions and 3 deletions
|
|
@ -265,4 +265,26 @@ class AccountHandler
|
|||
'deleted_alias_count' => $deleteAliasCount,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
// -- /accounts/{id}/addalias - Create a new alias for the account
|
||||
|
||||
public function addAliasToAccount(int $accountId, AccountAddAliasData $aliasAddData): void
|
||||
{
|
||||
// Check if account exists
|
||||
try {
|
||||
$this->accountRepository->fetchAccountById($accountId);
|
||||
} catch (AccountNotFoundException $e) {
|
||||
throw new InputValidationError('Account with ID ' . $accountId . ' does not exist!');
|
||||
}
|
||||
|
||||
// Check if alias address is still available
|
||||
$address = $aliasAddData->getAliasAddress();
|
||||
if (!$this->accountRepository->checkUsernameAvailable($address) || !$this->aliasRepository->checkAliasAvailable($address)) {
|
||||
throw new InputValidationError("Alias address \"$address\" is not available.");
|
||||
}
|
||||
|
||||
// Create alias in database
|
||||
$this->aliasRepository->createNewAlias($accountId, $address);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue