Skip to content

Commit

Permalink
Fix: Forgot about displayName column in users
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Apr 15, 2026
1 parent a0b4e49 commit 72045a1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public User getUserFromDBUsernameAndPassword(String username, String password) {
String sql_query =
"""
SELECT
u.UUID_User, u.user_name, u.user_email, u.user_password, u.role,
u.UUID_User, u.user_displayname, u.user_name, u.user_email, u.user_password, u.role,
s.User_UUID_User, s.isAnonymous, s.language, s.lightmode,
m.UUID_message, m.message_title, m.message_content, m.message_date, m.sender_user_id, m.sender_charity_id, m.user_id
FROM User u
Expand All @@ -80,6 +80,7 @@ public User getUserFromDBUsernameAndPassword(String username, String password) {
user =
new User(
userId,
rs.getString("user_displayname"),
rs.getString("user_name"),
rs.getString("user_email"),
rs.getString("user_password"),
Expand Down Expand Up @@ -136,7 +137,7 @@ public User getUserFromDBUuid(String user_id) {
String sql_query =
"""
SELECT
u.UUID_User, u.user_name, u.user_email, u.user_password, u.role,
u.UUID_User, u.user_displayname u.user_name, u.user_email, u.user_password, u.role,
s.User_UUID_User, s.isAnonymous, s.language, s.lightmode,
m.UUID_message, m.message_title, m.message_content, m.message_date, m.sender_user_id, m.sender_charity_id, m.user_id
FROM User u
Expand All @@ -155,6 +156,7 @@ public User getUserFromDBUuid(String user_id) {
user =
new User(
userId,
rs.getString("user_displayname"),
rs.getString("user_name"),
rs.getString("user_email"),
rs.getString("user_password"),
Expand Down Expand Up @@ -211,7 +213,7 @@ public UserRegistry getUsersFromDB() {
String sql_query =
"""
SELECT
u.UUID_User, u.user_name, u.user_email, u.user_password, u.role,
u.UUID_User, u.user_displayname u.user_name, u.user_email, u.user_password, u.role,
s.User_UUID_User, s.isAnonymous, s.language, s.lightmode,
m.UUID_message, m.message_title, m.message_content, m.message_date, m.sender_user_id, m.sender_charity_id, m.user_id
FROM User u
Expand All @@ -231,6 +233,7 @@ public UserRegistry getUsersFromDB() {
currentUser =
new User(
userId,
rs.getString("user_displayname"),
rs.getString("user_name"),
rs.getString("user_email"),
rs.getString("user_password"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class User {
private static final PasswordHasher passwordHasher = new PasswordHasher();

private final UUID id;
private String name;
private String displayName;
private String username;
private String email;
private String passwordHash;
private final Role role;
Expand All @@ -27,7 +28,8 @@ public class User {
/**
* Creates a new user.
*
* @param name the name of the user
* @param displayName the name of the user that is shown
* @param username unqiue username used for login
* @param email the email of the user
* @param password the password for the user
* @param role users role
Expand All @@ -36,9 +38,12 @@ public class User {
* @throws IllegalArgumentException if any required argument is invalid.
*/
public User(
String name, String email, String password, Role role, Settings settings, Inbox inbox) {
String displayName, String username, String email, String password, Role role, Settings settings, Inbox inbox) {
if (displayName == null || username.isBlank()){
throw new IllegalArgumentException("displayName cannot be null or blank.");
}

if (name == null || name.isBlank()) {
if (username == null || username.isBlank()) {
throw new IllegalArgumentException("Name cannot be null or blank.");
}

Expand All @@ -60,7 +65,8 @@ public User(
}

this.id = UUID.randomUUID();
this.name = name;
this.displayName = displayName;
this.username = username;
this.email = email;
this.passwordHash = passwordHasher.getHashPassword(password);
this.role = role;
Expand All @@ -73,19 +79,20 @@ public User(
* later date throught another method in databaseManager class
*
* @param uuid gives the user a unique identifier with UUID
* @param name the name of the user
* @param displayName the name of the user that is shown
* @param username the name of the user
* @param email the email of the user
* @param password the password for the user
* @param role users role
* @throws IllegalArgumentException if any required argument is invalid.
*/
public User(String uuid, String name, String email, String password, String role) {
public User(String uuid, String displayName, String username, String email, String password, String role) {

if (uuid == null || uuid.isBlank()) {
throw new IllegalArgumentException("UUID cannot be null or blank.");
}

if (name == null || name.isBlank()) {
if (username == null || username.isBlank()) {
throw new IllegalArgumentException("Name cannot be null or blank.");
}

Expand All @@ -99,7 +106,8 @@ public User(String uuid, String name, String email, String password, String role
}

this.id = UUID.fromString(uuid);
this.name = name;
this.displayName = displayName;
this.username = username;
this.email = email;
this.passwordHash = password;
this.role = Role.valueOf(role);
Expand All @@ -113,8 +121,12 @@ public UUID getId() {
return id;
}

public String getName() {
return name;
public String getDisplayName() {
return displayName;
}

public String getUsername() {
return username;
}

public String getEmail() {
Expand Down Expand Up @@ -145,11 +157,11 @@ public Inbox getInbox() {
* @param name the new name
* @throws IllegalArgumentException if the name is null or blank
*/
public void setName(String name) {
public void setUsername(String name) {
if (name == null || name.isBlank()) {
throw new IllegalArgumentException("Name cannot be null or blank.");
}
this.name = name;
this.username = name;
}

/**
Expand Down

0 comments on commit 72045a1

Please sign in to comment.