Skip to content

Organization #12

Merged
merged 5 commits into from
Feb 26, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 75 additions & 2 deletions src/main/java/model/Organization.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,79 @@
package model;

import java.util.Objects;

public class Organization {
public String name;
public String orgNr;
private final String name;
private final String orgNr;
private final Cause cause;
private final String description;
private final String contactEmail;
private final String website;
private final boolean verified;


public Organization(String name, String orgNr, Cause cause, String description, String contactEmail, String website, boolean verified) {
if (name == null || name.isBlank()) {
throw new IllegalArgumentException("Name cannot be null or blank");
}
if (orgNr == null || !orgNr.matches("\\d{9}")) {
throw new IllegalArgumentException("Organization number must be 9 digits");
}
if (contactEmail != null) {
contactEmail = contactEmail.trim();

if (contactEmail.isBlank()) {
throw new IllegalArgumentException("Email cannot be blank");
}

if (!contactEmail.matches("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"
)) //Got help from ChatGPT on regex
{
throw new IllegalArgumentException("Invalid email format");
}
}

if (website != null) {
website = website.trim();

if (website.isBlank()) {
throw new IllegalArgumentException("Website cannot be blank");
}

if (!website.matches("^https?://.+")) { //Got help from ChatGPT for regex
throw new IllegalArgumentException("Website must start with http:// or https://");
}
}

this.name = name.trim();
this.orgNr = orgNr.trim();
this.cause = Objects.requireNonNull(cause, "Cause cannot be null");
this.description = description;
this.contactEmail = contactEmail;
this.website = website;
this.verified = verified;
}


public String getName() {
return name;
}
public String getOrgNr() {
return orgNr;
}
public Cause getCause() {
return cause;
}
public String getDescription() {
return description;
}
public String getContactEmail() {
return contactEmail;
}
public String getWebsite() {
return website;
}
public boolean isVerified() {
return verified;
}
}
5 changes: 5 additions & 0 deletions src/main/java/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public User(String userName, String phoneNumber, String password, String eMail)
if (phoneNumber.length() != 8) {
throw new IllegalArgumentException("Fill in a phonenumber with 8 digits");
}

this.userName = userName;
this.phoneNumber = phoneNumber;
this.eMail = eMail;
this.password = password;
}

public String getUsername() {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/register/UserRegister.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ public UserRegister(String userName, User user) {
}

public void addUser(User user) {
if (user == null) {
throw new IllegalArgumentException("User cannot be null");
}
if (!users.containsKey(user.getUsername())) {
users.put(user.getUsername(), user);
}
}

public void removeUser(User user) {
if (users.containsValue(user)) {
users.remove(user);
if (user == null) {
throw new IllegalArgumentException("User cannot be null");
}
users.remove(user.getUsername());
}

public List<User> getAllUsers() {
Expand Down
Loading