Created
January 18, 2022 10:37
-
-
Save emilybache/d22d3ee02ca67e6ad631195e1344f480 to your computer and use it in GitHub Desktop.
after peeling the call to MessageBus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void changeEmail(String newEmail) | |
{ | |
if (changeEmailInDatabase(newEmail)) return; | |
MessageBus.sendEmailChangedMessage(this.userId, newEmail); | |
} | |
boolean changeEmailInDatabase(String newEmail) { | |
Object[] data = Database.getUserById(userId); | |
email = (String)data[1]; | |
userType = (UserType)data[2]; | |
if (Objects.equals(email, newEmail)) | |
return true; | |
Object[] companyData = Database.getCompany(userId); | |
int companyId = (int)companyData[0]; | |
String companyDomainName = (String)companyData[1]; | |
int numberOfEmployees = (int)companyData[2]; | |
String emailDomain = newEmail.split("@")[1]; | |
boolean isEmailCorporate = Objects.equals(emailDomain, companyDomainName); | |
UserType newType = isEmailCorporate | |
? UserType.Employee | |
: UserType.Customer; | |
if (userType != newType) | |
{ | |
int delta = newType == UserType.Employee ? 1 : -1; | |
int newNumber = numberOfEmployees + delta; | |
Database.saveCompany(companyId, companyDomainName, newNumber); | |
} | |
email = newEmail; | |
userType = newType; | |
Database.saveUser(this); | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment