@@ -125,7 +125,7 @@ Enum Class Hierarchy
diff --git a/docs/javadoc/package-search-index.js b/docs/javadoc/package-search-index.js
index bb7161b..d54b332 100644
--- a/docs/javadoc/package-search-index.js
+++ b/docs/javadoc/package-search-index.js
@@ -1 +1 @@
-packageSearchIndex = [{"l":"All Packages","u":"allpackages-index.html","k":"18"},{"l":"no.ntnu.idatt1005.group03"},{"l":"no.ntnu.idatt1005.group03.Controller"},{"l":"no.ntnu.idatt1005.group03.DAO"},{"l":"no.ntnu.idatt1005.group03.Model"},{"l":"no.ntnu.idatt1005.group03.Service"},{"l":"no.ntnu.idatt1005.group03.UI"}];updateSearchResults();
\ No newline at end of file
+packageSearchIndex = [{"l":"All Packages","u":"allpackages-index.html","k":"18"},{"l":"no.ntnu.idatt1005.group03"},{"l":"no.ntnu.idatt1005.group03.controller"},{"l":"no.ntnu.idatt1005.group03.dao"},{"l":"no.ntnu.idatt1005.group03.model"},{"l":"no.ntnu.idatt1005.group03.service"},{"l":"no.ntnu.idatt1005.group03.ui"}];updateSearchResults();
\ No newline at end of file
diff --git a/docs/javadoc/search.html b/docs/javadoc/search.html
index f760d05..1c584eb 100644
--- a/docs/javadoc/search.html
+++ b/docs/javadoc/search.html
@@ -1,7 +1,7 @@
-
+
-
+
Search (help-me-help 1.0-SNAPSHOT API)
diff --git a/docs/javadoc/type-search-index.js b/docs/javadoc/type-search-index.js
index 6036b07..342b54e 100644
--- a/docs/javadoc/type-search-index.js
+++ b/docs/javadoc/type-search-index.js
@@ -1 +1 @@
-typeSearchIndex = [{"p":"no.ntnu.idatt1005.group03.UI","l":"AboutUsScreen"},{"p":"no.ntnu.idatt1005.group03.UI","l":"AccountScreen"},{"l":"All Classes and Interfaces","u":"allclasses-index.html","k":"18"},{"p":"no.ntnu.idatt1005.group03.Service","l":"ApiClient"},{"p":"no.ntnu.idatt1005.group03","l":"App"},{"p":"no.ntnu.idatt1005.group03.Controller","l":"AuthController"},{"p":"no.ntnu.idatt1005.group03.DAO","l":"DatabaseConnection"},{"p":"no.ntnu.idatt1005.group03.Model","l":"Donation"},{"p":"no.ntnu.idatt1005.group03.UI","l":"DonationScreen"},{"p":"no.ntnu.idatt1005.group03.Controller","l":"FavoriteController"},{"p":"no.ntnu.idatt1005.group03.UI","l":"LoginScreen"},{"p":"no.ntnu.idatt1005.group03.Model","l":"Organization"},{"p":"no.ntnu.idatt1005.group03.Controller","l":"OrganizationController"},{"p":"no.ntnu.idatt1005.group03.DAO","l":"OrganizationDAO"},{"p":"no.ntnu.idatt1005.group03.UI","l":"OrganizationsScreen"},{"p":"no.ntnu.idatt1005.group03.Model","l":"Role","k":"9"},{"p":"no.ntnu.idatt1005.group03.Model","l":"SavedCharity"},{"p":"no.ntnu.idatt1005.group03.DAO","l":"SavedCharityDAO"},{"p":"no.ntnu.idatt1005.group03.Model","l":"SavedOrganization"},{"p":"no.ntnu.idatt1005.group03.UI","l":"ScreenManager"},{"p":"no.ntnu.idatt1005.group03.UI","l":"TopMenu"},{"p":"no.ntnu.idatt1005.group03.Model","l":"User"},{"p":"no.ntnu.idatt1005.group03.DAO","l":"UserRepository","k":"10"},{"p":"no.ntnu.idatt1005.group03.DAO","l":"UserRepositoryDAO"}];updateSearchResults();
\ No newline at end of file
+typeSearchIndex = [{"p":"no.ntnu.idatt1005.group03.ui","l":"AboutUsScreen"},{"p":"no.ntnu.idatt1005.group03.ui","l":"AccountScreen"},{"l":"All Classes and Interfaces","u":"allclasses-index.html","k":"18"},{"p":"no.ntnu.idatt1005.group03.service","l":"ApiClient"},{"p":"no.ntnu.idatt1005.group03","l":"App"},{"p":"no.ntnu.idatt1005.group03.controller","l":"AuthController"},{"p":"no.ntnu.idatt1005.group03.dao","l":"DatabaseConnection"},{"p":"no.ntnu.idatt1005.group03.model","l":"Donation"},{"p":"no.ntnu.idatt1005.group03.ui","l":"DonationScreen"},{"p":"no.ntnu.idatt1005.group03.controller","l":"FavoriteController"},{"p":"no.ntnu.idatt1005.group03.ui","l":"LoginScreen"},{"p":"no.ntnu.idatt1005.group03.model","l":"Organization"},{"p":"no.ntnu.idatt1005.group03.controller","l":"OrganizationController"},{"p":"no.ntnu.idatt1005.group03.dao","l":"OrganizationDAO"},{"p":"no.ntnu.idatt1005.group03.ui","l":"OrganizationsScreen"},{"p":"no.ntnu.idatt1005.group03.model","l":"Role","k":"9"},{"p":"no.ntnu.idatt1005.group03.model","l":"SavedCharity"},{"p":"no.ntnu.idatt1005.group03.dao","l":"SavedCharityDAO"},{"p":"no.ntnu.idatt1005.group03.model","l":"SavedOrganization"},{"p":"no.ntnu.idatt1005.group03.ui","l":"ScreenManager"},{"p":"no.ntnu.idatt1005.group03.ui","l":"TopMenu"},{"p":"no.ntnu.idatt1005.group03.model","l":"User"},{"p":"no.ntnu.idatt1005.group03.dao","l":"UserRepository","k":"10"},{"p":"no.ntnu.idatt1005.group03.dao","l":"UserRepositoryDAO"}];updateSearchResults();
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index c652e50..1af887f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -92,6 +92,19 @@
true
+
+
+ com.spotify.fmt
+ fmt-maven-plugin
+ 2.29
+
+
+ com.google.googlejavaformat
+ google-java-format
+ 1.27.0
+
+
+
-
\ No newline at end of file
+
diff --git a/src/main/java/no/ntnu/idatt1005/group03/App.java b/src/main/java/no/ntnu/idatt1005/group03/App.java
index ded5f58..527ec9e 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/App.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/App.java
@@ -3,26 +3,26 @@
import javafx.application.Application;
import javafx.scene.text.Font;
import javafx.stage.Stage;
-import no.ntnu.idatt1005.group03.DAO.DatabaseConnection;
-import no.ntnu.idatt1005.group03.UI.LoginScreen;
+import no.ntnu.idatt1005.group03.dao.DatabaseConnection;
+import no.ntnu.idatt1005.group03.ui.LoginScreen;
/**
* Starts the application and initializes required resources.
*
- * This class serves as the main entry point of the application. It is part of the
- * overall application bootstrap layer and is responsible for starting the JavaFX runtime,
- * initializing the database, and launching the first user interface screen.
+ * This class serves as the main entry point of the application. It is part of the overall
+ * application bootstrap layer and is responsible for starting the JavaFX runtime, initializing the
+ * database, and launching the first user interface screen.
*
- *
When the application starts, the database schema is initialized before the login
- * screen is displayed to the user.
+ * When the application starts, the database schema is initialized before the login screen is
+ * displayed to the user.
*/
public class App extends Application {
/**
* Starts the JavaFX application.
*
- *
This method initializes the database and launches the login screen on the provided
- * primary stage. If the user interface fails to load, an error message is printed.
+ * This method initializes the database and launches the login screen on the provided primary
+ * stage. If the user interface fails to load, an error message is printed.
*
* @param primaryStage the primary JavaFX stage for the application
*/
@@ -50,9 +50,7 @@ public static void main(String[] args) {
launch(args);
}
- /**
- * Loads bundled fonts so they are available to the shared stylesheet.
- */
+ /** Loads bundled fonts so they are available to the shared stylesheet. */
private void loadFonts() {
Font.loadFont(getClass().getResource("/fonts/Inter-Regular.ttf").toExternalForm(), 14);
Font.loadFont(getClass().getResource("/fonts/Inter-SemiBold.ttf").toExternalForm(), 14);
diff --git a/src/main/java/no/ntnu/idatt1005/group03/Controller/AuthController.java b/src/main/java/no/ntnu/idatt1005/group03/controller/AuthController.java
similarity index 59%
rename from src/main/java/no/ntnu/idatt1005/group03/Controller/AuthController.java
rename to src/main/java/no/ntnu/idatt1005/group03/controller/AuthController.java
index 7021491..d834ac2 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/Controller/AuthController.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/controller/AuthController.java
@@ -1,22 +1,21 @@
-package no.ntnu.idatt1005.group03.Controller;
-
-import no.ntnu.idatt1005.group03.DAO.UserRepository;
-import no.ntnu.idatt1005.group03.Model.Role;
-import no.ntnu.idatt1005.group03.Model.User;
+package no.ntnu.idatt1005.group03.controller;
import java.util.Objects;
import java.util.Optional;
+import no.ntnu.idatt1005.group03.dao.UserRepository;
+import no.ntnu.idatt1005.group03.model.Role;
+import no.ntnu.idatt1005.group03.model.User;
/**
* Handles authentication-related operations for users.
*
*
This class is part of the controller layer in the MVC architecture and is responsible
- * for coordinating login and registration logic between the user interface and the data access layer.
- * It validates user input, communicates with the {@code UserRepository}, and returns authentication
- * results to the caller.
+ * for coordinating login and registration logic between the user interface and the data access
+ * layer. It validates user input, communicates with the {@code UserRepository}, and returns
+ * authentication results to the caller.
*
* The controller supports login by either username or email address, and it ensures that
- * registration only succeeds when the provided user information is valid and unique.
+ * registration only succeeds when the provided user information is valid and unique.
*/
public class AuthController {
@@ -35,48 +34,53 @@ public AuthController(UserRepository userRepository) {
/**
* Attempts to authenticate a user with the given username or email and password.
*
- * If either input is null or blank, the login attempt fails immediately and an empty
- * {@code Optional} is returned. The method first tries to find a user by username, and if
- * no match is found, it then attempts to find a user by email. Authentication succeeds only
- * if the provided password matches the stored password value.
+ * If either input is null or blank, the login attempt fails immediately and an empty {@code
+ * Optional} is returned. The method first tries to find a user by username, and if no match is
+ * found, it then attempts to find a user by email. Authentication succeeds only if the provided
+ * password matches the stored password value.
*
* @param loginInput the username or email entered by the user
* @param password the password entered by the user
- * @return an {@code Optional} containing the authenticated user if login succeeds,
- * or an empty {@code Optional} if login fails
+ * @return an {@code Optional} containing the authenticated user if login succeeds, or an empty
+ * {@code Optional} if login fails
*/
public Optional login(String loginInput, String password) {
- if (loginInput == null || loginInput.isBlank()
- || password == null || password.isBlank()) {
+ if (loginInput == null || loginInput.isBlank() || password == null || password.isBlank()) {
return Optional.empty();
}
String trimmedInput = loginInput.trim();
- return userRepository.findByUserName(trimmedInput)
- .or(() -> userRepository.findByEmail(trimmedInput))
- .filter(user -> user.getPassword().equals(password));
+ return userRepository
+ .findByUserName(trimmedInput)
+ .or(() -> userRepository.findByEmail(trimmedInput))
+ .filter(user -> user.getPassword().equals(password));
}
/**
* Attempts to register a new user with the given credentials.
*
- * Registration succeeds only if all input values are non-null and non-blank, the password
- * and confirmation password match, and no existing user is found with the same username or email.
- * A newly registered user is assigned the default role {@code Role.USER}.
+ * Registration succeeds only if all input values are non-null and non-blank, the password and
+ * confirmation password match, and no existing user is found with the same username or email. A
+ * newly registered user is assigned the default role {@code Role.USER}.
*
* @param username the desired username
* @param email the email address of the new user
* @param password the password for the new user
* @param confirmPassword the confirmation of the password
- * @return an {@code Optional} containing the newly created user if registration succeeds,
- * or an empty {@code Optional} if registration fails
+ * @return an {@code Optional} containing the newly created user if registration succeeds, or an
+ * empty {@code Optional} if registration fails
*/
- public Optional register(String username, String email, String password, String confirmPassword) {
- if (username == null || username.isBlank()
- || email == null || email.isBlank()
- || password == null || password.isBlank()
- || confirmPassword == null || confirmPassword.isBlank()) {
+ public Optional register(
+ String username, String email, String password, String confirmPassword) {
+ if (username == null
+ || username.isBlank()
+ || email == null
+ || email.isBlank()
+ || password == null
+ || password.isBlank()
+ || confirmPassword == null
+ || confirmPassword.isBlank()) {
return Optional.empty();
}
@@ -100,4 +104,4 @@ public Optional register(String username, String email, String password, S
return Optional.of(newUser);
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/no/ntnu/idatt1005/group03/Controller/FavoriteController.java b/src/main/java/no/ntnu/idatt1005/group03/controller/FavoriteController.java
similarity index 75%
rename from src/main/java/no/ntnu/idatt1005/group03/Controller/FavoriteController.java
rename to src/main/java/no/ntnu/idatt1005/group03/controller/FavoriteController.java
index 08a2fff..812d9be 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/Controller/FavoriteController.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/controller/FavoriteController.java
@@ -1,26 +1,25 @@
-package no.ntnu.idatt1005.group03.Controller;
-
-import no.ntnu.idatt1005.group03.DAO.OrganizationDAO;
-import no.ntnu.idatt1005.group03.DAO.SavedCharityDAO;
-import no.ntnu.idatt1005.group03.Model.Organization;
-import no.ntnu.idatt1005.group03.Model.SavedCharity;
-import no.ntnu.idatt1005.group03.Model.User;
+package no.ntnu.idatt1005.group03.controller;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+import no.ntnu.idatt1005.group03.dao.OrganizationDAO;
+import no.ntnu.idatt1005.group03.dao.SavedCharityDAO;
+import no.ntnu.idatt1005.group03.model.Organization;
+import no.ntnu.idatt1005.group03.model.SavedCharity;
+import no.ntnu.idatt1005.group03.model.User;
/**
* Handles favorite organization operations for users.
*
* This class is part of the controller layer in the MVC architecture and is responsible
- * for coordinating favorite-related actions between the user interface, the data access layer,
- * and the user model. It manages the addition, removal, loading, and toggling of a user's
- * favorite organizations.
+ * for coordinating favorite-related actions between the user interface, the data access layer, and
+ * the user model. It manages the addition, removal, loading, and toggling of a user's favorite
+ * organizations.
*
* The controller stores favorite relationships using {@code SavedCharityDAO} and retrieves
- * organization details through {@code OrganizationDAO}. It also keeps the user's in-memory
- * favorite organization list synchronized with the persisted data.
+ * organization details through {@code OrganizationDAO}. It also keeps the user's in-memory favorite
+ * organization list synchronized with the persisted data.
*/
public class FavoriteController {
private final SavedCharityDAO savedCharityDAO;
@@ -29,8 +28,8 @@ public class FavoriteController {
/**
* Constructs a new {@code FavoriteController} with default DAO implementations.
*
- * This constructor creates a {@code SavedCharityDAO} and an {@code OrganizationDAO}
- * for use by the controller.
+ * This constructor creates a {@code SavedCharityDAO} and an {@code OrganizationDAO} for use by
+ * the controller.
*/
public FavoriteController() {
this(new SavedCharityDAO(), new OrganizationDAO());
@@ -39,23 +38,26 @@ public FavoriteController() {
/**
* Constructs a new {@code FavoriteController} with the given DAO dependencies.
*
- *
This constructor supports dependency injection, which is useful for testing
- * and for supplying alternative DAO implementations.
+ * This constructor supports dependency injection, which is useful for testing and for
+ * supplying alternative DAO implementations.
*
* @param savedCharityDAO the DAO used to store and remove favorite relationships
* @param organizationDAO the DAO used to retrieve organization details
- * @throws NullPointerException if {@code savedCharityDAO} or {@code organizationDAO} is {@code null}
+ * @throws NullPointerException if {@code savedCharityDAO} or {@code organizationDAO} is {@code
+ * null}
*/
public FavoriteController(SavedCharityDAO savedCharityDAO, OrganizationDAO organizationDAO) {
- this.savedCharityDAO = Objects.requireNonNull(savedCharityDAO, "savedCharityDAO cannot be null");
- this.organizationDAO = Objects.requireNonNull(organizationDAO, "organizationDAO cannot be null");
+ this.savedCharityDAO =
+ Objects.requireNonNull(savedCharityDAO, "savedCharityDAO cannot be null");
+ this.organizationDAO =
+ Objects.requireNonNull(organizationDAO, "organizationDAO cannot be null");
}
/**
* Adds an organization to the user's list of favorites.
*
*
The favorite relationship is first stored through the data access layer, and the
- * organization is then added to the user's in-memory list of favorite organizations.
+ * organization is then added to the user's in-memory list of favorite organizations.
*
* @param user the user who is adding the favorite organization
* @param organization the organization to add as a favorite
@@ -70,8 +72,8 @@ public void addFavorite(User user, Organization organization) {
* Loads all favorite organizations for the given user.
*
* The method retrieves saved favorite relationships for the user, resolves the corresponding
- * organizations through the organization data access layer, and updates the user's in-memory
- * list of favorite organizations.
+ * organizations through the organization data access layer, and updates the user's in-memory list
+ * of favorite organizations.
*
* @param user the user whose favorites should be loaded
*/
@@ -92,8 +94,8 @@ public void loadFavorites(User user) {
/**
* Removes an organization from the user's list of favorites.
*
- * The favorite relationship is removed through the data access layer, and the organization
- * is then removed from the user's in-memory list of favorite organizations.
+ * The favorite relationship is removed through the data access layer, and the organization is
+ * then removed from the user's in-memory list of favorite organizations.
*
* @param user the user who is removing the favorite organization
* @param organization the organization to remove from favorites
@@ -107,8 +109,8 @@ public void removeFavorite(User user, Organization organization) {
/**
* Toggles the favorite status of an organization for a user.
*
- *
If the organization is already marked as a favorite, it is removed. Otherwise,
- * it is added to the user's favorites.
+ * If the organization is already marked as a favorite, it is removed. Otherwise, it is added
+ * to the user's favorites.
*
* @param user the user whose favorite list should be updated
* @param organization the organization to toggle
diff --git a/src/main/java/no/ntnu/idatt1005/group03/Controller/OrganizationController.java b/src/main/java/no/ntnu/idatt1005/group03/controller/OrganizationController.java
similarity index 68%
rename from src/main/java/no/ntnu/idatt1005/group03/Controller/OrganizationController.java
rename to src/main/java/no/ntnu/idatt1005/group03/controller/OrganizationController.java
index 9e51c27..5533846 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/Controller/OrganizationController.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/controller/OrganizationController.java
@@ -1,12 +1,10 @@
-package no.ntnu.idatt1005.group03.Controller;
-
-import no.ntnu.idatt1005.group03.DAO.OrganizationDAO;
-import no.ntnu.idatt1005.group03.Model.Organization;
-import no.ntnu.idatt1005.group03.Service.ApiClient;
+package no.ntnu.idatt1005.group03.controller;
import java.util.List;
-import java.util.Locale;
import java.util.Objects;
+import no.ntnu.idatt1005.group03.dao.OrganizationDAO;
+import no.ntnu.idatt1005.group03.model.Organization;
+import no.ntnu.idatt1005.group03.service.ApiClient;
/**
* Handles organization-related operations in the application.
@@ -14,11 +12,11 @@
*
This class is part of the controller layer in the MVC architecture and is responsible
* for coordinating access to organization data between the user interface, the data access layer,
* and the external API layer. It maintains a local cache of organizations and provides operations
- * for retrieving, searching, and synchronizing organization data.
+ * for retrieving, searching, and synchronizing organization data.
*
- * When the controller is created, it attempts to load organizations from the database.
- * If no organizations are found, it automatically fetches data from the external API and stores
- * the result in the database.
+ * When the controller is created, it attempts to load organizations from the database. If no
+ * organizations are found, it automatically fetches data from the external API and stores the
+ * result in the database.
*/
public class OrganizationController {
private final OrganizationDAO orgDAO;
@@ -28,9 +26,9 @@ public class OrganizationController {
/**
* Constructs a new {@code OrganizationController} with default DAO implementations.
*
- *
The controller initializes its data access object and loads organizations
- * from the database into an internal cache. If the database does not contain any
- * organizations, the controller attempts to synchronize organization data from the API.
+ * The controller initializes its data access object and loads organizations from the database
+ * into an internal cache. If the database does not contain any organizations, the controller
+ * attempts to synchronize organization data from the API.
*/
public OrganizationController() {
this(new OrganizationDAO(), new ApiClient());
@@ -39,12 +37,12 @@ public OrganizationController() {
/**
* Constructs a new {@code OrganizationController} with the given dependencies.
*
- *
This constructor supports dependency injection, allowing custom implementations
- * of {@code OrganizationDAO} and {@code ApiClient} to be provided (e.g., for testing).
+ * This constructor supports dependency injection, allowing custom implementations of {@code
+ * OrganizationDAO} and {@code ApiClient} to be provided (e.g., for testing).
*
- *
When initialized, the controller loads organizations from the database into an
- * internal cache. If no organizations are found, it automatically attempts to fetch
- * and store data from the external API.
+ * When initialized, the controller loads organizations from the database into an internal
+ * cache. If no organizations are found, it automatically attempts to fetch and store data from
+ * the external API.
*
* @param orgDAO the DAO used to access and persist organization data
* @param apiClient the client used to fetch organization data from the external API
@@ -73,9 +71,9 @@ public List getOrganizations() {
/**
* Searches the cached organizations by name or category.
*
- * If the query is null or blank, the full list of cached organizations is returned.
- * Otherwise, the method returns all organizations whose name or category contains the
- * given query string, ignoring case.
+ * If the query is null or blank, the full list of cached organizations is returned. Otherwise,
+ * the method returns all organizations whose name or category contains the given query string,
+ * ignoring case.
*
* @param query the search query used to filter organizations
* @return a list of organizations matching the search query
@@ -87,20 +85,24 @@ public List searchOrganizations(String query) {
String lowerCaseQuery = query.trim().toLowerCase();
return cachedOrganizations.stream()
- .filter(org -> {
- boolean matchesName = org.getName() != null && org.getName().toLowerCase().contains(lowerCaseQuery);
- boolean matchesCategory = org.getCategory() != null && org.getCategory().toLowerCase().contains(lowerCaseQuery);
+ .filter(
+ org -> {
+ boolean matchesName =
+ org.getName() != null && org.getName().toLowerCase().contains(lowerCaseQuery);
+ boolean matchesCategory =
+ org.getCategory() != null
+ && org.getCategory().toLowerCase().contains(lowerCaseQuery);
return matchesName || matchesCategory;
})
- .toList();
+ .toList();
}
/**
* Refreshes the internal cache of organizations from the database.
*
- * This method reloads the cached organization list by retrieving the latest
- * organizations from the data access layer.
+ * This method reloads the cached organization list by retrieving the latest organizations from
+ * the data access layer.
*/
public void refreshCache() {
this.cachedOrganizations = orgDAO.getAllOrganizations();
@@ -110,13 +112,12 @@ public void refreshCache() {
/**
* Synchronizes organizations from the external API to the database.
*
- *
This method fetches organizations from the external API using {@code ApiClient}.
- * If new organizations are returned, they are saved to the database and the internal
- * cache is refreshed. If no organizations are returned, the method assumes that the
- * local data is already up to date.
+ * This method fetches organizations from the external API using {@code ApiClient}. If new
+ * organizations are returned, they are saved to the database and the internal cache is refreshed.
+ * If no organizations are returned, the method assumes that the local data is already up to date.
*
- *
If an error occurs during synchronization, the exception is caught and an error
- * message is printed to the standard error output.
+ * If an error occurs during synchronization, the exception is caught and an error message is
+ * printed to the standard error output.
*/
public void syncOrganizationsFromApi() {
try {
diff --git a/src/main/java/no/ntnu/idatt1005/group03/DAO/DatabaseConnection.java b/src/main/java/no/ntnu/idatt1005/group03/dao/DatabaseConnection.java
similarity index 73%
rename from src/main/java/no/ntnu/idatt1005/group03/DAO/DatabaseConnection.java
rename to src/main/java/no/ntnu/idatt1005/group03/dao/DatabaseConnection.java
index 0072150..ef3c367 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/DAO/DatabaseConnection.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/dao/DatabaseConnection.java
@@ -1,4 +1,4 @@
-package no.ntnu.idatt1005.group03.DAO;
+package no.ntnu.idatt1005.group03.dao;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -8,21 +8,18 @@
/**
* Provides access to the application's database and initializes required tables.
*
- *
This class is part of the DAO layer in the MVC architecture and is responsible
- * for managing the database connection used by the application's data access objects.
- * It also contains logic for initializing the database schema required by the system.
+ * This class is part of the DAO layer in the MVC architecture and is responsible for
+ * managing the database connection used by the application's data access objects. It also contains
+ * logic for initializing the database schema required by the system.
*
- *
The class uses SQLite as the underlying database and creates the necessary tables
- * for organizations, users, and saved charities if they do not already exist.
+ * The class uses SQLite as the underlying database and creates the necessary tables for
+ * organizations, users, and saved charities if they do not already exist.
*/
public class DatabaseConnection {
private static final String URL = "jdbc:sqlite:./hmh.db";
- /**
- * Prevents instantiation of this utility class.
- */
- private DatabaseConnection() {
- }
+ /** Prevents instantiation of this utility class. */
+ private DatabaseConnection() {}
/**
* Returns a new database connection to the application's SQLite database.
@@ -37,15 +34,16 @@ public static Connection getConnection() throws SQLException {
/**
* Initializes the database by creating the required tables if they do not already exist.
*
- *
This method creates tables for organizations, users, and saved charities.
- * It also enables SQLite foreign key support before executing the table creation statements.
+ * This method creates tables for organizations, users, and saved charities. It also enables
+ * SQLite foreign key support before executing the table creation statements.
*
- *
If initialization succeeds, a success message is printed to the console.
- * If an error occurs, an error message and the reason are printed instead.
+ * If initialization succeeds, a success message is printed to the console. If an error occurs,
+ * an error message and the reason are printed instead.
*/
public static void initializeDatabase() {
- String createOrganizationTable = """
- CREATE TABLE IF NOT EXISTS organizations (
+ String createOrganizationTable =
+ """
+ CREATE TABLE IF NOT EXISTS organizations (
org_number TEXT PRIMARY KEY,
name TEXT NOT NULL,
status TEXT,
@@ -54,7 +52,8 @@ CREATE TABLE IF NOT EXISTS organizations (
);
""";
- String createUserTable = """
+ String createUserTable =
+ """
CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY,
username TEXT NOT NULL UNIQUE,
@@ -64,7 +63,8 @@ CREATE TABLE IF NOT EXISTS users (
);
""";
- String createSavedCharitiesTable = """
+ String createSavedCharitiesTable =
+ """
CREATE TABLE IF NOT EXISTS saved_charities (
user_id TEXT NOT NULL,
org_number TEXT NOT NULL,
@@ -75,7 +75,7 @@ FOREIGN KEY (org_number) REFERENCES organizations(org_number) ON DELETE CASCADE
""";
try (Connection conn = getConnection();
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("PRAGMA foreign_keys = ON;");
stmt.execute(createOrganizationTable);
diff --git a/src/main/java/no/ntnu/idatt1005/group03/DAO/OrganizationDAO.java b/src/main/java/no/ntnu/idatt1005/group03/dao/OrganizationDAO.java
similarity index 81%
rename from src/main/java/no/ntnu/idatt1005/group03/DAO/OrganizationDAO.java
rename to src/main/java/no/ntnu/idatt1005/group03/dao/OrganizationDAO.java
index c1dc2a0..ac5c820 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/DAO/OrganizationDAO.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/dao/OrganizationDAO.java
@@ -1,6 +1,5 @@
-package no.ntnu.idatt1005.group03.DAO;
+package no.ntnu.idatt1005.group03.dao;
-import no.ntnu.idatt1005.group03.Model.Organization;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -8,24 +7,25 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+import no.ntnu.idatt1005.group03.model.Organization;
/**
* Provides database access for {@link Organization} entities.
*
- *
This class is part of the DAO layer in the MVC architecture and is responsible
- * for persisting and retrieving organization data from the database. It handles storage,
- * lookup, and retrieval of organizations used throughout the application.
+ * This class is part of the DAO layer in the MVC architecture and is responsible for
+ * persisting and retrieving organization data from the database. It handles storage, lookup, and
+ * retrieval of organizations used throughout the application.
*
- *
The class uses JDBC to communicate with the database and maps rows from the
- * {@code organizations} table to {@code Organization} objects.
+ * The class uses JDBC to communicate with the database and maps rows from the {@code
+ * organizations} table to {@code Organization} objects.
*/
public class OrganizationDAO {
/**
* Saves a list of organizations to the database.
*
- *
Each organization is inserted into the {@code organizations} table if it does not
- * already exist. Existing entries are ignored.
+ * Each organization is inserted into the {@code organizations} table if it does not already
+ * exist. Existing entries are ignored.
*
* @param organizations the list of organizations to save
* @throws NullPointerException if {@code organizations} is null
@@ -33,13 +33,14 @@ public class OrganizationDAO {
public void saveAll(List organizations) {
Objects.requireNonNull(organizations, "organizations cannot be null");
- String sql = """
- INSERT OR IGNORE INTO organizations (org_number, name, status, url, category)
+ String sql =
+ """
+ INSERT OR IGNORE INTO organizations (org_number, name, status, url, category)
VALUES (?, ?, ?, ?, ?)
""";
try (Connection conn = DatabaseConnection.getConnection();
- PreparedStatement pstmt = conn.prepareStatement(sql)) {
+ PreparedStatement pstmt = conn.prepareStatement(sql)) {
int count = 0;
for (Organization org : organizations) {
@@ -70,8 +71,8 @@ public List getAllOrganizations() {
String sql = "SELECT * FROM organizations";
try (Connection conn = DatabaseConnection.getConnection();
- PreparedStatement pstmt = conn.prepareStatement(sql);
- ResultSet rs = pstmt.executeQuery()) {
+ PreparedStatement pstmt = conn.prepareStatement(sql);
+ ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
Organization org = new Organization();
@@ -93,8 +94,7 @@ public List getAllOrganizations() {
/**
* Retrieves all verified organizations from the database.
*
- * A verified organization is defined as an organization whose status is
- * {@code approved}.
+ * A verified organization is defined as an organization whose status is {@code approved}.
*
* @return a list of all verified organizations
*/
@@ -103,8 +103,8 @@ public List getAllVerifiedOrganizations() {
String sql = "SELECT * FROM organizations WHERE status = 'approved'";
try (Connection conn = DatabaseConnection.getConnection();
- PreparedStatement pstmt = conn.prepareStatement(sql);
- ResultSet rs = pstmt.executeQuery()) {
+ PreparedStatement pstmt = conn.prepareStatement(sql);
+ ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
Organization org = new Organization();
@@ -127,14 +127,14 @@ public List getAllVerifiedOrganizations() {
* Finds an organization by its organization number.
*
* @param orgNumber the organization number to search for
- * @return the matching organization if found, or {@code null} if no organization exists
- * with the given organization number
+ * @return the matching organization if found, or {@code null} if no organization exists with the
+ * given organization number
*/
public Organization findByOrgNumber(String orgNumber) {
String sql = "SELECT * FROM organizations WHERE org_number = ?";
try (Connection conn = DatabaseConnection.getConnection();
- PreparedStatement pstmt = conn.prepareStatement(sql)) {
+ PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, orgNumber);
@@ -155,4 +155,4 @@ public Organization findByOrgNumber(String orgNumber) {
return null;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/no/ntnu/idatt1005/group03/DAO/SavedCharityDAO.java b/src/main/java/no/ntnu/idatt1005/group03/dao/SavedCharityDAO.java
similarity index 80%
rename from src/main/java/no/ntnu/idatt1005/group03/DAO/SavedCharityDAO.java
rename to src/main/java/no/ntnu/idatt1005/group03/dao/SavedCharityDAO.java
index a2f0e95..daaebde 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/DAO/SavedCharityDAO.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/dao/SavedCharityDAO.java
@@ -1,6 +1,4 @@
-package no.ntnu.idatt1005.group03.DAO;
-
-import no.ntnu.idatt1005.group03.Model.SavedCharity;
+package no.ntnu.idatt1005.group03.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -9,23 +7,24 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+import no.ntnu.idatt1005.group03.model.SavedCharity;
/**
* Provides database access for {@link SavedCharity} entities.
*
- * This class is part of the DAO layer in the MVC architecture and is responsible
- * for storing and retrieving the relationship between users and their saved organizations.
- * It handles persistence of favorite organizations in the database.
+ * This class is part of the DAO layer in the MVC architecture and is responsible for
+ * storing and retrieving the relationship between users and their saved organizations. It handles
+ * persistence of favorite organizations in the database.
*
- *
The class uses JDBC to communicate with the database and maps rows from the
- * {@code saved_charities} table to {@code SavedCharity} objects.
+ * The class uses JDBC to communicate with the database and maps rows from the {@code
+ * saved_charities} table to {@code SavedCharity} objects.
*/
public class SavedCharityDAO {
/**
* Adds a saved charity entry to the database.
*
- *
If the same user-organization relationship already exists, the insert is ignored.
+ * If the same user-organization relationship already exists, the insert is ignored.
*
* @param charity the saved charity entry to add
* @throws NullPointerException if {@code charity} is null
@@ -33,12 +32,13 @@ public class SavedCharityDAO {
public void addFavorite(SavedCharity charity) {
Objects.requireNonNull(charity, "charity cannot be null");
- String sql = """
- INSERT OR IGNORE INTO saved_charities (user_id, org_number)
+ String sql =
+ """
+ INSERT OR IGNORE INTO saved_charities (user_id, org_number)
VALUES (?, ?)
""";
- try(Connection conn = DatabaseConnection.getConnection();
+ try (Connection conn = DatabaseConnection.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, charity.getUserId());
@@ -55,7 +55,7 @@ INSERT OR IGNORE INTO saved_charities (user_id, org_number)
/**
* Removes a saved charity entry from the database.
*
- *
The entry is identified by the combination of user ID and organization ID.
+ * The entry is identified by the combination of user ID and organization ID.
*
* @param charity the saved charity entry to remove
* @throws NullPointerException if {@code charity} is null
@@ -63,13 +63,14 @@ INSERT OR IGNORE INTO saved_charities (user_id, org_number)
public void removeFavorite(SavedCharity charity) {
Objects.requireNonNull(charity, "charity cannot be null");
- String sql = """
- DELETE FROM saved_charities
- WHERE user_id = ?
+ String sql =
+ """
+ DELETE FROM saved_charities
+ WHERE user_id = ?
AND org_number = ?
""";
- try(Connection conn = DatabaseConnection.getConnection();
+ try (Connection conn = DatabaseConnection.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, charity.getUserId());
@@ -94,11 +95,12 @@ public List getFavoritesFromUser(String userId) {
Objects.requireNonNull(userId, "userId cannot be null");
List savedCharities = new ArrayList<>();
- String sql = """
+ String sql =
+ """
SELECT * FROM saved_charities WHERE user_id = ?
""";
- try(Connection conn = DatabaseConnection.getConnection();
+ try (Connection conn = DatabaseConnection.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, userId);
diff --git a/src/main/java/no/ntnu/idatt1005/group03/DAO/UserRepository.java b/src/main/java/no/ntnu/idatt1005/group03/dao/UserRepository.java
similarity index 69%
rename from src/main/java/no/ntnu/idatt1005/group03/DAO/UserRepository.java
rename to src/main/java/no/ntnu/idatt1005/group03/dao/UserRepository.java
index 95a2374..8e16434 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/DAO/UserRepository.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/dao/UserRepository.java
@@ -1,19 +1,18 @@
-package no.ntnu.idatt1005.group03.DAO;
-
-import no.ntnu.idatt1005.group03.Model.User;
+package no.ntnu.idatt1005.group03.dao;
import java.util.List;
import java.util.Optional;
+import no.ntnu.idatt1005.group03.model.User;
/**
* Defines the contract for user data access operations.
*
- * This interface is part of the DAO layer in the MVC architecture and specifies
- * the operations required for storing and retrieving {@link User} entities. It provides
- * an abstraction between the controller layer and the concrete persistence implementation.
+ * This interface is part of the DAO layer in the MVC architecture and specifies the
+ * operations required for storing and retrieving {@link User} entities. It provides an abstraction
+ * between the controller layer and the concrete persistence implementation.
*
- *
Implementations of this interface are responsible for handling access to the underlying
- * data source, such as a database.
+ * Implementations of this interface are responsible for handling access to the underlying data
+ * source, such as a database.
*/
public interface UserRepository {
@@ -28,7 +27,8 @@ public interface UserRepository {
* Finds a user by its unique identifier.
*
* @param id the ID of the user to find
- * @return an {@code Optional} containing the matching user if found, otherwise an empty {@code Optional}
+ * @return an {@code Optional} containing the matching user if found, otherwise an empty {@code
+ * Optional}
*/
Optional findById(String id);
@@ -36,7 +36,8 @@ public interface UserRepository {
* Finds a user by username.
*
* @param username the username of the user to find
- * @return an {@code Optional} containing the matching user if found, otherwise an empty {@code Optional}
+ * @return an {@code Optional} containing the matching user if found, otherwise an empty {@code
+ * Optional}
*/
Optional findByUserName(String username);
@@ -44,7 +45,8 @@ public interface UserRepository {
* Finds a user by email address.
*
* @param email the email address of the user to find
- * @return an {@code Optional} containing the matching user if found, otherwise an empty {@code Optional}
+ * @return an {@code Optional} containing the matching user if found, otherwise an empty {@code
+ * Optional}
*/
Optional findByEmail(String email);
diff --git a/src/main/java/no/ntnu/idatt1005/group03/DAO/UserRepositoryDAO.java b/src/main/java/no/ntnu/idatt1005/group03/dao/UserRepositoryDAO.java
similarity index 75%
rename from src/main/java/no/ntnu/idatt1005/group03/DAO/UserRepositoryDAO.java
rename to src/main/java/no/ntnu/idatt1005/group03/dao/UserRepositoryDAO.java
index f0876eb..8c67547 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/DAO/UserRepositoryDAO.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/dao/UserRepositoryDAO.java
@@ -1,7 +1,4 @@
-package no.ntnu.idatt1005.group03.DAO;
-
-import no.ntnu.idatt1005.group03.Model.Role;
-import no.ntnu.idatt1005.group03.Model.User;
+package no.ntnu.idatt1005.group03.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -11,25 +8,26 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
+import no.ntnu.idatt1005.group03.model.Role;
+import no.ntnu.idatt1005.group03.model.User;
/**
* Provides database access for {@link User} entities.
*
- * This class is part of the DAO layer in the MVC architecture and is responsible
- * for persisting and retrieving user data from the database. It implements the
- * {@link UserRepository} interface and acts as the concrete data access component for
- * user-related operations.
+ * This class is part of the DAO layer in the MVC architecture and is responsible for
+ * persisting and retrieving user data from the database. It implements the {@link UserRepository}
+ * interface and acts as the concrete data access component for user-related operations.
*
- *
The class uses JDBC to communicate with the database and maps rows from the
- * {@code users} table to {@code User} objects.
+ * The class uses JDBC to communicate with the database and maps rows from the {@code users}
+ * table to {@code User} objects.
*/
public class UserRepositoryDAO implements UserRepository {
/**
* Saves a user to the database.
*
- *
The user is inserted into the {@code users} table with its ID, username, email,
- * password, and role.
+ * The user is inserted into the {@code users} table with its ID, username, email, password,
+ * and role.
*
* @param user the user to save
* @throws NullPointerException if {@code user} is null
@@ -39,12 +37,13 @@ public class UserRepositoryDAO implements UserRepository {
public void save(User user) {
Objects.requireNonNull(user, "user cannot be null");
- String sql = """
+ String sql =
+ """
INSERT INTO users (Id, username, email, password, role)
VALUES (?, ?, ?, ?, ?)
""";
try (Connection conn = DatabaseConnection.getConnection();
- PreparedStatement pStat = conn.prepareStatement(sql)) {
+ PreparedStatement pStat = conn.prepareStatement(sql)) {
pStat.setString(1, user.getId());
pStat.setString(2, user.getUsername());
pStat.setString(3, user.getEmail());
@@ -62,31 +61,35 @@ INSERT INTO users (Id, username, email, password, role)
* Finds a user by its unique identifier.
*
* @param id the ID of the user to find
- * @return an {@code Optional} containing the matching user if found, otherwise an empty {@code Optional}
+ * @return an {@code Optional} containing the matching user if found, otherwise an empty {@code
+ * Optional}
* @throws RuntimeException if a database access error occurs while searching for the user
*/
@Override
public Optional findById(String id) {
- String sql = "SELECT id, username, email, password, role FROM users WHERE id = ?";
+ String sql = "SELECT id, username, email, password, role FROM users WHERE id = ?";
- try (Connection conn = DatabaseConnection.getConnection();
- PreparedStatement pStat = conn.prepareStatement(sql)) {
- pStat.setString(1, id);
+ try (Connection conn = DatabaseConnection.getConnection();
+ PreparedStatement pStat = conn.prepareStatement(sql)) {
+ pStat.setString(1, id);
- try (ResultSet rs = pStat.executeQuery()) {
- if (!rs.next()) return Optional.empty();
- return Optional.of(mapRowToUser(rs));
+ try (ResultSet rs = pStat.executeQuery()) {
+ if (!rs.next()) {
+ return Optional.empty();
}
- } catch (SQLException e) {
- throw new RuntimeException("Failed to find user by id:" + e.getMessage(), e);
+ return Optional.of(mapRowToUser(rs));
}
+ } catch (SQLException e) {
+ throw new RuntimeException("Failed to find user by id:" + e.getMessage(), e);
}
+ }
/**
* Finds a user by username.
*
* @param username the username of the user to find
- * @return an {@code Optional} containing the matching user if found, otherwise an empty {@code Optional}
+ * @return an {@code Optional} containing the matching user if found, otherwise an empty {@code
+ * Optional}
* @throws RuntimeException if a database access error occurs while searching for the user
*/
@Override
@@ -94,7 +97,7 @@ public Optional findByUserName(String username) {
String sql = "SELECT id, username, email, password, role FROM users WHERE username = ?";
try (Connection conn = DatabaseConnection.getConnection();
- PreparedStatement pStat = conn.prepareStatement(sql)) {
+ PreparedStatement pStat = conn.prepareStatement(sql)) {
pStat.setString(1, username);
@@ -114,15 +117,16 @@ public Optional findByUserName(String username) {
* Finds a user by email address.
*
* @param email the email address of the user to find
- * @return an {@code Optional} containing the matching user if found, otherwise an empty {@code Optional}
+ * @return an {@code Optional} containing the matching user if found, otherwise an empty {@code
+ * Optional}
* @throws RuntimeException if a database access error occurs while searching for the user
*/
@Override
- public Optional findByEmail(String email) {
+ public Optional findByEmail(String email) {
String sql = "SELECT id, username, email, password, role FROM users WHERE email = ?";
try (Connection conn = DatabaseConnection.getConnection();
- PreparedStatement pStat = conn.prepareStatement(sql)) {
+ PreparedStatement pStat = conn.prepareStatement(sql)) {
pStat.setString(1, email);
@@ -151,8 +155,8 @@ public List findAll() {
List users = new ArrayList<>();
try (Connection conn = DatabaseConnection.getConnection();
- PreparedStatement pStat = conn.prepareStatement(sql);
- ResultSet rs = pStat.executeQuery()) {
+ PreparedStatement pStat = conn.prepareStatement(sql);
+ ResultSet rs = pStat.executeQuery()) {
while (rs.next()) {
users.add(mapRowToUser(rs));
@@ -182,4 +186,3 @@ private User mapRowToUser(ResultSet rs) throws SQLException {
return new User(id, username, email, password, role);
}
}
-
diff --git a/src/main/java/no/ntnu/idatt1005/group03/Model/Donation.java b/src/main/java/no/ntnu/idatt1005/group03/model/Donation.java
similarity index 75%
rename from src/main/java/no/ntnu/idatt1005/group03/Model/Donation.java
rename to src/main/java/no/ntnu/idatt1005/group03/model/Donation.java
index c42836c..81bc06e 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/Model/Donation.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/model/Donation.java
@@ -1,4 +1,4 @@
-package no.ntnu.idatt1005.group03.Model;
+package no.ntnu.idatt1005.group03.model;
import java.time.LocalDate;
import java.util.Objects;
@@ -6,12 +6,12 @@
/**
* Represents a donation made by a user to an organization.
- *
- * This class is part of the model layer in the MVC architecture and is responsible
- * for storing and representing donation data. It contains information about the donor,
- * the organization, the donation amount, and the date of the donation.
- *
- * Each donation is assigned a unique identifier upon creation.
+ *
+ *
This class is part of the model layer in the MVC architecture and is responsible for storing
+ * and representing donation data. It contains information about the donor, the organization, the
+ * donation amount, and the date of the donation.
+ *
+ *
Each donation is assigned a unique identifier upon creation.
*/
public class Donation {
private final String id;
@@ -23,20 +23,21 @@ public class Donation {
/**
* Constructs a new {@code Donation} instance.
- *
- * A unique ID is automatically generated for each donation. The amount must be positive,
- * and all other fields must be non-null.
- *
+ *
+ *
A unique ID is automatically generated for each donation. The amount must be positive, and
+ * all other fields must be non-null.
+ *
* @param userId the ID of the user making the donation
* @param organizationId the ID of the organization receiving the donation
* @param amount the donation amount (must be greater than 0)
* @param date the date the donation was made
* @param organizationName the name of the organization
* @throws IllegalArgumentException if {@code amount <= 0}
- * @throws NullPointerException if any of {@code userId}, {@code organizationId},
- * {@code date}, or {@code organizationName} is null
+ * @throws NullPointerException if any of {@code userId}, {@code organizationId}, {@code date}, or
+ * {@code organizationName} is null
*/
- public Donation(String userId, String organizationId, int amount, LocalDate date,String organizationName) {
+ public Donation(
+ String userId, String organizationId, int amount, LocalDate date, String organizationName) {
if (amount <= 0) {
throw new IllegalArgumentException("amount must be positive");
diff --git a/src/main/java/no/ntnu/idatt1005/group03/Model/Organization.java b/src/main/java/no/ntnu/idatt1005/group03/model/Organization.java
similarity index 81%
rename from src/main/java/no/ntnu/idatt1005/group03/Model/Organization.java
rename to src/main/java/no/ntnu/idatt1005/group03/model/Organization.java
index e10f3af..a4caee6 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/Model/Organization.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/model/Organization.java
@@ -1,20 +1,18 @@
-package no.ntnu.idatt1005.group03.Model;
+package no.ntnu.idatt1005.group03.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
-
import java.util.Objects;
-
/**
- * Represents an organization
+ * Represents an organization.
*
- *
This class is part of the model layer in the MVC architecture and is responsible
- * for storing and representing organization data. It is typically populated from external
- * API responses using Jackson for JSON deserialization.
+ * This class is part of the model layer in the MVC architecture and is responsible for storing
+ * and representing organization data. It is typically populated from external API responses using
+ * Jackson for JSON deserialization.
*
- *
The class includes basic information such as organization number, name, status,
- * and website URL, as well as a category used for grouping or filtering organizations.
+ * The class includes basic information such as organization number, name, status, and website
+ * URL, as well as a category used for grouping or filtering organizations.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class Organization {
@@ -32,15 +30,11 @@ public class Organization {
private String category = "general";
- /**
- * Default constructor required by Jackson for JSON deserialization.
- */
- public Organization() {
- }
+ /** Default constructor required by Jackson for JSON deserialization. */
+ public Organization() {}
/**
- * Constructs a new {@code Organization} instance.
- * All fields must be non-null
+ * Constructs a new {@code Organization} instance. All fields must be non-null
*
* @param orgNumber the unique organization number
* @param name the name of the organization
@@ -147,8 +141,8 @@ public void setCategory(String category) {
/**
* Checks whether the organization is approved.
*
- *
An organization is considered approved if its status is equal to
- * {@code "approved"} (case-insensitive).
+ * An organization is considered approved if its status is equal to {@code "approved"}
+ * (case-insensitive).
*
* @return {@code true} if the organization is approved, otherwise {@code false}
*/
@@ -163,8 +157,13 @@ public boolean isApprovedByIK() {
*/
@Override
public String toString() {
- return "Organization: " + "[" + orgNumber + "]" +
- "\n Organization name: " + name +
- "\n category of donation: " + category;
+ return "Organization: "
+ + "["
+ + orgNumber
+ + "]"
+ + "\n Organization name: "
+ + name
+ + "\n category of donation: "
+ + category;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/no/ntnu/idatt1005/group03/Model/Role.java b/src/main/java/no/ntnu/idatt1005/group03/model/Role.java
similarity index 60%
rename from src/main/java/no/ntnu/idatt1005/group03/Model/Role.java
rename to src/main/java/no/ntnu/idatt1005/group03/model/Role.java
index a6a72bd..b2c4dcf 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/Model/Role.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/model/Role.java
@@ -1,29 +1,28 @@
-package no.ntnu.idatt1005.group03.Model;
+package no.ntnu.idatt1005.group03.model;
/**
* Represents the role assigned to a user in the system.
*
- *
This enum is part of the model layer in the MVC architecture and is used
- * to define different levels of access and permissions within the application.
+ * This enum is part of the model layer in the MVC architecture and is used to define different
+ * levels of access and permissions within the application.
*
*
The role determines what actions a user is allowed to perform, such as accessing
- * administrative features or standard user functionality.
+ * administrative features or standard user functionality.
*/
public enum Role {
/**
* Represents a standard user with limited access rights.
*
- * Users with this role can perform actions such as viewing
- * organizations and making donations.
+ * Users with this role can perform actions such as viewing organizations and making donations.
*/
- USER,
+ USER,
/**
* Represents an administrator with elevated privileges.
*
- *
Users with this role have access to administrative functionality such as
- * managing organizations, users, or system settings.
+ * Users with this role have access to administrative functionality such as managing
+ * organizations, users, or system settings.
*/
- ADMIN
- }
\ No newline at end of file
+ ADMIN
+}
diff --git a/src/main/java/no/ntnu/idatt1005/group03/Model/SavedCharity.java b/src/main/java/no/ntnu/idatt1005/group03/model/SavedCharity.java
similarity index 83%
rename from src/main/java/no/ntnu/idatt1005/group03/Model/SavedCharity.java
rename to src/main/java/no/ntnu/idatt1005/group03/model/SavedCharity.java
index 3d916dd..ce49398 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/Model/SavedCharity.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/model/SavedCharity.java
@@ -1,4 +1,4 @@
-package no.ntnu.idatt1005.group03.Model;
+package no.ntnu.idatt1005.group03.model;
import java.util.Objects;
import java.util.UUID;
@@ -6,12 +6,12 @@
/**
* Represents an organization saved by a user.
*
- *
This class is part of the model layer in the MVC architecture and is responsible
- * for storing and representing the relationship between a user and an organization the user
- * has marked as a favorite.
+ * This class is part of the model layer in the MVC architecture and is responsible for
+ * storing and representing the relationship between a user and an organization the user has marked
+ * as a favorite.
*
- *
Each saved charity entry links a user to an organization and is assigned a unique
- * identifier when created in the application.
+ * Each saved charity entry links a user to an organization and is assigned a unique identifier
+ * when created in the application.
*/
public class SavedCharity {
private final String id;
@@ -21,7 +21,7 @@ public class SavedCharity {
/**
* Constructs a new {@code SavedCharity} instance.
*
- *
A unique ID is automatically generated for each saved charity entry.
+ * A unique ID is automatically generated for each saved charity entry.
*
* @param userId the ID of the user saving the organization
* @param organizationId the ID of the saved organization
@@ -59,4 +59,4 @@ public String getOrganizationId() {
public String getUserId() {
return userId;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/no/ntnu/idatt1005/group03/Model/SavedOrganization.java b/src/main/java/no/ntnu/idatt1005/group03/model/SavedOrganization.java
similarity index 85%
rename from src/main/java/no/ntnu/idatt1005/group03/Model/SavedOrganization.java
rename to src/main/java/no/ntnu/idatt1005/group03/model/SavedOrganization.java
index f436e51..ea6859b 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/Model/SavedOrganization.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/model/SavedOrganization.java
@@ -1,17 +1,16 @@
-package no.ntnu.idatt1005.group03.Model;
+package no.ntnu.idatt1005.group03.model;
import java.time.LocalDate;
import java.util.Objects;
-
/**
* Represents an organization saved by a user.
*
- *
This class is part of the model layer in the MVC architecture and is responsible
- * for storing and representing data about organizations that a user has chosen to save.
+ * This class is part of the model layer in the MVC architecture and is responsible for storing
+ * and representing data about organizations that a user has chosen to save.
*
- *
Each saved charity entry links a user to an organization and includes the date
- * when the organization was saved.
+ * Each saved charity entry links a user to an organization and includes the date when the
+ * organization was saved.
*/
public class SavedOrganization {
private final String id;
@@ -19,16 +18,16 @@ public class SavedOrganization {
private final String userId;
private final LocalDate date;
-
/**
* Constructs a new {@code SavedCharity} instance.
*
- *
A unique ID is automatically generated for each saved charity. All fields must be non-null.
+ * A unique ID is automatically generated for each saved charity. All fields must be non-null.
*
* @param userId the ID of the user saving the organization
* @param organizationId the ID of the saved organization
* @param date the date the organization was saved
- * @throws NullPointerException if any of {@code userId}, {@code organizationId}, or {@code date} is null
+ * @throws NullPointerException if any of {@code userId}, {@code organizationId}, or {@code date}
+ * is null
*/
public SavedOrganization(String userId, String organizationId, LocalDate date) {
this.userId = Objects.requireNonNull(userId, "userId cannot be null");
diff --git a/src/main/java/no/ntnu/idatt1005/group03/Model/User.java b/src/main/java/no/ntnu/idatt1005/group03/model/User.java
similarity index 89%
rename from src/main/java/no/ntnu/idatt1005/group03/Model/User.java
rename to src/main/java/no/ntnu/idatt1005/group03/model/User.java
index ddc2274..a75876a 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/Model/User.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/model/User.java
@@ -1,4 +1,4 @@
-package no.ntnu.idatt1005.group03.Model;
+package no.ntnu.idatt1005.group03.model;
import java.util.ArrayList;
import java.util.List;
@@ -8,12 +8,12 @@
/**
* Represents a user in the system.
*
- *
This class is part of the model layer in the MVC architecture and is responsible
- * for storing and representing user-related data. It includes authentication information,
- * user role, and associations such as donations and favorite organizations.
+ * This class is part of the model layer in the MVC architecture and is responsible for
+ * storing and representing user-related data. It includes authentication information, user role,
+ * and associations such as donations and favorite organizations.
*
*
Each user is assigned a unique identifier and can have multiple donations and saved
- * organizations linked to their account.
+ * organizations linked to their account.
*/
public class User {
private final String id;
@@ -27,7 +27,7 @@ public class User {
/**
* Constructs a new {@code User} instance.
*
- * A unique ID is automatically generated for each user. All fields must be non-null.
+ * A unique ID is automatically generated for each user. All fields must be non-null.
*
* @param username the username of the user
* @param email the email address of the user
@@ -46,8 +46,8 @@ public User(String username, String email, String passwordHash, Role role) {
/**
* Constructs a {@code User} instance from existing data.
*
- *
This constructor is typically used when loading user data from a database,
- * where the unique identifier is already defined.
+ * This constructor is typically used when loading user data from a database, where the unique
+ * identifier is already defined.
*
* @param id the unique identifier of the user
* @param username the username of the user
@@ -139,8 +139,8 @@ public List getDonations() {
/**
* Adds an organization to the user's list of favorite organizations.
*
- * If the organization is not already in the list, it will be added to the
- * beginning of the list.
+ * If the organization is not already in the list, it will be added to the beginning of the
+ * list.
*
* @param org the organization to add
*/
@@ -153,8 +153,8 @@ public void addFavoriteOrganization(Organization org) {
/**
* Removes an organization from the user's list of favorite organizations.
*
- *
The organization is matched by organization number. If no matching favorite
- * organization is found, the list remains unchanged.
+ * The organization is matched by organization number. If no matching favorite organization is
+ * found, the list remains unchanged.
*
* @param org the organization to remove from the favorites list
*/
@@ -165,14 +165,14 @@ public void removeFavoriteOrganization(Organization org) {
/**
* Checks whether a given organization is in the user's list of favorite organizations.
*
- *
The organization is matched by organization number.
+ * The organization is matched by organization number.
*
* @param org the organization to check
* @return {@code true} if the organization is in the favorites list, otherwise {@code false}
*/
public boolean isFavoriteOrganization(Organization org) {
return favoriteOrganizations.stream()
- .anyMatch(favorite -> favorite.getOrgNumber().equals(org.getOrgNumber()));
+ .anyMatch(favorite -> favorite.getOrgNumber().equals(org.getOrgNumber()));
}
/**
@@ -188,7 +188,7 @@ public List getFavoriteOrganizations() {
* Replaces the user's list of favorite organizations.
*
* A new copy of the provided list is created to avoid storing the original list reference
- * directly.
+ * directly.
*
* @param favoriteOrganizations the new list of favorite organizations
* @throws NullPointerException if {@code favoriteOrganizations} is null
diff --git a/src/main/java/no/ntnu/idatt1005/group03/Service/ApiClient.java b/src/main/java/no/ntnu/idatt1005/group03/service/ApiClient.java
similarity index 60%
rename from src/main/java/no/ntnu/idatt1005/group03/Service/ApiClient.java
rename to src/main/java/no/ntnu/idatt1005/group03/service/ApiClient.java
index 94e051c..5e1da22 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/Service/ApiClient.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/service/ApiClient.java
@@ -1,25 +1,23 @@
-package no.ntnu.idatt1005.group03.Service;
+package no.ntnu.idatt1005.group03.service;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
-import no.ntnu.idatt1005.group03.Model.Organization;
-
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.List;
+import no.ntnu.idatt1005.group03.model.Organization;
/**
* Provides access to external API data for organizations.
*
- * This class is part of the service layer in the MVC architecture and is responsible
- * for communicating with an external API to retrieve organization data. It acts as the
- * integration component between the application and the Innsamlingskontrollen public API.
+ * This class is part of the service layer in the MVC architecture and is responsible for
+ * communicating with an external API to retrieve organization data. It acts as the integration
+ * component between the application and the Innsamlingskontrollen public API.
*
- *
The class uses Java's {@code HttpClient} to send HTTP requests and Jackson's
- * {@code ObjectMapper} to deserialize the JSON response into a list of
- * {@link Organization} objects.
+ * The class uses Java's {@code HttpClient} to send HTTP requests and Jackson's {@code
+ * ObjectMapper} to deserialize the JSON response into a list of {@link Organization} objects.
*/
public class ApiClient {
@@ -31,8 +29,8 @@ public class ApiClient {
/**
* Constructs a new {@code ApiClient} instance.
*
- *
The client initializes the HTTP client and JSON object mapper used
- * to communicate with the external API and parse the response.
+ * The client initializes the HTTP client and JSON object mapper used to communicate with the
+ * external API and parse the response.
*/
public ApiClient() {
this.objectMapper = new ObjectMapper();
@@ -42,33 +40,26 @@ public ApiClient() {
/**
* Fetches organizations from the external API.
*
- *
This method sends an HTTP GET request to the configured API endpoint.
- * If the request is successful, the JSON response is deserialized into a list
- * of {@code Organization} objects.
+ * This method sends an HTTP GET request to the configured API endpoint. If the request is
+ * successful, the JSON response is deserialized into a list of {@code Organization} objects.
*
* @return a list of organizations returned by the external API
- * @throws Exception if the HTTP request fails, the response status is not {@code 200},
- * or the response cannot be parsed
+ * @throws Exception if the HTTP request fails, the response status is not {@code 200}, or the
+ * response cannot be parsed
*/
public List fetchOrganizations() throws Exception {
- HttpRequest request = HttpRequest.newBuilder()
- .uri(URI.create(API_URL))
- .GET()
- .build();
+ HttpRequest request = HttpRequest.newBuilder().uri(URI.create(API_URL)).GET().build();
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
String jsonText = response.body();
- return objectMapper.readValue(
- jsonText,
- new TypeReference>() {}
- );
+ return objectMapper.readValue(jsonText, new TypeReference>() {});
} else {
throw new Exception("API Request failed, status code: " + response.statusCode());
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/no/ntnu/idatt1005/group03/UI/AboutUsScreen.java b/src/main/java/no/ntnu/idatt1005/group03/ui/AboutUsScreen.java
similarity index 80%
rename from src/main/java/no/ntnu/idatt1005/group03/UI/AboutUsScreen.java
rename to src/main/java/no/ntnu/idatt1005/group03/ui/AboutUsScreen.java
index a562154..ac21162 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/UI/AboutUsScreen.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/ui/AboutUsScreen.java
@@ -1,4 +1,4 @@
-package no.ntnu.idatt1005.group03.UI;
+package no.ntnu.idatt1005.group03.ui;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
@@ -13,21 +13,20 @@
/**
* Displays the "About Us" screen in the application.
*
- * This class is part of the UI layer in the MVC architecture and is responsible
- * for presenting informational content about the application. It builds and displays a
- * JavaFX screen containing a top menu, a large image, and a button for navigating back
- * to the home screen.
+ * This class is part of the UI layer in the MVC architecture and is responsible for
+ * presenting informational content about the application. It builds and displays a JavaFX screen
+ * containing a top menu, a large image, and a button for navigating back to the home screen.
*
- *
The screen content is wrapped in a {@code ScrollPane} to support vertical scrolling
- * when the content exceeds the available window height.
+ * The screen content is wrapped in a {@code ScrollPane} to support vertical scrolling when the
+ * content exceeds the available window height.
*/
public class AboutUsScreen {
/**
* Builds and displays the About Us screen on the provided stage.
*
- *
This method creates the layout, applies the stylesheet, sets the scene on the stage,
- * and shows the window.
+ * This method creates the layout, applies the stylesheet, sets the scene on the stage, and
+ * shows the window.
*
* @param stage the JavaFX stage on which the screen will be displayed
*/
@@ -40,11 +39,7 @@ public void start(Stage stage) {
layout.setCenter(scrollPane);
ScreenManager.showRoot(
- stage,
- layout,
- "About Us",
- getClass().getResource("/styles/app.css").toExternalForm()
- );
+ stage, layout, "About Us", getClass().getResource("/styles/app.css").toExternalForm());
}
// --- UI COMPONENTS ---
diff --git a/src/main/java/no/ntnu/idatt1005/group03/UI/AccountScreen.java b/src/main/java/no/ntnu/idatt1005/group03/ui/AccountScreen.java
similarity index 74%
rename from src/main/java/no/ntnu/idatt1005/group03/UI/AccountScreen.java
rename to src/main/java/no/ntnu/idatt1005/group03/ui/AccountScreen.java
index ba202d0..31cd140 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/UI/AccountScreen.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/ui/AccountScreen.java
@@ -1,26 +1,26 @@
-package no.ntnu.idatt1005.group03.UI;
+package no.ntnu.idatt1005.group03.ui;
+import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
-import javafx.scene.layout.BorderPane;
-import javafx.stage.Stage;
-import javafx.scene.layout.VBox;
-import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
-import no.ntnu.idatt1005.group03.Model.User;
-import no.ntnu.idatt1005.group03.Model.Donation;
+import javafx.scene.layout.BorderPane;
+import javafx.scene.layout.VBox;
+import javafx.stage.Stage;
+import no.ntnu.idatt1005.group03.model.Donation;
+import no.ntnu.idatt1005.group03.model.User;
/**
* Displays the account screen for a logged-in user.
*
- *
This class is part of the UI layer in the MVC architecture and is responsible
- * for presenting account-related information to the user. It builds and displays a JavaFX
- * screen containing the user's profile details, donation history, and logout option.
+ * This class is part of the UI layer in the MVC architecture and is responsible for
+ * presenting account-related information to the user. It builds and displays a JavaFX screen
+ * containing the user's profile details, donation history, and logout option.
*
- *
The screen is composed of separate sections for profile information, donation records,
- * and logout functionality.
+ * The screen is composed of separate sections for profile information, donation records, and
+ * logout functionality.
*/
public class AccountScreen {
@@ -38,8 +38,8 @@ public AccountScreen(User user) {
/**
* Builds and displays the account screen on the provided stage.
*
- *
This method creates the layout, applies the stylesheet, sets the scene on the stage,
- * and shows the window.
+ * This method creates the layout, applies the stylesheet, sets the scene on the stage, and
+ * shows the window.
*
* @param stage the JavaFX stage on which the screen will be displayed
*/
@@ -51,20 +51,17 @@ public void start(Stage stage) {
mainContent.setAlignment(Pos.CENTER);
mainContent.setPadding(new Insets(24));
- mainContent.getChildren().addAll(
- createProfileSection(),
- createDonationLog(),
- createLogoutSection()
- );
+ mainContent
+ .getChildren()
+ .addAll(createProfileSection(), createDonationLog(), createLogoutSection());
accountLayout.setCenter(mainContent);
ScreenManager.showRoot(
- stage,
- accountLayout,
- "Account",
- getClass().getResource("/styles/app.css").toExternalForm()
- );
+ stage,
+ accountLayout,
+ "Account",
+ getClass().getResource("/styles/app.css").toExternalForm());
}
private VBox createProfileSection() {
@@ -87,10 +84,7 @@ private VBox createProfileSection() {
Label emailLabel = new Label(user.getEmail());
emailLabel.getStyleClass().add("account-email");
- Button editProfileButton = new Button("Edit Profile");
- editProfileButton.getStyleClass().addAll("btn", "btn-outline", "btn-large");
-
- profileBox.getChildren().addAll(profileView, usernameLabel, emailLabel, editProfileButton);
+ profileBox.getChildren().addAll(profileView, usernameLabel, emailLabel);
return profileBox;
}
@@ -102,18 +96,21 @@ private VBox createDonationLog() {
recentTitle.getStyleClass().add("account-section-title");
donationsBox.getChildren().add(recentTitle);
-
if (user.getDonations() == null || user.getDonations().isEmpty()) {
Label noDonations = new Label("No donations yet.");
noDonations.getStyleClass().add("account-email");
donationsBox.getChildren().add(noDonations);
} else {
for (Donation donation : user.getDonations()) {
- Label donationLabel = new Label(
- donation.getOrganizationName() +
- " - " + donation.getAmount() + " kr" +
- " (" + donation.getDate() + ")"
- );
+ Label donationLabel =
+ new Label(
+ donation.getOrganizationName()
+ + " - "
+ + donation.getAmount()
+ + " kr"
+ + " ("
+ + donation.getDate()
+ + ")");
donationLabel.getStyleClass().add("account-donation-text");
donationsBox.getChildren().add(donationLabel);
diff --git a/src/main/java/no/ntnu/idatt1005/group03/UI/DonationScreen.java b/src/main/java/no/ntnu/idatt1005/group03/ui/DonationScreen.java
similarity index 60%
rename from src/main/java/no/ntnu/idatt1005/group03/UI/DonationScreen.java
rename to src/main/java/no/ntnu/idatt1005/group03/ui/DonationScreen.java
index 0d993ab..1289463 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/UI/DonationScreen.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/ui/DonationScreen.java
@@ -1,5 +1,8 @@
-package no.ntnu.idatt1005.group03.UI;
+package no.ntnu.idatt1005.group03.ui;
+import java.awt.*;
+import java.net.URI;
+import java.time.LocalDate;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
@@ -10,25 +13,20 @@
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
-import no.ntnu.idatt1005.group03.Controller.FavoriteController;
-import no.ntnu.idatt1005.group03.Model.Donation;
-import no.ntnu.idatt1005.group03.Model.Organization;
-import no.ntnu.idatt1005.group03.Model.User;
-
-import java.awt.*;
-import java.net.URI;
-import java.time.LocalDate;
+import no.ntnu.idatt1005.group03.controller.FavoriteController;
+import no.ntnu.idatt1005.group03.model.Donation;
+import no.ntnu.idatt1005.group03.model.Organization;
+import no.ntnu.idatt1005.group03.model.User;
/**
* Displays the donation screen for a selected organization.
*
- *
This class is part of the UI layer in the MVC architecture and is responsible
- * for presenting donation-related actions to the user. It allows the user to view the
- * selected organization, visit its website, add or remove it from favorites, and register
- * a donation.
+ * This class is part of the UI layer in the MVC architecture and is responsible for
+ * presenting donation-related actions to the user. It allows the user to view the selected
+ * organization, visit its website, add or remove it from favorites, and register a donation.
*
- *
The screen validates donation input before creating a {@link Donation} object and
- * adding it to the current user's donation list.
+ * The screen validates donation input before creating a {@link Donation} object and adding it to
+ * the current user's donation list.
*/
public class DonationScreen {
@@ -51,8 +49,8 @@ public DonationScreen(Organization organization, User user) {
/**
* Builds and displays the donation screen on the provided stage.
*
- *
This method creates the layout, applies the stylesheet, sets the scene on the stage,
- * and shows the window.
+ * This method creates the layout, applies the stylesheet, sets the scene on the stage, and
+ * shows the window.
*
* @param stage the JavaFX stage on which the screen will be displayed
*/
@@ -72,10 +70,7 @@ public void start(Stage stage) {
HBox actionButtons = new HBox(10);
actionButtons.setAlignment(Pos.CENTER);
- actionButtons.getChildren().addAll(
- favoriteButton,
- websiteButton
- );
+ actionButtons.getChildren().addAll(favoriteButton, websiteButton);
Label amountLabel = new Label("Amount");
TextField amountInput = new TextField();
@@ -91,7 +86,9 @@ public void start(Stage stage) {
Button donateButton = createDonateButton(amountInput, feedbackLabel);
Button backButton = createBackButton();
- layout.getChildren().addAll(
+ layout
+ .getChildren()
+ .addAll(
orgName,
actionButtons,
websiteFeedbackLabel,
@@ -105,11 +102,10 @@ public void start(Stage stage) {
StackPane.setMargin(layout, new Insets(100, 0, 0, 0));
ScreenManager.showRoot(
- stage,
- centeredLayout,
- "Donation",
- getClass().getResource("/styles/app.css").toExternalForm()
- );
+ stage,
+ centeredLayout,
+ "Donation",
+ getClass().getResource("/styles/app.css").toExternalForm());
}
private Label createOrgNameLabel() {
@@ -123,15 +119,16 @@ private Button createWebsiteButton(Label websiteFeedbackLabel) {
websiteButton.getStyleClass().addAll("btn", "btn-action");
if (organization.getWebsiteUrl() != null && !organization.getWebsiteUrl().isBlank()) {
- websiteButton.setOnAction(e -> {
- try {
- Desktop.getDesktop().browse(new URI(organization.getWebsiteUrl()));
- websiteFeedbackLabel.setText("");
- } catch (Exception ex) {
- websiteFeedbackLabel.setTextFill(Color.RED);
- websiteFeedbackLabel.setText("Could not open website.");
- }
- });
+ websiteButton.setOnAction(
+ e -> {
+ try {
+ Desktop.getDesktop().browse(new URI(organization.getWebsiteUrl()));
+ websiteFeedbackLabel.setText("");
+ } catch (Exception ex) {
+ websiteFeedbackLabel.setTextFill(Color.RED);
+ websiteFeedbackLabel.setText("Could not open website.");
+ }
+ });
} else {
websiteButton.setDisable(true);
websiteButton.setText("Website not available");
@@ -148,15 +145,16 @@ private Button createFavoriteButton() {
}
favoriteButton.getStyleClass().addAll("btn", "btn-action");
- favoriteButton.setOnAction(e -> {
- favoriteController.toggleFavorite(user, organization);
+ favoriteButton.setOnAction(
+ e -> {
+ favoriteController.toggleFavorite(user, organization);
- if (user.isFavoriteOrganization(organization)) {
- favoriteButton.setText("Unfavorite");
- } else {
- favoriteButton.setText("Favorite");
- }
- });
+ if (user.isFavoriteOrganization(organization)) {
+ favoriteButton.setText("Unfavorite");
+ } else {
+ favoriteButton.setText("Favorite");
+ }
+ });
return favoriteButton;
}
@@ -166,44 +164,45 @@ private Button createDonateButton(TextField amountInput, Label feedbackLabel) {
donateButton.getStyleClass().addAll("btn", "btn-primary", "btn-large");
donateButton.setDefaultButton(true);
- donateButton.setOnAction(e -> {
- String textAmount = amountInput.getText().trim();
-
- if (textAmount.isEmpty()) {
- feedbackLabel.setTextFill(Color.RED);
- feedbackLabel.setText("Enter an amount");
- return;
- }
-
- int amount;
- try {
- amount = Integer.parseInt(textAmount);
- } catch (NumberFormatException ex) {
- feedbackLabel.setTextFill(Color.RED);
- feedbackLabel.setText("Enter a valid number");
- return;
- }
-
- if (amount <= 0) {
- feedbackLabel.setTextFill(Color.RED);
- feedbackLabel.setText("Must donate more than 0");
- return;
- }
-
- Donation donation = new Donation(
- user.getId(),
- organization.getOrgNumber(),
- amount,
- LocalDate.now(),
- organization.getName()
- );
- System.out.println("Donated " + amount + " kr to " + organization.getName());
- user.addDonation(donation);
- amountInput.clear();
-
- feedbackLabel.setTextFill(Color.GREEN);
- feedbackLabel.setText("Donation completed");
- });
+ donateButton.setOnAction(
+ e -> {
+ String textAmount = amountInput.getText().trim();
+
+ if (textAmount.isEmpty()) {
+ feedbackLabel.setTextFill(Color.RED);
+ feedbackLabel.setText("Enter an amount");
+ return;
+ }
+
+ int amount;
+ try {
+ amount = Integer.parseInt(textAmount);
+ } catch (NumberFormatException ex) {
+ feedbackLabel.setTextFill(Color.RED);
+ feedbackLabel.setText("Enter a valid number");
+ return;
+ }
+
+ if (amount <= 0) {
+ feedbackLabel.setTextFill(Color.RED);
+ feedbackLabel.setText("Must donate more than 0");
+ return;
+ }
+
+ Donation donation =
+ new Donation(
+ user.getId(),
+ organization.getOrgNumber(),
+ amount,
+ LocalDate.now(),
+ organization.getName());
+ System.out.println("Donated " + amount + " kr to " + organization.getName());
+ user.addDonation(donation);
+ amountInput.clear();
+
+ feedbackLabel.setTextFill(Color.GREEN);
+ feedbackLabel.setText("Donation completed");
+ });
return donateButton;
}
diff --git a/src/main/java/no/ntnu/idatt1005/group03/UI/LoginScreen.java b/src/main/java/no/ntnu/idatt1005/group03/ui/LoginScreen.java
similarity index 71%
rename from src/main/java/no/ntnu/idatt1005/group03/UI/LoginScreen.java
rename to src/main/java/no/ntnu/idatt1005/group03/ui/LoginScreen.java
index 8949060..bba4a61 100644
--- a/src/main/java/no/ntnu/idatt1005/group03/UI/LoginScreen.java
+++ b/src/main/java/no/ntnu/idatt1005/group03/ui/LoginScreen.java
@@ -1,37 +1,36 @@
-package no.ntnu.idatt1005.group03.UI;
+package no.ntnu.idatt1005.group03.ui;
+import java.util.Optional;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
+import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
-import javafx.scene.Parent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;
-import no.ntnu.idatt1005.group03.Controller.AuthController;
-import no.ntnu.idatt1005.group03.Controller.FavoriteController;
-import no.ntnu.idatt1005.group03.DAO.UserRepositoryDAO;
-import no.ntnu.idatt1005.group03.Model.User;
-
-import java.util.Optional;
+import no.ntnu.idatt1005.group03.controller.AuthController;
+import no.ntnu.idatt1005.group03.controller.FavoriteController;
+import no.ntnu.idatt1005.group03.dao.UserRepositoryDAO;
+import no.ntnu.idatt1005.group03.model.User;
/**
* Displays the login and sign-up screen for the application.
*
- *
This class is part of the UI layer in the MVC architecture and serves as the
- * entry point for user authentication. It provides both user registration and user login
- * flows, reusing a single JavaFX scene while swapping between different root layouts.
- * The class coordinates user input with the authentication controller and handles
- * navigation to the home screen after successful authentication.
+ * This class is part of the UI layer in the MVC architecture and serves as the entry
+ * point for user authentication. It provides both user registration and user login flows, reusing a
+ * single JavaFX scene while swapping between different root layouts. The class coordinates user
+ * input with the authentication controller and handles navigation to the home screen after
+ * successful authentication.
*
- *
The class extends {@link Application} and is responsible for initializing the
- * primary stage used for login and registration.
+ * The class extends {@link Application} and is responsible for initializing the primary stage
+ * used for login and registration.
*/
public class LoginScreen extends Application { // homepage
@@ -45,15 +44,15 @@ public class LoginScreen extends Application { // homepage
/**
* Initializes and displays the login screen on the provided primary stage.
*
- *
This method creates the authentication controller and favorite controller,
- * initializes feedback labels, prepares the shared authentication scene,
- * and displays the initial sign-up view.
+ * This method creates the authentication controller and favorite controller, initializes
+ * feedback labels, prepares the shared authentication scene, and displays the initial sign-up
+ * view.
*
* @param primaryStage the primary JavaFX stage for the application
*/
@Override
public void start(Stage primaryStage) {
- boolean MaximizeOnStartup = primaryStage.getScene() == null;
+ boolean maximizeOnStartup = primaryStage.getScene() == null;
String stylesheet = getClass().getResource("/styles/app.css").toExternalForm();
this.stage = primaryStage;
@@ -80,7 +79,7 @@ public void start(Stage primaryStage) {
primaryStage.show();
}
- if (MaximizeOnStartup) {
+ if (maximizeOnStartup) {
Platform.runLater(() -> primaryStage.setMaximized(true));
}
}
@@ -96,20 +95,19 @@ private Parent createSignUpRoot() {
PasswordField passInput = new PasswordField();
Label passConfirmLabel = new Label("Confirm your password");
PasswordField passConfirmInput = new PasswordField();
- CheckBox checkbox = new CheckBox("Show password");
-
Label usernameLabel = new Label("Username");
TextField usernameInput = new TextField();
Button loginButton = new Button("Create an account");
loginButton.getStyleClass().addAll("btn", "btn-primary");
loginButton.setDefaultButton(true);
- loginButton.setOnAction(e -> handleSignUp(
- usernameInput.getText(),
- nameInput.getText(),
- passInput.getText(),
- passConfirmInput.getText()
- ));
+ loginButton.setOnAction(
+ e ->
+ handleSignUp(
+ usernameInput.getText(),
+ nameInput.getText(),
+ passInput.getText(),
+ passConfirmInput.getText()));
addHeader(root1, false);
@@ -121,13 +119,12 @@ private Parent createSignUpRoot() {
root1.add(passConfirmInput, 2, 6);
root1.add(usernameLabel, 1, 1);
root1.add(usernameInput, 1, 2, 2, 1);
- root1.add(checkbox, 1, 7);
- root1.add(signUpErrLabel, 1, 8, 3, 1);
+ root1.add(signUpErrLabel, 1, 7, 3, 1);
HBox accountBox = new HBox(0);
accountBox.getChildren().addAll(loginButton);
accountBox.setAlignment(Pos.CENTER);
- root1.add(accountBox, 1, 9, 3, 1);
+ root1.add(accountBox, 1, 8, 3, 1);
return wrapCentered(root1);
}
@@ -141,18 +138,11 @@ private Parent createLoginRoot() {
Label passLabel2 = new Label("Password");
PasswordField passInput2 = new PasswordField();
- CheckBox checkbox2 = new CheckBox("Remember me");
-
Text terms = new Text("By continuing, you agree to the Terms of use and Privacy Policy.");
- Hyperlink forgot = new Hyperlink("Forgot your password");
-
Button loginButton2 = new Button("Log in");
loginButton2.getStyleClass().addAll("btn", "btn-primary", "btn-super-wide");
loginButton2.setDefaultButton(true);
- loginButton2.setOnAction(e -> handleLogin(
- usernameInput2.getText(),
- passInput2.getText()
- ));
+ loginButton2.setOnAction(e -> handleLogin(usernameInput2.getText(), passInput2.getText()));
addHeader(root2, true);
@@ -160,17 +150,13 @@ private Parent createLoginRoot() {
root2.add(usernameInput2, 1, 2, 2, 1);
root2.add(passLabel2, 1, 3);
root2.add(passInput2, 1, 4, 2, 1);
- root2.add(terms, 1, 6);
- root2.add(forgot, 1, 8, 3, 1);
- root2.add(checkbox2, 1, 5);
- root2.add(loginErrLabel, 1, 7, 3, 1);
+ root2.add(terms, 1, 5);
+ root2.add(loginErrLabel, 1, 6, 3, 1);
HBox accountBox2 = new HBox(0);
accountBox2.getChildren().addAll(loginButton2);
accountBox2.setAlignment(Pos.CENTER);
- root2.add(accountBox2, 1, 8, 3, 1);
-
- GridPane.setHalignment(forgot, HPos.CENTER);
+ root2.add(accountBox2, 1, 7, 3, 1);
return wrapCentered(root2);
}
@@ -206,22 +192,28 @@ private void addHeader(GridPane grid, boolean isScene2) {
imageView.setFitHeight(48);
imageView.setPreserveRatio(true);
- Button signloginButton = new Button("Sign In");
- signloginButton.getStyleClass().addAll("btn", isScene2 ? "btn-outline" : "btn-secondary", "btn-toggle");
- signloginButton.setOnAction(e -> {
- signUpErrLabel.setText("");
- authScene.setRoot(createSignUpRoot());
- });
+ Button signUpButton = new Button("Sign up");
+ signUpButton
+ .getStyleClass()
+ .addAll("btn", isScene2 ? "btn-outline" : "btn-secondary", "btn-toggle");
+ signUpButton.setOnAction(
+ e -> {
+ signUpErrLabel.setText("");
+ authScene.setRoot(createSignUpRoot());
+ });
Button loginButton = new Button("Log in");
- loginButton.getStyleClass().addAll("btn", isScene2 ? "btn-secondary" : "btn-outline", "btn-toggle");
- loginButton.setOnAction(e -> {
- loginErrLabel.setText("");
- authScene.setRoot(createLoginRoot());
- });
+ loginButton
+ .getStyleClass()
+ .addAll("btn", isScene2 ? "btn-secondary" : "btn-outline", "btn-toggle");
+ loginButton.setOnAction(
+ e -> {
+ loginErrLabel.setText("");
+ authScene.setRoot(createLoginRoot());
+ });
HBox buttonBox = new HBox(0); // 0px spacing
- buttonBox.getChildren().addAll(signloginButton, loginButton);
+ buttonBox.getChildren().addAll(signUpButton, loginButton);
buttonBox.setAlignment(Pos.CENTER);
grid.add(imageView, 0, 0);
@@ -230,9 +222,11 @@ private void addHeader(GridPane grid, boolean isScene2) {
// -------- ACTION LOGIC --------
- private void handleSignUp(String username, String email, String password, String confirmPassword) {
+ private void handleSignUp(
+ String username, String email, String password, String confirmPassword) {
signUpErrLabel.setText("");
- Optional registeredUser = authController.register(username, email, password, confirmPassword);
+ Optional