From 7daf841258a5dfd9a7588aef64c8f647386259d8 Mon Sep 17 00:00:00 2001 From: AdrianBalunan Date: Sun, 15 Mar 2026 17:33:40 +0100 Subject: [PATCH] Feat: JavaDoc for Database files --- .../team6/database/DatabaseConnection.java | 2 -- .../team6/database/DatabaseManager.java | 20 ++++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseConnection.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseConnection.java index 7ec66b0..018d229 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseConnection.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseConnection.java @@ -18,8 +18,6 @@ public class DatabaseConnection { * blank */ - // Values stored in system environment variables for security (using ntnu's phpmyadmin for this - // project) public DatabaseConnection() { this.databaseURL = "jdbc:mysql://namox.idi.ntnu.no:3306/apbaluna?useSSL=false&serverTimezone=UTC"; diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseManager.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseManager.java index 34bf218..43c4bef 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseManager.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseManager.java @@ -12,17 +12,19 @@ import ntnu.systemutvikling.team6.scraper.APICharityData; /** - * Manages creation of MySQL tables (for now) + * Manages the Database with MySQL tables and JDBC. * - *

This class is responsible for creating the tables needed for the application, if not done + * This class is responsible for creating the tables needed for the application, if not done * already and maintaining the {@code charities} table based on data retrieved from the IK API. + * It is also responsible for retrieving the data from the database and sending it to the application through the CharityRegistry and DonationRegistry. + * It is used by the FrontpageController to retrieve the data needed to display the charities */ public class DatabaseManager { private final DatabaseConnection connection; /** * Contractor for DatabaseManager. It uses a DatabaseConnection object that contains a connection - * credentials using environment variables in the DatabaseConnection. + * credentials. */ public DatabaseManager() { this.connection = new DatabaseConnection(); @@ -54,9 +56,9 @@ public boolean testConnection() { } /** - * Creates the {@code charities} table if it does not already exist. + * Creates the {@code Charities} and {@code Donations} tables if they do not already exist. * - *

The table structure is based on fields from {@link APICharityData}. + *

The table structure for Charities is based on fields from {@link APICharityData}.

* * @throws RuntimeException if a {@link SQLException} occurs while creating the table */ @@ -109,6 +111,14 @@ REFERENCES Charities (`UUID_charities`) } } + /** + * This method is used to verify the integrity of the data in the {@code charities} table and to update it based on the data retrieved from the IK API. + * The param charities are retrieved from the IK API through the APICharityData class. + * Called in initialize method in HmHApplication.java, which is the main class of the application, to ensure that the data is up to date when the application starts. + * Uses a a temp table to ensure that the data in the database is consistent with the data from the API. + * + * @param charities + */ public void addAPIDataToTable(List charities) { Connection conn = null; try {