Skip to content

Commit

Permalink
Switched from using first and last name to simply 'Name'
Browse files Browse the repository at this point in the history
Closing #110
  • Loading branch information
DavidLazarescu committed Feb 22, 2024
1 parent 1b5889e commit 0791619
Show file tree
Hide file tree
Showing 35 changed files with 194 additions and 471 deletions.
3 changes: 1 addition & 2 deletions src/adapters/DTOs/register_dto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace adapters::dtos

struct ADAPTERS_EXPORT RegisterDto
{
QString firstName;
QString lastName;
QString name;
QString email;
QString password;
};
Expand Down
6 changes: 2 additions & 4 deletions src/adapters/controllers/authentication_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ void AuthenticationController::logoutUser()
m_authenticationService->logoutUser();
}

void AuthenticationController::registerUser(const QString& firstName,
const QString& lastName,
void AuthenticationController::registerUser(const QString& name,
const QString& email,
QString password, bool keepUpdated)
{
// Make sure that the email is always lower-case
auto fixedEmail = email.toLower();
RegisterModel registerModel(firstName, lastName, fixedEmail, password,
keepUpdated);
RegisterModel registerModel(name, fixedEmail, password, keepUpdated);

m_authenticationService->registerUser(registerModel);
}
Expand Down
5 changes: 2 additions & 3 deletions src/adapters/controllers/authentication_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ class ADAPTERS_EXPORT AuthenticationController
bool rememberUser) override;
void tryAutomaticLogin() override;
void logoutUser() override;
void registerUser(const QString& firstName, const QString& lastName,
const QString& email, QString password,
bool keepUpdated) override;
void registerUser(const QString& name, const QString& email,
QString password, bool keepUpdated) override;
void checkIfEmailConfirmed(const QString& email) override;

private:
Expand Down
29 changes: 7 additions & 22 deletions src/adapters/controllers/user_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,32 +103,18 @@ bool UserController::renameTag(const QString& uuid, const QString& newName)
return result;
}

QString UserController::getFirstName() const
QString UserController::getName() const
{
return m_userService->getFirstName();
return m_userService->getName();
}

void UserController::setFirstName(const QString& newFirstName)
void UserController::setName(const QString& newName)
{
if(newFirstName == m_userService->getFirstName())
if(newName == m_userService->getName())
return;

m_userService->setFirstName(newFirstName);
emit firstNameChanged();
}

QString UserController::getLastName() const
{
return m_userService->getLastName();
}

void UserController::setLastName(const QString& newLastName)
{
if(newLastName == m_userService->getLastName())
return;

m_userService->setLastName(newLastName);
emit lastNameChanged();
m_userService->setName(newName);
emit nameChanged();
}

QString UserController::getEmail() const
Expand Down Expand Up @@ -201,8 +187,7 @@ data_models::UserTagsModel* UserController::getUserTagsModel()

