createAccount method
Creates an account.
correlation_id
(optional) transaction id to trace execution through call chain.account
an account to be created. Return (optional) Future that receives created account or error.
Implementation
@override
Future<AccountV1?> createAccount(
String? correlationId, AccountV1? account) async {
if (account == null) {
return null;
}
var oldAccounts = _accounts.where((x) {
return x.login == account.login;
}).toList();
if (oldAccounts.isNotEmpty) {
throw BadRequestException(correlationId, 'ACCOUNT_ALREADY_EXIST',
'Account ' + account.login.toString() + ' already exists');
}
// clone
var newAccount = AccountV1();
newAccount.fromJson(account.toJson());
newAccount.id = newAccount.id ?? IdGenerator.nextLong();
_accounts.add(newAccount);
return newAccount;
}