From 837cf93c5eec1f6c7ae866e6c708e7c388e8168e Mon Sep 17 00:00:00 2001 From: Fredrik Marjoni Date: Thu, 26 Feb 2026 11:03:46 +0100 Subject: [PATCH] feat[User]: add constructor and get methods --- .../java/edu/group5/app/model/user/User.java | 111 +++++++++++++++++- .../edu/group5/app/model/user/User.class | Bin 289 -> 1917 bytes 2 files changed, 110 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/group5/app/model/user/User.java b/src/main/java/edu/group5/app/model/user/User.java index e163785..939bea9 100644 --- a/src/main/java/edu/group5/app/model/user/User.java +++ b/src/main/java/edu/group5/app/model/user/User.java @@ -1,5 +1,114 @@ package edu.group5.app.model.user; +/** + * User class represents a user in the system. It is an abstract class that will be extended by specific user types such as Donor, Recipient, and Admin. + * Each user has a unique userId, a role that defines their permissions in the system, and personal information such as first name, last name, email, and password hash. + * The constructor validates that all required fields are provided and throws an IllegalArgumentException if any of the fields are null or empty. + * This ensures that the User objects are always in a valid state when created. + */ +public abstract class User { + private int userId; + private String role; + private String firstName; + private String lastName; + private String email; + private String passwordHash; + + /** + * Constructor for User class. Validates that all required fields + * are provided and throws an IllegalArgumentException if any of the fields are null or empty. + * @param userId the unique identifier for the user, must be a positive integer + * @param role the role of the user (e.g., "Donor", "Recipient", "Admin") + * @param firstName the first name of the user + * @param lastName the last name of the user + * @param email the email address of the user + * @param passwordHash the hashed password of the user + */ + public User(int userId, String role, String firstName, + String lastName, String email, String passwordHash) { + if (userId <= 0) { + throw new IllegalArgumentException("User ID must be positive"); + } + if (role == null || role.trim().isEmpty()) { + throw new IllegalArgumentException("Role cannot be null or empty"); + } + if (firstName == null || firstName.trim().isEmpty()) { + throw new IllegalArgumentException("First name cannot be null or empty"); + } + if (lastName == null || lastName.trim().isEmpty()) { + throw new IllegalArgumentException("Last name cannot be null or empty"); + } + if (email == null || email.trim().isEmpty()) { + throw new IllegalArgumentException("Email cannot be null or empty"); + } + if (passwordHash == null || passwordHash.trim().isEmpty()) { + throw new IllegalArgumentException("Password hash cannot be null or empty"); + } + this.userId = userId; + this.role = role.trim(); + this.firstName = firstName.trim(); + this.lastName = lastName.trim(); + this.email = email.trim(); + this.passwordHash = passwordHash; +} -public class User { + /** + * Gets the unique identifier for the user. + * @return the userId of the user + */ + public int getUserId() { + return userId; + } + + /** + * Gets the role of the user, which defines their permissions in the system. + * @return the role of the user + */ + public String getRole() { + return role; + } + + /** + * Gets the first name of the user. + * @return the first name of the user + */ + public String getFirstName() { + return firstName; + } + /** + * Gets the last name of the user. + * @return the last name of the user + */ + public String getLastName() { + return lastName; + } + + /** + * Gets the email address of the user. + * @return the email of the user + */ + public String getEmail() { + return email; + } + + /** + * Gets the hashed password of the user. + * This is used for authentication purposes and should not be exposed in plaintext. + * @return the password hash of the user + */ + public String getPasswordHash() { + return passwordHash; + } + + /** + * Verifies if the provided password matches the stored password hash for the user. + * This method should implement the logic to hash the input password + * and compare it with the stored password hash. + * @param password the plaintext password to verify + * @return true if the password is correct, false otherwise + */ + public boolean verifyPassword(String password) { + // TODO Implement password verification logic here, e.g., using a hashing algorithm + return true; // Placeholder return value + } } diff --git a/target/classes/edu/group5/app/model/user/User.class b/target/classes/edu/group5/app/model/user/User.class index 950b2f7160ec2652685a7081f89e90b9a1c868d5..4f41b157efad2b627e7442266011a3ad90367176 100644 GIT binary patch literal 1917 zcmb_cL37hq5dNNHTXrHR5CSD60R>2EizEsmgtVcw5F9WB+97RbN;{oVY~hH?l17qK z_yaxn(nDv;vA0gAovF!8JA@kteiX3#Venv&l{%i8x5~!IYu+I0^=K66r=?X+&8yO!!g~u@#V&Ss~QPp*`rbu5EX%R z;5nAS;OZN{wJ5ON`jSBYo*jhIZL>iRImg@;Ggia29Rbxh!|*3Bs9iV1O$vL_cJ1hr zzz@aB-e@06Q(C8-m#NTR^x&Y10tN+oiluc0Ljot?R8espt8O}%gL<=Jxl#E+)$$|T zb8|Q%aFqGcDp$2eGmNwiOY^af7!;@+f7>%ADkn1ay`YGcY&9LEVt zkN9f{3>8az@r)id<^oa@;Ie~#y+qG^t8yi;ewYd=wq*pbabu+N}+*YQeO*<6OR^L7N zG`fYg$gKW&%ka zzhwpXy@$KXeMaUky`J5tBG9|$HG`_PV)NB`&S{2+Ha$*c_0Z$aBE>9{lwuC$P7KPO z_>()aCwJnG_8cJ#=%;l65WiCtg|s{RHV%wDLg9ZL`gZW}Ha>bf^$dln$2j&F+HYteWZmMo$qg9R_FU#nA2tW z7Up#st%U`BINQSFKU6^vKBe^zhG;#8G)Ae?F%04aH2QRUM2k3uE0`dkNqmnY9F(wy zGx!-(_ysfg6$Tz*7JuL@{=yu#aSl%~k0pwDJ!T0P@fn?nFUh))67!yt5;MG-bYKj6O6pXz60}A;RQnQnB(}buhZIc+zbt`@WcS7^xkGsQ delta 159 zcmey%w~&eJ)W2Q(7#J8_83ZPB*~;2v=4F=HF)}b~XofK|usG+Zq;fGZGjQ@Surjbs zzRnb!#TA@iT9lmXmYI{v$iNv|oLZ!pl~|U@pvVB!1vH2ONHc;|14(uuPan)@U|`kS m&cLw|D8R(P1tdYz3_uOsK#~W{W(Cr`KprClACP2X;0FLGfEL^U