Skip to content

Commit

Permalink
Feat: JavaDoc for Database files
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Mar 15, 2026
1 parent d2f3e7c commit 7daf841
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>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();
Expand Down Expand Up @@ -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.
*
* <p>The table structure is based on fields from {@link APICharityData}.
* <p>The table structure for Charities is based on fields from {@link APICharityData}. </p>
*
* @throws RuntimeException if a {@link SQLException} occurs while creating the table
*/
Expand Down Expand Up @@ -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<Charity> charities) {
Connection conn = null;
try {
Expand Down

0 comments on commit 7daf841

Please sign in to comment.