From e17ae394cdbc761b013f6d036ba570046b2787b8 Mon Sep 17 00:00:00 2001 From: AdrianBalunan Date: Tue, 7 Apr 2026 20:37:16 +0200 Subject: [PATCH] Fix and feat: Changed String from field to UUID for matching of charity and such, and added new contructur to make previous messages. --- .../team6/models/user/Message.java | 55 ++++++++++++++++--- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/user/Message.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/user/Message.java index b70ece1..3f0fe44 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/user/Message.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/user/Message.java @@ -1,5 +1,6 @@ package ntnu.systemutvikling.team6.models.user; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.UUID; @@ -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 @@ -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."); } @@ -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() { @@ -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; } }