diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/DAO/CharityDAO.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/DAO/CharityDAO.java deleted file mode 100644 index 210a853..0000000 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/DAO/CharityDAO.java +++ /dev/null @@ -1,266 +0,0 @@ -package ntnu.systemutvikling.team6.DAO; - -import ntnu.systemutvikling.team6.scraper.APICharityData; - -import java.sql.*; -import java.util.List; - -/** - * Manages the charity - *
- * This class is responsible for establishing connections using environment variables - * and maintaining the {@code charities} table based on data retrieved from the IK API. - *
- */ - -public class CharityDAO { - - public class DatabaseManager { - private final String databaseURL; - private final String username; - private final String password; - - /** - Constructs a new {@code DatabaseManager} using database credentials - * retrieved from system environment variables. - *- * Required environment variables: - *
- * Used primarily for JUnit tests. Production should use the constructor - * using environment variables. - *
- * - * @param databaseURL the url to the database - * @param username the username used to log in to the database - * @param password the password used to log in to the database - * @throws IllegalArgumentException if databaseURL, username, or password is - * {@code null} or blank - */ - - public DatabaseManager(String databaseURL, String username, String password) { - this.databaseURL = databaseURL; - this.username = username; - this.password = password; - - if (this.databaseURL == null || this.databaseURL.isBlank()) { - throw new IllegalArgumentException("Database environment variable URL has not been set"); - } - - if (this.username == null || this.username.isBlank()) { - throw new IllegalArgumentException("Username environment variable has not been set"); - } - - if (this.password == null || this.password.isBlank()) { - throw new IllegalArgumentException("Password environment variable has not been set"); - } - } - - /** - * Creates the {@code charities} table if it does not already exist. - *- * The table structure is based on fields from {@link APICharityData}. - *
- * @throws RuntimeException if a {@link SQLException} occurs while creating the table - */ - - public void createTables() { - String sql_query = """ - -- MySQL Workbench Forward Engineering - - SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; - SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; - SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; - - -- ----------------------------------------------------- - -- Schema HelpMeHelp - -- ----------------------------------------------------- - - -- ----------------------------------------------------- - -- Schema HelpMeHelp - -- ----------------------------------------------------- - --CREATE SCHEMA IF NOT EXISTS `HelpMeHelp` DEFAULT CHARACTER SET utf8 ; - --USE `HelpMeHelp` ; - USE apbaluna; - - -- ----------------------------------------------------- - -- Table `HelpMeHelp`.`Charities` - -- ----------------------------------------------------- - CREATE TABLE IF NOT EXISTS `HelpMeHelp`.`Charities` ( - `UUID` CHAR(36) NOT NULL, - `charity_name` VARCHAR(255) NOT NULL, - `charity_description` VARCHAR(255) NOT NULL, - `isVerified` TINYINT NOT NULL, - `category` VARCHAR(45) NOT NULL, - PRIMARY KEY (`UUID`)) - ENGINE = InnoDB; - - - -- ----------------------------------------------------- - -- Table `HelpMeHelp`.`Donations` - -- ----------------------------------------------------- - CREATE TABLE IF NOT EXISTS `HelpMeHelp`.`Donations` ( - `UUID` CHAR(36) NOT NULL, - `amount` DECIMAL NOT NULL, - `date` DATE NOT NULL, - `Charities_UUID` CHAR(36) NOT NULL, - PRIMARY KEY (`UUID`), - INDEX `fk_Donations_Charities_idx` (`Charities_UUID` ASC) VISIBLE, - CONSTRAINT `fk_Donations_Charities` - FOREIGN KEY (`Charities_UUID`) - REFERENCES `HelpMeHelp`.`Charities` (`UUID`) - ON DELETE NO ACTION - ON UPDATE NO ACTION) - ENGINE = InnoDB; - - - SET SQL_MODE=@OLD_SQL_MODE; - SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; - SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; - - """; - - try (Connection conn = DriverManager.getConnection(databaseURL, username, password); - Statement s = conn.createStatement()) { - - s.execute(sql_query); - } catch (SQLException e) { - e.printStackTrace(); - throw new RuntimeException("Error creating table."); - } - } - - /** - * Synchronizes the {@code charities} table with the provided list of APICharityData. - *- * Summary of function: - *