diff --git a/helpmehelpapplication/.idea/.gitignore b/helpmehelpapplication/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/helpmehelpapplication/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/helpmehelpapplication/.idea/checkstyle-idea.xml b/helpmehelpapplication/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..db90706 --- /dev/null +++ b/helpmehelpapplication/.idea/checkstyle-idea.xml @@ -0,0 +1,15 @@ + + + + 13.2.0 + JavaOnly + + + \ No newline at end of file diff --git a/helpmehelpapplication/.idea/compiler.xml b/helpmehelpapplication/.idea/compiler.xml new file mode 100644 index 0000000..5c8171b --- /dev/null +++ b/helpmehelpapplication/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/helpmehelpapplication/.idea/dictionaries/project.xml b/helpmehelpapplication/.idea/dictionaries/project.xml new file mode 100644 index 0000000..e01d6da --- /dev/null +++ b/helpmehelpapplication/.idea/dictionaries/project.xml @@ -0,0 +1,7 @@ + + + + Prestmo + + + \ No newline at end of file diff --git a/helpmehelpapplication/.idea/inspectionProfiles/Project_Default.xml b/helpmehelpapplication/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..769a78f --- /dev/null +++ b/helpmehelpapplication/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/helpmehelpapplication/.idea/jarRepositories.xml b/helpmehelpapplication/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/helpmehelpapplication/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/helpmehelpapplication/.idea/misc.xml b/helpmehelpapplication/.idea/misc.xml new file mode 100644 index 0000000..5e4e294 --- /dev/null +++ b/helpmehelpapplication/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/helpmehelpapplication/.idea/vcs.xml b/helpmehelpapplication/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/helpmehelpapplication/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Donation.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Donation.java index 78569b2..16e44cb 100644 --- a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Donation.java +++ b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Donation.java @@ -44,7 +44,7 @@ public Donation(double amount, LocalDateTime date, Charity charity, User donor) // ASSUMES that this is the way to get the anonymous setting from the user's settings. - if (donor.getSettings().getAnonymous() == false) { + if (donor.getSettings().isAnonymous() == false) { this.isAnonymous = true; } else { this.isAnonymous = false; diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Feedback.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Feedback.java index 891dce1..2a0657e 100644 --- a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Feedback.java +++ b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Feedback.java @@ -35,7 +35,7 @@ public Feedback(User user, String comment) { this.date = LocalDateTime.now(); // ASSUMES that this is the way to get the anonymous setting from the user's settings. - if (user.getSettings().getAnonymous() == false) { + if (user.getSettings().isAnonymous() == false) { this.isAnonymous = true; } else { this.isAnonymous = false; diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Inbox.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Inbox.java index 75fed79..00c8f52 100644 --- a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Inbox.java +++ b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Inbox.java @@ -1,5 +1,72 @@ package ntnu.sytemutvikling.team6.models; +import java.util.*; + +// Enhetstester mangler + +/** + * Represents a user's inbox that contains messages. + * Provides methods to add, remove and get messages. + * + * @author Robin Strand Prestmo + */ public class Inbox { - + private final List messages; + + /** + * Creates an empty inbox with no messages. + */ + public Inbox() { + this.messages = new ArrayList<>(); + } + + /** + * Returns an unmodifiable view of the messages in this inbox. + * + * @return an unmodifiable list of messages + */ + public List getMessages() { + return Collections.unmodifiableList(messages); + } + + /** + * Finds a specific message by id. + * + * @param messageId the id of the message to search for + * @return messageId the id of the message to remove + * @throws IllegalArgumentException if messageId is null + */ + public Optional findMessageById(UUID messageId) { + if (messageId == null) { + throw new IllegalArgumentException("MessageId cannot be null."); + } + return messages.stream().filter(message -> messageId.equals(message.getId())).findFirst(); + } + + /** + * Add´s message to the messages list. + * + * @param message to be added + * @throws IllegalArgumentException if message is null + */ + public void addMessage(Message message) { + if (message == null) { + throw new IllegalArgumentException("Message cannot be null"); + } + messages.add(message); + } + + /** + * Removes a message from the inbox list. + * + * @param messageId the id to the message to be removed + * @return true if the message was removed, false if not found + * @throws IllegalArgumentException if messageId is null + */ + public boolean removeMessage(UUID messageId) { + if (messageId == null) { + throw new IllegalArgumentException("MessageId cannot be null"); + } + return messages.removeIf(message -> messageId.equals(message.getId())); + } } diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Language.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Language.java new file mode 100644 index 0000000..d4ab0ae --- /dev/null +++ b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Language.java @@ -0,0 +1,10 @@ +package ntnu.sytemutvikling.team6.models; + +/** + * Supported application languages. + * + * @author Robin Strand Prestmo + */ +public enum Language { + ENGLISH +} \ No newline at end of file diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Message.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Message.java index e69de29..10ea569 100644 --- a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Message.java +++ b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Message.java @@ -0,0 +1,72 @@ +package ntnu.sytemutvikling.team6.models; + +import java.time.LocalDateTime; +import java.util.UUID; + +// Enhetstester mangler + +/** + * Represents a message. + * + * @author Robin Strand Prestmo + */ +public class Message { + private final UUID id; + private final String title; + private final String from; + private final String content; + private final LocalDateTime timeAndDate; + + /** + * Creates a message with a unique identifier. + * The message includes a title, a string who it's from, + * content and the time and date. + * + * @param title the title of the message + * @param from who the message is from + * @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) { + + if (title == null || title.isBlank()) { + throw new IllegalArgumentException("Title cannot be null or blank."); + } + + if (from == null || from.isBlank()) { + throw new IllegalArgumentException("From cannot be null or blank."); + } + + if (content == null || content.isBlank()) { + throw new IllegalArgumentException("Content cannot be null or blank."); + } + + this.id = UUID.randomUUID(); + this.title = title; + this.from = from; + this.content = content; + this.timeAndDate = LocalDateTime.now(); + } + + public UUID getId() { + return id; + } + + public String getTitle() { + return title; + } + + public String getFrom() { + return from; + } + + public String getContent() { + return content; + } + + public LocalDateTime getTimeAndDate() { + return timeAndDate; + } +} \ No newline at end of file diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Role.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Role.java new file mode 100644 index 0000000..cde9117 --- /dev/null +++ b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Role.java @@ -0,0 +1,11 @@ +package ntnu.sytemutvikling.team6.models; + +/** + * Available users + * + * @author Robin Strand Prestmo + */ +public enum Role { + NORMAL_USER, + CHARITY_USER, +} diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Settings.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Settings.java index 71e218a..cd70f0a 100644 --- a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Settings.java +++ b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Settings.java @@ -1,5 +1,77 @@ package ntnu.sytemutvikling.team6.models; +// Mangler Enhetstesting + +/** + * Represents the settings for a user. + * + * @author Robin Strand Prestmo + */ public class Settings { - + private boolean lightMode; + private Language language; + private boolean anonymous; + + /** + * Sets standard settings. + * LightMode enabled, language set to English, + * Anonymous disabled + */ + public Settings() { + this(true, Language.ENGLISH, false); + } + /** + * Creates settings for a user. + * + * @param lightMode choose between light or dark mode + * @param language choose language + * @param anonymous choose if user is anonymous + * + */ + public Settings(boolean lightMode, Language language, boolean anonymous) { + if (language == null) { + throw new IllegalArgumentException("Language cannot be null"); + } + this.lightMode = lightMode; + this.language = language; + this.anonymous = anonymous; + } + + /** + * Toggles between light and dark mode + */ + public void toggleLightMode() { + lightMode = !lightMode; + } + + /** + * Toggles anonymous mode on and off + */ + public void toggleAnonymousMode() { + anonymous = !anonymous; + } + + /** + * Change language to the chosen language. + * + * @param newLanguage the language to change to. + */ + public void changeLanguage(Language newLanguage) { + if (newLanguage == null) { + throw new IllegalArgumentException("Language cannot be null"); + } + language = newLanguage; + } + + public boolean isLightMode() { + return lightMode; + } + + public Language getLanguage() { + return language; + } + + public boolean isAnonymous() { + return anonymous; + } } diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/User.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/User.java index c51d84b..283bfa1 100644 --- a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/User.java +++ b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/User.java @@ -1,4 +1,92 @@ package ntnu.sytemutvikling.team6.models; +import java.util.UUID; + +// Passord må hashes!!! +// Unntakshåndtering mangler +// Enhetstesting mangler + +/** + * Represents a user. + * + * @author Robin Strand Prestmo + */ public class User { + private final UUID id; + private String name; + private String email; + private String password; + private final String role; + private final Settings settings; + private final Inbox inbox; + + /** + * Creates a new user + * + * @param id gives the user a unique identifier with UUID + * @param name the name of the user + * @param email the email of the user + * @param password the password for the user + * @param role users role + * @param settings the user´s settings + * @param inbox the user´s inbox + * + */ + public User(UUID id, + String name, + String email, + String password, + String role, + Settings settings, + Inbox inbox) { + + this.id = id; + this.name = name; + this.email = email; + this.password = password; + this.role = role; + this.settings = settings; + this.inbox = inbox; + } + + // Add Getters + + public UUID getId() { + return id; + } + + public String getName() { + return name; + } + + public String getEmail() { + return email; + } + + public String getRole() { + return role; + } + + public Settings getSettings() { + return settings; + } + + public Inbox getInbox() { + return inbox; + } + + // Add Setters + + + public void setName(String name) { + this.name = name; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setEmail(String email) { + this.email = email; + } } diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/service/AuthenticationService.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/service/AuthenticationService.java deleted file mode 100644 index 5f98c21..0000000 --- a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/service/AuthenticationService.java +++ /dev/null @@ -1,4 +0,0 @@ -package ntnu.sytemutvikling.team6.service; - -public class AuthenticationService { -} diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/service/CharityService.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/service/CharityService.java deleted file mode 100644 index 6bd33ce..0000000 --- a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/service/CharityService.java +++ /dev/null @@ -1,4 +0,0 @@ -package ntnu.sytemutvikling.team6.service; - -public class CharityService { -} diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/service/DonationService.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/service/DonationService.java deleted file mode 100644 index bc4a7c8..0000000 --- a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/service/DonationService.java +++ /dev/null @@ -1,4 +0,0 @@ -package ntnu.sytemutvikling.team6.service; - -public class DonationService { -} diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/service/FeedbackService.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/service/FeedbackService.java deleted file mode 100644 index 93b2555..0000000 --- a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/service/FeedbackService.java +++ /dev/null @@ -1,4 +0,0 @@ -package ntnu.sytemutvikling.team6.service; - -public class FeedbackService { -} diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Charity.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Charity.class new file mode 100644 index 0000000..7803742 Binary files /dev/null and b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Charity.class differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/CharityRegistry.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/CharityRegistry.class new file mode 100644 index 0000000..61b8503 Binary files /dev/null and b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/CharityRegistry.class differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Donation.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Donation.class new file mode 100644 index 0000000..78d4151 Binary files /dev/null and b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Donation.class differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/DonationRegistry.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/DonationRegistry.class new file mode 100644 index 0000000..1b81460 Binary files /dev/null and b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/DonationRegistry.class differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Feedback.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Feedback.class new file mode 100644 index 0000000..28853ec Binary files /dev/null and b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Feedback.class differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Inbox.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Inbox.class new file mode 100644 index 0000000..72613e7 Binary files /dev/null and b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Inbox.class differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Language.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Language.class new file mode 100644 index 0000000..de22840 Binary files /dev/null and b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Language.class differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Message.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Message.class new file mode 100644 index 0000000..12c1cec Binary files /dev/null and b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Message.class differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Role.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Role.class new file mode 100644 index 0000000..f19f0d3 Binary files /dev/null and b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Role.class differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Settings.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Settings.class new file mode 100644 index 0000000..9420861 Binary files /dev/null and b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/Settings.class differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/User.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/User.class new file mode 100644 index 0000000..c0cc6c8 Binary files /dev/null and b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/User.class differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/UserRegistry.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/UserRegistry.class new file mode 100644 index 0000000..970aced Binary files /dev/null and b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/UserRegistry.class differ diff --git a/helpmehelpapplication/target/classes/tempClassDiagram.puml b/helpmehelpapplication/target/classes/tempClassDiagram.puml new file mode 100644 index 0000000..c32ad2a --- /dev/null +++ b/helpmehelpapplication/target/classes/tempClassDiagram.puml @@ -0,0 +1,307 @@ +@startuml + + + +' ========================= + +' DOMAIN LAYER + +' ========================= + + + +package "Domain Layer" { + + + +class User { + + - idNext : static int + + - id : int + + - name : String + + - email : String + + - passwordHash : String + + - role : String + + - settings : Settings + + - inbox : Inbox + + + + + getUserId() : int + + + setUserId(id : int) + + + getUserName() : String + + + setUserName(name : String) + + + getUserEmail() : String + + + setUserEmail(email : String) + + + getUserPasswordHash() : String + + + setUserPasswordHash(passwordHash : String) + + + getUserRole() : String + + + setUserRole(role : String) + +} + + + +class Settings { + + - lightmode : boolean + + - language : String + + - anonymous : boolean + + + + + getSettings() : String + +} + + + +class Inbox { + + - messages : ArrayList + + + + + getMessages() : ArrayList + + + addMessage(message : Message) + + + removeMessage(message : Message) + +} + + + +class Message { + + - title : String + + - from : Charity + + - date : LocalDateTime + + + + + getTitle() : String + + + getFrom() : Charity + + + getDate() : LocalDateTime + +} + + + +class Charity { + + - idNext : static int + + - id : int + + - name : String + + - description : String + + - totalDonations : double + + - verified : boolean + + - category : String + + + + + getCharityId() : int + + + setCharityId(id : int) + + + getCharityName() : String + + + setCharityName(name : String) + + + getCharityDescription() : String + + + setCharityDescription(description : String) + + + getCharityTotalDonations() : double + + + setCharityTotalDonations(totalDonations : double) + +} + + + +abstract class Donation { + + - idNext : static int + + - id : int + + - amount : double + + - date : LocalDateTime + + - charity : Charity + + - user : User + + + + + getDonationId() : int + + + setDonationId(id : int) + + + getDonationAmount() : double + + + setDonationAmount(amount : double) + + + getDonationDate() : LocalDateTime + + + setDonationDate(date : LocalDateTime) + + + getDonorInfo() : String + +} + + + +class AnonymousDonation { + + - comment : String + +} + + + +class PublicDonation { + + - comment : String + +} + + + +class Feedback { + + - id : int + + - message : String + + - date : LocalDateTime + + - charityId : int + + + + + getId() : int + + + setId(id : int) + + + getMessage() : String + + + setMessage(message : String) + + + getDate() : LocalDateTime + + + setDate(date : LocalDateTime) + +} + + + +class UserRegistry { + + - users : List + + + addUser(user : User) + + + removeUser(user : User) + + + getUserById(id : int) : User + + + getAllUsers() : List + +} + + + +class CharityRegistry { + + - charities : List + + + addCharity(charity : Charity) + + + removeCharity(charity : Charity) + + + getCharityById(id : int) : Charity + + + getAllCharities() : List + +} + + + +class DonationRegistry { + + - donations : List + + + addDonation(donation : Donation) + + + removeDonation(donation : Donation) + + + getDonationById(id : int) : Donation + + + getAllDonations() : List + +} + + + +' Associations + +User "1" -- "0..*" Donation + +Charity "1" -- "0..*" Donation + + + +User "1" -- "0..*" Feedback + +Charity "1" -- "0..*" Feedback + + + +Donation <|-- AnonymousDonation + +Donation <|-- PublicDonation + + + +User "1" *-- "1" Settings + +User "1" *-- "1" Inbox + +Inbox "1" -- "0..*" Message + +Message "1" --> "1" Charity + + + +} \ No newline at end of file