Skip to content

Commit

Permalink
Fix and feat: Changed String from field to UUID for matching of chari…
Browse files Browse the repository at this point in the history
…ty and such, and added new contructur to make previous messages.
  • Loading branch information
AdrianBalunan committed Apr 7, 2026
1 parent dc3e7ea commit e17ae39
Showing 1 changed file with 46 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ntnu.systemutvikling.team6.models.user;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.UUID;

Expand All @@ -13,9 +14,9 @@
public class Message {
private final UUID id;
private final String title;
private final String from;
private final UUID fromCharityID;
private final String content;
private final LocalDateTime timeAndDate;
private final LocalDate timeAndDate;

/**
* Creates a message with a unique identifier. The message includes a title, a string who it's
Expand All @@ -26,13 +27,13 @@ public class Message {
* @param content the content of the message
* @throws IllegalArgumentException if title, from or content is null or blank.
*/
public Message(String title, String from, String content) {
public Message(String title, UUID from, String content) {

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

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

Expand All @@ -42,9 +43,45 @@ public Message(String title, String from, String content) {

this.id = UUID.randomUUID();
this.title = title;
this.from = from;
this.fromCharityID = from;
this.content = content;
this.timeAndDate = LocalDateTime.now();
this.timeAndDate = LocalDate.now();
}

/**
* Creates a message with a unique identifier. The message includes a title, a string who it's
* from, content and the time and date.
* This one creates a message that has been created before.
*
* @param title the title of the message
* @param from who the message is from
* @param content the content of the message
* @param date date of when the message was created
* @throws IllegalArgumentException if title, from or content is null or blank.
*/
public Message(String title, UUID from, String content, LocalDate date) {

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

if (from == null) {
throw new IllegalArgumentException("From cannot be null or blank.");
}

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

if (date == null) {
throw new IllegalArgumentException("Content cannot be null or blank.");
}

this.id = UUID.randomUUID();
this.title = title;
this.fromCharityID = from;
this.content = content;
this.timeAndDate = date;
}

public UUID getId() {
Expand All @@ -55,15 +92,15 @@ public String getTitle() {
return title;
}

public String getFrom() {
return from;
public UUID getFrom() {
return fromCharityID;
}

public String getContent() {
return content;
}

public LocalDateTime getTimeAndDate() {
public LocalDate getTimeAndDate() {
return timeAndDate;
}
}

0 comments on commit e17ae39

Please sign in to comment.