void UserController::proccessUserLoadingResult(bool success)
{
emit firstNameChanged();
emit lastNameChanged();
emit nameChanged();
emit emailChanged();
emit usedBookStorageChanged();
emit bookStorageLimitChanged();
Expand Down
7 changes: 2 additions & 5 deletions src/adapters/controllers/user_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ class ADAPTERS_EXPORT UserController : public IUserController
bool deleteTag(const QString& uuid) override;
bool renameTag(const QString& uuid, const QString& newName) override;

QString getFirstName() const override;
void setFirstName(const QString& newFirstName) override;

QString getLastName() const override;
void setLastName(const QString& newLastName) override;
QString getName() const override;
void setName(const QString& newName) override;

QString getEmail() const override;
void setEmail(const QString& newEmail) override;
Expand Down
3 changes: 1 addition & 2 deletions src/adapters/gateways/authentication_gateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ void AuthenticationGateway::authenticateUser(const LoginModel& loginModel)
void AuthenticationGateway::registerUser(const RegisterModel& registerModel)
{
dtos::RegisterDto registerDto {
.firstName = registerModel.getFirstName(),
.lastName = registerModel.getLastName(),
.name = registerModel.getName(),
.email = registerModel.getEmail(),
.password = registerModel.getPassword(),
};
Expand Down
29 changes: 16 additions & 13 deletions src/adapters/gateways/user_storage_gateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,10 @@ void UserStorageGateway::getProfilePicture(const QString& authToken)
m_userStorageAccess->getProfilePicture(authToken);
}

void UserStorageGateway::changeFirstName(const QString& authToken,
const QString& newFirstName)
void UserStorageGateway::changeName(const QString& authToken,
const QString& newName)
{
m_userStorageAccess->changeFirstName(authToken, newFirstName);
}

void UserStorageGateway::changeLastName(const QString& authToken,
const QString& newLastName)
{
m_userStorageAccess->changeLastName(authToken, newLastName);
m_userStorageAccess->changeName(authToken, newName);
}

void UserStorageGateway::changeEmail(const QString& authToken,
Expand Down Expand Up @@ -115,7 +109,7 @@ void UserStorageGateway::renameTag(const QString& authToken, const QUuid& uuid,

void UserStorageGateway::proccessUserData(const QByteArray& data)
{
User user("x", "y", "z", "s", 0, 0);
User user("x", "z", "s", 0, 0);

assignValuesToUser(user, data);

Expand All @@ -124,7 +118,7 @@ void UserStorageGateway::proccessUserData(const QByteArray& data)

void UserStorageGateway::reportFailureGettingUser()
{
User emptyUser("invalid", "invalid", "invalid@email.x", "Some", 0, 0);
User emptyUser("invalid", "[email protected]", "Some", 0, 0);
emit finishedGettingUser(emptyUser, false);
}

Expand All @@ -134,8 +128,17 @@ void UserStorageGateway::assignValuesToUser(User& user,
auto jsonDoc = QJsonDocument::fromJson(values);
auto jsonObj = jsonDoc.object();

user.setFirstName(jsonObj["firstName"].toString());
user.setLastName(jsonObj["lastName"].toString());
// Previously, we used first and last names instead of simply one name.
// Non-updated clients might still have saved data in the old format. In
// this case we should use the first and last name to create a full name.
user.setName(jsonObj["name"].toString());
if(user.getName().isEmpty())
{
auto firstName = jsonObj["firstName"].toString();
auto lastName = jsonObj["lastName"].toString();
user.setName(firstName + " " + lastName);
}

user.setRole(jsonObj["role"].toString());
user.setUsedBookStorage(
static_cast<qint64>(jsonObj["usedBookStorage"].toDouble()));
Expand Down
5 changes: 1 addition & 4 deletions src/adapters/gateways/user_storage_gateway.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ class ADAPTERS_EXPORT UserStorageGateway
void deleteUser(const QString& authToken) override;
void forgotPassword(const QString& email) override;
void getProfilePicture(const QString& authToken) override;
void changeFirstName(const QString& authToken,
const QString& newFirstName) override;
void changeLastName(const QString& authToken,
const QString& newLastName) override;
void changeName(const QString& authToken, const QString& newName) override;
void changeEmail(const QString& authToken,
const QString& newEmail) override;
void changePassword(const QString& authToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class ADAPTERS_EXPORT IAuthenticationController : public QObject
bool rememberUser) = 0;
Q_INVOKABLE virtual void tryAutomaticLogin() = 0;
Q_INVOKABLE virtual void logoutUser() = 0;
Q_INVOKABLE virtual void registerUser(const QString& firstName,
const QString& lastName,
Q_INVOKABLE virtual void registerUser(const QString& name,
const QString& email,
QString password,
bool keepUpdated) = 0;
Expand Down
15 changes: 4 additions & 11 deletions src/adapters/interfaces/controllers/i_user_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ namespace adapters
class ADAPTERS_EXPORT IUserController : public QObject
{
Q_OBJECT
Q_PROPERTY(QString firstName READ getFirstName WRITE setFirstName NOTIFY
firstNameChanged)
Q_PROPERTY(QString lastName READ getLastName WRITE setLastName NOTIFY
lastNameChanged)
Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString email READ getEmail WRITE setEmail NOTIFY emailChanged)
Q_PROPERTY(QString role READ getRole NOTIFY roleChanged)
Q_PROPERTY(qint64 usedBookStorage READ getUsedBookStorage NOTIFY
Expand Down Expand Up @@ -46,11 +43,8 @@ class ADAPTERS_EXPORT IUserController : public QObject
Q_INVOKABLE virtual bool renameTag(const QString& uuid,
const QString& newName) = 0;

virtual QString getFirstName() const = 0;
virtual void setFirstName(const QString& newFirstName) = 0;

virtual QString getLastName() const = 0;
virtual void setLastName(const QString& newLastName) = 0;
virtual QString getName() const = 0;
virtual void setName(const QString& newName) = 0;

virtual QString getEmail() const = 0;
virtual void setEmail(const QString& newEmail) = 0;
Expand All @@ -67,8 +61,7 @@ class ADAPTERS_EXPORT IUserController : public QObject

signals:
void finishedLoadingUser(bool success);
void firstNameChanged();
void lastNameChanged();
void nameChanged();
void emailChanged();
void roleChanged();
void usedBookStorageChanged();
Expand Down
6 changes: 2 additions & 4 deletions src/adapters/interfaces/persistance/i_user_storage_access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ class ADAPTERS_EXPORT IUserStorageAccess : public QObject
virtual void deleteUser(const QString& authToken) = 0;
virtual void forgotPassword(const QString& email) = 0;
virtual void getProfilePicture(const QString& authToken) = 0;
virtual void changeFirstName(const QString& authToken,
const QString& newFirstName) = 0;
virtual void changeLastName(const QString& authToken,
const QString& newLastName) = 0;
virtual void changeName(const QString& authToken,
const QString& newName) = 0;
virtual void changeEmail(const QString& authToken,
const QString& newEmail) = 0;
virtual void changePassword(const QString& authToken,
Expand Down
2 changes: 2 additions & 0 deletions src/application/common/enums/error_code.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ enum class APPLICATION_EXPORT ErrorCode
AiExplanationLimitReached, // 20
AiRequestTooLong, // 21
UserHasNoRootFolder, // 22
NameTooShort, // 23
NameTooLong, // 24
};

Q_ENUM_NS(ErrorCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ class APPLICATION_EXPORT IUserStorageGateway : public QObject
virtual void deleteUser(const QString& authToken) = 0;
virtual void forgotPassword(const QString& email) = 0;
virtual void getProfilePicture(const QString& authToken) = 0;
virtual void changeFirstName(const QString& authToken,
const QString& newFirstName) = 0;
virtual void changeLastName(const QString& authToken,
const QString& newLastName) = 0;
virtual void changeName(const QString& authToken,
const QString& newName) = 0;
virtual void changeEmail(const QString& authToken,
const QString& newEmail) = 0;
virtual void changePassword(const QString& authToken,
Expand Down
7 changes: 2 additions & 5 deletions src/application/interfaces/services/i_user_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ class APPLICATION_EXPORT IUserService : public QObject
virtual void deleteUser() = 0;
virtual void downloadUser() = 0;

virtual QString getFirstName() const = 0;
virtual void setFirstName(const QString& newFirstName) = 0;

virtual QString getLastName() const = 0;
virtual void setLastName(const QString& newLastName) = 0;
virtual QString getName() const = 0;
virtual void setName(const QString& newName) = 0;

virtual QString getEmail() const = 0;
virtual void setEmail(const QString& newEmail) = 0;
Expand Down
36 changes: 10 additions & 26 deletions src/application/services/user_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace application::services

UserService::UserService(IUserStorageGateway* userStorageGateway) :
m_userStorageGateway(userStorageGateway),
m_user("x", "y", "z", "s", 0, 0)
m_user("x", "z", "s", 0, 0)
{
connect(m_userStorageGateway, &IUserStorageGateway::authTokenExpired, this,
&UserService::logoutUser);
Expand Down Expand Up @@ -93,28 +93,15 @@ void UserService::downloadUser()
m_userStorageGateway->getUser(m_authenticationToken);
}

QString UserService::getFirstName() const
QString UserService::getName() const
{
return m_user.getFirstName();
return m_user.getName();
}

void UserService::setFirstName(const QString& newFirstName)
void UserService::setName(const QString& newName)
{
m_user.setFirstName(newFirstName);
m_userStorageGateway->changeFirstName(m_authenticationToken,
m_user.getFirstName());
}

QString UserService::getLastName() const
{
return m_user.getLastName();
}

void UserService::setLastName(const QString& newLastName)
{
m_user.setLastName(newLastName);
m_userStorageGateway->changeLastName(m_authenticationToken,
m_user.getLastName());
m_user.setName(newName);
m_userStorageGateway->changeName(m_authenticationToken, m_user.getName());
}

QString UserService::getEmail() const
Expand Down Expand Up @@ -378,8 +365,7 @@ void UserService::proccessUserInformation(const domain::entities::User& user,

void UserService::setUserData(const User& user)
{
m_user.setFirstName(user.getFirstName());
m_user.setLastName(user.getLastName());
m_user.setName(user.getName());
m_user.setEmail(user.getEmail());
m_user.setRole(user.getRole());
m_user.setUsedBookStorage(user.getUsedBookStorage());
Expand Down Expand Up @@ -428,9 +414,8 @@ bool UserService::tryLoadingUserFromFile()
if(result.has_value())
{
utility::UserData userData = result.value();
User user(userData.firstName, userData.lastName, userData.email,
userData.role, userData.usedBookStorage,
userData.bookStorageLimit);
User user(userData.name, userData.email, userData.role,
userData.usedBookStorage, userData.bookStorageLimit);
user.setProfilePictureLastUpdated(userData.profilePictureLastUpdated);
for(auto& tag : userData.tags)
user.addTag(tag);
Expand All @@ -453,8 +438,7 @@ bool UserService::tryLoadingUserFromFile()
void UserService::saveUserToFile(const domain::entities::User& user)
{
utility::UserData userData {
user.getFirstName(),
user.getLastName(),
user.getName(),
user.getEmail(),
user.getRole(),
user.getUsedBookStorage(),
Expand Down
7 changes: 2 additions & 5 deletions src/application/services/user_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ class APPLICATION_EXPORT UserService : public IUserService
void deleteUser() override;
void downloadUser() override;

QString getFirstName() const override;
void setFirstName(const QString& newFirstName) override;

QString getLastName() const override;
void setLastName(const QString& newLastName) override;
QString getName() const override;
void setName(const QString& newName) override;

QString getEmail() const override;
void setEmail(const QString& newEmail) override;
Expand Down
Loading

0 comments on commit 0791619

Please sign in to comment.