diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/DAO/DonationDAO.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/DAO/DonationDAO.java index 87674bf..c99056f 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/DAO/DonationDAO.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/DAO/DonationDAO.java @@ -1,44 +1,43 @@ package ntnu.systemutvikling.team6.DAO; -import ntnu.systemutvikling.team6.database.DatabaseConnection; -import ntnu.systemutvikling.team6.models.Charity; - import java.sql.*; -import java.util.Calendar; import java.util.UUID; +import ntnu.systemutvikling.team6.database.DatabaseConnection; +import ntnu.systemutvikling.team6.models.Charity; /** - * This class is responsible for sending concurrent information about the donation to the Donation Database. - * Usally called from the DonationPageController, where the user confirms their donation. + * This class is responsible for sending concurrent information about the donation to the Donation + * Database. Usally called from the DonationPageController, where the user confirms their donation. */ - public class DonationDAO { - private static final DatabaseConnection connection = new DatabaseConnection(); + private static final DatabaseConnection connection = new DatabaseConnection(); - /** - * Gets the total ammount of donations for a given charity, and sends it to the database throught MySQL. - * @param charity - * @param amount - */ - public static void addDonation(Charity charity, double amount){ - String sql_query = - """ + /** + * Gets the total ammount of donations for a given charity, and sends it to the database throught + * MySQL. + * + * @param charity + * @param amount + */ + public static void addDonation(Charity charity, double amount) { + String sql_query = + """ INSERT INTO Donations (UUID_Donations, amount, date, Charities_UUID_charities) VALUES (?, ?, ?, ?) """; - try (Connection conn = connection.getMySqlConnection(); - PreparedStatement ps = conn.prepareStatement(sql_query)){ - conn.setAutoCommit(false); + try (Connection conn = connection.getMySqlConnection(); + PreparedStatement ps = conn.prepareStatement(sql_query)) { + conn.setAutoCommit(false); - ps.setString(1, UUID.randomUUID().toString()); - ps.setDouble(2, amount); - ps.setDate(3, new Date(System.currentTimeMillis())); - ps.setString(4, charity.getUUID().toString()); + ps.setString(1, UUID.randomUUID().toString()); + ps.setDouble(2, amount); + ps.setDate(3, new Date(System.currentTimeMillis())); + ps.setString(4, charity.getUUID().toString()); - ps.executeUpdate(); - conn.commit(); - } catch (SQLException e) { - throw new RuntimeException(e); - } + ps.executeUpdate(); + conn.commit(); + } catch (SQLException e) { + throw new RuntimeException(e); } + } } diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/HmHApplication.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/HmHApplication.java index afa349d..293aa2d 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/HmHApplication.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/HmHApplication.java @@ -4,7 +4,6 @@ import java.net.http.HttpClient; import java.util.Objects; - import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; @@ -21,7 +20,10 @@ public void start(Stage stage) throws Exception { FXMLLoader fxmlLoader = new FXMLLoader(HmHApplication.class.getResource("/fxml/frontPage.fxml")); Scene scene = new Scene(fxmlLoader.load()); - Image icon = new Image(Objects.requireNonNull(HmHApplication.class.getResource("/images/Logo.png")).openStream()); + Image icon = + new Image( + Objects.requireNonNull(HmHApplication.class.getResource("/images/Logo.png")) + .openStream()); stage.getIcons().add(icon); stage.setTitle("Help Me Help"); stage.setScene(scene); diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/Main.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/Main.java index ead8b5c..d039f90 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/Main.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/Main.java @@ -1,6 +1,5 @@ package ntnu.systemutvikling.team6; - public class Main { // Make sure you're connected to the NTNU network for this to work public static void main(String[] args) { diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java index ea63c91..8eb853f 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java @@ -2,59 +2,60 @@ import javafx.event.ActionEvent; import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; -import javafx.scene.Node; -import javafx.scene.Parent; -import javafx.scene.Scene; import javafx.scene.control.Label; -import javafx.scene.layout.FlowPane; -import javafx.stage.Stage; -import ntnu.systemutvikling.team6.HmHApplication; import ntnu.systemutvikling.team6.models.Charity; -import java.io.IOException; - /** - * This controller represents the charity page, where the user can read about the charity and choose to donate to it. - * It also has a button to return to the front page. + * This controller represents the charity page, where the user can read about the charity and choose + * to donate to it. It also has a button to return to the front page. */ public class CharityPageController { @FXML private Label CharityDescription; @FXML private Label CharityName; - @FXML public void initialize() {} + @FXML + public void initialize() {} private Charity charity; /** - * This method is used to set the charity that is being displayed on the page. It also updates the labels with the charity's name and description. - * It acts like an initializer for the charity page, since the charity is not known until the user clicks on a charity from the front page. - * Param charity is the charity that is being displayed on the page, - * AND is called on from the front page when the user clicks on a charity, to set the charity that is being displayed on the page. + * This method is used to set the charity that is being displayed on the page. It also updates the + * labels with the charity's name and description. It acts like an initializer for the charity + * page, since the charity is not known until the user clicks on a charity from the front page. + * Param charity is the charity that is being displayed on the page, AND is called on from the + * front page when the user clicks on a charity, to set the charity that is being displayed on the + * page. + * * @param charity */ @FXML - public void setCharity(Charity charity){ + public void setCharity(Charity charity) { this.charity = charity; CharityDescription.setText(charity.getDescription()); CharityName.setText(charity.getName()); - } /** * This method is used to switch to the front page. + * * @param event */ - public void switchToFrontPage(ActionEvent event){ + @FXML + public void switchToFrontPage(ActionEvent event) { + System.out.println("Click"); LoaderScene.LoadScene("FrontPage", event, charity); } + /** * This method is used to switch to the donation page. + * * @param event */ - public void switchToDonationPage(ActionEvent event){ + @FXML + public void switchToDonationPage(ActionEvent event) { + System.out.println("Click"); LoaderScene.LoadScene("donationPage", event, charity); } } diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java index a355c46..839a3e8 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java @@ -1,5 +1,6 @@ package ntnu.systemutvikling.team6.controller; +import java.util.Optional; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Alert; @@ -9,110 +10,124 @@ import ntnu.systemutvikling.team6.DAO.DonationDAO; import ntnu.systemutvikling.team6.models.Charity; -import java.util.Optional; /** - * This controller represents the donation page, where the user can enter a donation amount and confirm their donation to the charity. - * It also has a button to return to the front page. + * This controller represents the donation page, where the user can enter a donation amount and + * confirm their donation to the charity. It also has a button to return to the front page. */ - public class DonationPageController { - @FXML private Charity charity; - - @FXML private TextField donatioAmount; - - @FXML private Label CharityName; - - - /** - * Initialize method for the donation page. Sets the charity name label to the name of the charity that is being donated to. - * The charity is set from the original page it was called from when the user clicks on the donate button, and is passed as a parameter to this method. - * - * @param charity - */ - @FXML - public void setCharity(Charity charity) { - this.charity = charity; - - CharityName.setText(charity.getName()); + @FXML private Charity charity; + + @FXML private TextField donatioAmount; + + @FXML private Label CharityName; + + /** + * Initialize method for the donation page. Sets the charity name label to the name of the charity + * that is being donated to. The charity is set from the original page it was called from when the + * user clicks on the donate button, and is passed as a parameter to this method. + * + * @param charity + */ + @FXML + public void setCharity(Charity charity) { + this.charity = charity; + + CharityName.setText(charity.getName()); + } + + /** + * This method is used to switch back to the front page when the user clicks the back button. + * + * @param event + */ + public void switchToFrontPage(ActionEvent event) { + LoaderScene.LoadScene("FrontPage", event, null); + } + + /** + * This method is used to switch back to the Donation page when the user clicks the back button. + * + * @param event + */ + public void switchToCharityPage(ActionEvent event) { + LoaderScene.LoadScene("charityPage", event, charity); + } + + /** + * This method is used to process the donation when the user clicks the donate button. Checks if + * the input is valid and displays appropriate error messages if it is not. If the input is valid, + * it shows a confirmation dialog to the user. Shows a confirmation dialog. If the user confirms, + * the donation is processed and the user is taken back to the front page. + * + * @param event + */ + public void Donate(ActionEvent event) { + String input = donatioAmount.getText().trim(); + + if (input.isEmpty()) { + showAlert(Alert.AlertType.ERROR, "Invalid input", "Please enter a donation amount."); + return; } + double amount; - /** - * This method is used to switch back to the front page when the user clicks the back button. - * @param event - */ - - public void switchToFrontPage(ActionEvent event) { - LoaderScene.LoadScene("FrontPage", event, null); + try { + amount = Double.parseDouble(input); + } catch (NumberFormatException e) { + showAlert(Alert.AlertType.ERROR, "Invalid input", "Please enter a valid number."); + return; } - /** - * This method is used to process the donation when the user clicks the donate button. - * Checks if the input is valid and displays appropriate error messages if it is not. If the input is valid, it shows a confirmation dialog to the user. - * Shows a confirmation dialog. If the user confirms, the donation is processed and the user is taken back to the front page. - * @param event - */ - public void Donate(ActionEvent event){ - String input = donatioAmount.getText().trim(); - - if (input.isEmpty()) { - showAlert(Alert.AlertType.ERROR, "Invalid input", "Please enter a donation amount."); - return; - } - double amount; - - try { - amount = Double.parseDouble(input); - } catch (NumberFormatException e) { - showAlert(Alert.AlertType.ERROR, "Invalid input", "Please enter a valid number."); - return; - } - - if (amount <= 0) { - showAlert(Alert.AlertType.ERROR, "Invalid amount", "Donation must be greater than 0."); - return; - } - - if (amount > 100_000) { - showAlert(Alert.AlertType.WARNING, "Amount too high", "Maximum donation is 100,000."); - return; - } - - Alert confirm = new Alert(Alert.AlertType.CONFIRMATION); - confirm.setTitle("Confirm Donation"); - confirm.setHeaderText("You're about to donate " + amount + " to " + charity.getName()); - confirm.setContentText("Are you sure?"); - Optional result = confirm.showAndWait(); - - if (result.isPresent() && result.get() == ButtonType.OK) { - // Process donation - processDonation(charity,amount); - showAlert(Alert.AlertType.INFORMATION, "Thank you!", "You have donated " + amount + " to " + charity.getName()); - donatioAmount.clear(); - LoaderScene.LoadScene("FrontPage", event, null); - } + if (amount <= 0) { + showAlert(Alert.AlertType.ERROR, "Invalid amount", "Donation must be greater than 0."); + return; } - /** - * Invoke DAO object to add the donation to the database. - * This method is called from the Donate method after the user confirms their donation. - * @param charity - * @param amount - */ - public void processDonation(Charity charity, double amount){ - DonationDAO.addDonation(charity, amount); + if (amount > 100_000) { + showAlert(Alert.AlertType.WARNING, "Amount too high", "Maximum donation is 100,000."); + return; } - /** - * Show an JavaFx alert dialog with the specified type, title, and message. - * @param type - * @param title - * @param message - */ - private void showAlert(Alert.AlertType type, String title, String message){ - Alert alert = new Alert(type); - alert.setTitle(title); - alert.setHeaderText(null); - alert.setContentText(message); - alert.showAndWait(); + Alert confirm = new Alert(Alert.AlertType.CONFIRMATION); + confirm.setTitle("Confirm Donation"); + confirm.setHeaderText("You're about to donate " + amount + " to " + charity.getName()); + confirm.setContentText("Are you sure?"); + Optional result = confirm.showAndWait(); + + if (result.isPresent() && result.get() == ButtonType.OK) { + // Process donation + processDonation(charity, amount); + showAlert( + Alert.AlertType.INFORMATION, + "Thank you!", + "You have donated " + amount + " to " + charity.getName()); + donatioAmount.clear(); + LoaderScene.LoadScene("FrontPage", event, null); } + } + + /** + * Invoke DAO object to add the donation to the database. This method is called from the Donate + * method after the user confirms their donation. + * + * @param charity + * @param amount + */ + public void processDonation(Charity charity, double amount) { + DonationDAO.addDonation(charity, amount); + } + + /** + * Show an JavaFx alert dialog with the specified type, title, and message. + * + * @param type + * @param title + * @param message + */ + private void showAlert(Alert.AlertType type, String title, String message) { + Alert alert = new Alert(type); + alert.setTitle(title); + alert.setHeaderText(null); + alert.setContentText(message); + alert.showAndWait(); + } } diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java index 5e7b1fe..f8ffc2a 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java @@ -1,5 +1,6 @@ package ntnu.systemutvikling.team6.controller; +import java.util.Random; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; @@ -12,43 +13,35 @@ import ntnu.systemutvikling.team6.models.Donation; import ntnu.systemutvikling.team6.models.DonationRegistry; -import java.util.Random; -import java.util.stream.Collectors; - /** - * Landing page's controller. This is the first page the user sees when they open the application. It displays a random featured charity, some statistics about the charities and donations, and a list of all charities in the database. The user can click on a charity to see more details about it, or click on the featured charity to see more details about it. - * It also has buttons to switch to the charity page and the donation page for the featured charity + * Landing page's controller. This is the first page the user sees when they open the application. + * It displays a random featured charity, some statistics about the charities and donations, and a + * list of all charities in the database. The user can click on a charity to see more details about + * it, or click on the featured charity to see more details about it. It also has buttons to switch + * to the charity page and the donation page for the featured charity */ - public class FrontpageController { - @FXML - private Charity featuredCharity; + @FXML private Charity featuredCharity; - @FXML - private FlowPane cardsContainer; + @FXML private FlowPane cardsContainer; - - @FXML - private Label Carosel_Organisasjon; - - @FXML - private Label Carosel_Beskrivelse; - - @FXML - private Label Total_Orgnisasjon; - - @FXML - private Label Total_Donations; - - @FXML - private Label PreApproved_Percentage; + @FXML private Label Carosel_Organisasjon; + + @FXML private Label Carosel_Beskrivelse; + + @FXML private Label Total_Orgnisasjon; + + @FXML private Label Total_Donations; + + @FXML private Label PreApproved_Percentage; /** - * Initialize method for the front page. This method is called when the front page is loaded. - * It retrieves the list of charities and donations from the database. - * The list of charities is displayed as a list of cards, where each card represents a charity from the Innsamlingskontrollen - * A random charity is selected to be featured on the page, and its name and description are displayed in the carousel section. - * The total number of charities, total amount of donations, and percentage of pre-approved charities are also displayed on the page. + * Initialize method for the front page. This method is called when the front page is loaded. It + * retrieves the list of charities and donations from the database. The list of charities is + * displayed as a list of cards, where each card represents a charity from the + * Innsamlingskontrollen A random charity is selected to be featured on the page, and its name and + * description are displayed in the carousel section. The total number of charities, total amount + * of donations, and percentage of pre-approved charities are also displayed on the page. */ @FXML public void initialize() { @@ -58,14 +51,14 @@ public void initialize() { DonationRegistry Donations = db.getDonationFromDB(); for (Charity ch : Charities.getAllCharities()) { - FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/organizationCard.fxml")); Parent card = loader.load(); OrganizationCardController cardController = loader.getController(); - // System.out.println("Added Name: " + ch.getName() + " Added Description: " + ch.getDescription()); + // System.out.println("Added Name: " + ch.getName() + " Added Description: " + + // ch.getDescription()); cardController.setOrganization(ch); cardsContainer.getChildren().add(card); @@ -80,10 +73,16 @@ public void initialize() { Carosel_Beskrivelse.setText(randomCharity.getDescription()); Total_Orgnisasjon.setText(Integer.toString(Charities_size)); - Total_Donations.setText(Double.toString(Donations.getAllDonations().stream().mapToDouble(Donation::getAmount).sum())); + Total_Donations.setText( + Double.toString( + Donations.getAllDonations().stream().mapToDouble(Donation::getAmount).sum())); PreApproved_Percentage.setText( - String.format("%.2f", Charities.getAllCharities().stream().filter(Charity::getPreApproved).count() * 100.0 / Charities_size) - + "%"); + String.format( + "%.2f", + Charities.getAllCharities().stream().filter(Charity::getPreApproved).count() + * 100.0 + / Charities_size) + + "%"); } catch (Exception e) { e.printStackTrace(); @@ -92,18 +91,19 @@ public void initialize() { /** * This method is used to switch to the charity page for the selected charity - * + * * @param event */ - public void switchToCharityPage(ActionEvent event){ + public void switchToCharityPage(ActionEvent event) { LoaderScene.LoadScene("CharityPage", event, featuredCharity); } + /** * This method is used to switch to the donation page for the selected charity. - * + * * @param event */ - public void switchToDonationPage(ActionEvent event){ + public void switchToDonationPage(ActionEvent event) { LoaderScene.LoadScene("DonationPage", event, featuredCharity); } } diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/LoaderScene.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/LoaderScene.java index e8b7036..83ace1e 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/LoaderScene.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/LoaderScene.java @@ -1,5 +1,7 @@ package ntnu.systemutvikling.team6.controller; +import java.io.IOException; +import java.util.Objects; import javafx.event.ActionEvent; import javafx.fxml.FXMLLoader; import javafx.scene.Node; @@ -10,52 +12,52 @@ import ntnu.systemutvikling.team6.HmHApplication; import ntnu.systemutvikling.team6.models.Charity; -import java.io.IOException; -import java.util.Objects; - /** - * This class is a utility class that is used to load different scenes in the application. - * For now, It is used to switch between the front page, charity page, and donation page. - * It takes care of loading the FXML file, setting the controller, and switching the scene. + * This class is a utility class that is used to load different scenes in the application. For now, + * It is used to switch between the front page, charity page, and donation page. It takes care of + * loading the FXML file, setting the controller, and switching the scene. */ - public class LoaderScene { - /** - * When going to a new scene, this method is called to load the new scene. - * It takes the name of the scene to load, the event that triggered the scene change, and the charity that is being passed to the new scene (if applicable). - * It loads the FXML file for the new scene, sets the controller, and switches the scene. - * - * @param sceneName - * @param event - * @param charity - */ - public static void LoadScene(String sceneName, ActionEvent event, Charity charity){ - try { - System.out.println(HmHApplication.class.getResource("/fxml/"+ sceneName +".fxml")); - FXMLLoader fxmlLoader = - new FXMLLoader(HmHApplication.class.getResource("/fxml/"+ sceneName +".fxml")); - Parent root = fxmlLoader.load(); + /** + * When going to a new scene, this method is called to load the new scene. It takes the name of + * the scene to load, the event that triggered the scene change, and the charity that is being + * passed to the new scene (if applicable). It loads the FXML file for the new scene, sets the + * controller, and switches the scene. + * + * @param sceneName + * @param event + * @param charity + */ + public static void LoadScene(String sceneName, ActionEvent event, Charity charity) { + try { + System.out.println(HmHApplication.class.getResource("/fxml/" + sceneName + ".fxml")); + FXMLLoader fxmlLoader = + new FXMLLoader(HmHApplication.class.getResource("/fxml/" + sceneName + ".fxml")); + Parent root = fxmlLoader.load(); - System.out.println("Controller: " + fxmlLoader.getController()); - Object controller = fxmlLoader.getController(); + System.out.println("Controller: " + fxmlLoader.getController()); + Object controller = fxmlLoader.getController(); - // Needs to be expanded when more pages get implemented. - if (controller instanceof CharityPageController charityController) { - charityController.setCharity(charity); - } - if (controller instanceof DonationPageController donationController) { - donationController.setCharity(charity); - } + // Needs to be expanded when more pages get implemented. + if (controller instanceof CharityPageController charityController) { + charityController.setCharity(charity); + } + if (controller instanceof DonationPageController donationController) { + donationController.setCharity(charity); + } - Stage stage = (Stage) ((Node)event.getSource()).getScene().getWindow(); - Image icon = new Image(Objects.requireNonNull(HmHApplication.class.getResource("/images/Logo.png")).openStream()); - stage.getIcons().add(icon); - Scene scene = new Scene(root); - stage.setScene(scene); - stage.setFullScreen(true); - stage.show(); - } catch (IOException e) { - throw new RuntimeException(e); - } + Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); + Image icon = + new Image( + Objects.requireNonNull(HmHApplication.class.getResource("/images/Logo.png")) + .openStream()); + stage.getIcons().add(icon); + Scene scene = new Scene(root); + stage.setScene(scene); + stage.setFullScreen(true); + stage.show(); + } catch (IOException e) { + throw new RuntimeException(e); } + } } diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/OrganizationCardController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/OrganizationCardController.java index 5ac3006..b51e530 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/OrganizationCardController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/OrganizationCardController.java @@ -2,23 +2,14 @@ import javafx.event.ActionEvent; import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; -import javafx.scene.Node; -import javafx.scene.Parent; -import javafx.scene.Scene; import javafx.scene.control.Label; -import javafx.stage.Stage; -import ntnu.systemutvikling.team6.HmHApplication; import ntnu.systemutvikling.team6.models.Charity; -import java.io.IOException; -import java.util.Objects; - /** - * This controller represents the organization card that is displayed on the front page and is looped upon in FronpageController. - * It is used to display the name and description of a charity, and to switch to the charity page or donation page when the user clicks on the card. + * This controller represents the organization card that is displayed on the front page and is + * looped upon in FronpageController. It is used to display the name and description of a charity, + * and to switch to the charity page or donation page when the user clicks on the card. */ - public class OrganizationCardController { @FXML private Label organizationName; @@ -35,10 +26,11 @@ public void setOrganization(Charity charity) { } /* EVENTS */ - public void switchToCharityPage(ActionEvent event){ - LoaderScene.LoadScene("CharityPage", event, charity); + public void switchToCharityPage(ActionEvent event) { + LoaderScene.LoadScene("CharityPage", event, charity); } - public void switchToDonationPage(ActionEvent event){ - LoaderScene.LoadScene("DonationPage", event, charity); + + public void switchToDonationPage(ActionEvent event) { + LoaderScene.LoadScene("DonationPage", event, charity); } } 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 1222288..28c325d 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseConnection.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseConnection.java @@ -17,13 +17,11 @@ public class DatabaseConnection { * @throws IllegalStateException if either databaseURL, username, or password is {@code null} or * blank */ - public DatabaseConnection() { this.databaseURL = "jdbc:mysql://namox.idi.ntnu.no:3306/apbaluna?useSSL=false&serverTimezone=UTC"; this.username = "apbaluna"; this.password = "GYntUFPG"; - } /** 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 0017f63..a4007a0 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseManager.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseManager.java @@ -3,8 +3,6 @@ import java.sql.*; import java.util.List; import java.util.UUID; - -import ntnu.systemutvikling.team6.DAO.DonationDAO; import ntnu.systemutvikling.team6.models.Charity; import ntnu.systemutvikling.team6.models.CharityRegistry; import ntnu.systemutvikling.team6.models.Donation; @@ -12,12 +10,13 @@ import ntnu.systemutvikling.team6.scraper.APICharityData; /** - * Manages the Database with MySQL tables and JDBC. + * Manages the Database with MySQL tables and JDBC. * - * 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 + *

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; @@ -58,7 +57,7 @@ public boolean testConnection() { /** * Creates the {@code Charities} and {@code Donations} tables if they do not already exist. * - *

The table structure for Charities 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 */ @@ -112,11 +111,13 @@ 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. - * + * 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) { @@ -155,7 +156,8 @@ INSERT INTO Charities (UUID_charities, org_number, charity_name, charity_link, p } // -- Intergerty Check: - String createTemp = """ + String createTemp = + """ CREATE TEMPORARY TABLE temp_api_charities ( org_number VARCHAR(20) PRIMARY KEY ) @@ -170,14 +172,15 @@ org_number VARCHAR(20) PRIMARY KEY try (PreparedStatement ps = conn.prepareStatement(insertTemp)) { for (Charity charity : charities) { - ps.setString(1, charity.getOrg_number().replaceAll("\\s","")); + ps.setString(1, charity.getOrg_number().replaceAll("\\s", "")); ps.addBatch(); } ps.executeBatch(); } - String deleteSql = """ + String deleteSql = + """ DELETE FROM Charities c WHERE NOT EXISTS ( SELECT 1 @@ -214,25 +217,27 @@ WHERE NOT EXISTS ( } } } - public CharityRegistry getCharitiesFromDB(){ + + public CharityRegistry getCharitiesFromDB() { CharityRegistry registry = null; Connection conn = null; try { conn = connection.getMySqlConnection(); - String sql_query = "SELECT UUID_charities, org_number, charity_name, charity_link, pre_approved, status FROM Charities"; + String sql_query = + "SELECT UUID_charities, org_number, charity_name, charity_link, pre_approved, status FROM Charities"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql_query); registry = new CharityRegistry(); - while (rs.next()){ - Charity charity = new Charity( + while (rs.next()) { + Charity charity = + new Charity( rs.getString("UUID_charities"), - rs.getString("org_number" ), + rs.getString("org_number"), rs.getString("charity_link"), rs.getString("charity_name"), rs.getBoolean("pre_approved"), - rs.getString("status") - ); + rs.getString("status")); registry.addCharity(charity); } } catch (SQLException e) { @@ -242,13 +247,14 @@ public CharityRegistry getCharitiesFromDB(){ return registry; } - public DonationRegistry getDonationFromDB(){ + public DonationRegistry getDonationFromDB() { DonationRegistry registry = null; Connection conn = null; try { conn = connection.getMySqlConnection(); - String sql_query = """ - SELECT + String sql_query = + """ + SELECT d.UUID_Donations, d.amount, d.date, @@ -266,22 +272,22 @@ public DonationRegistry getDonationFromDB(){ ResultSet rs = stmt.executeQuery(sql_query); registry = new DonationRegistry(); - while (rs.next()){ - Charity charity = new Charity( + while (rs.next()) { + Charity charity = + new Charity( rs.getString("UUID_charities"), rs.getString("org_number"), rs.getString("charity_name"), rs.getString("charity_link"), rs.getBoolean("pre_approved"), - rs.getString("status") - ); + rs.getString("status")); - Donation donation = new Donation( + Donation donation = + new Donation( rs.getString("UUID_Donations"), rs.getDouble("amount"), rs.getDate("date").toLocalDate(), - charity - ); + charity); registry.addDonation(donation); } } catch (SQLException e) { diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java index 4f5a9ec..d97d996 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java @@ -34,8 +34,6 @@ public class Charity { /* List that contains the charity's Feedbacks */ private List feedbacks; - - /** * Contructor for creating a new charity. Taylored to match data given from Api. Other attributes * will just be initialized as empty @@ -56,17 +54,23 @@ public Charity( this.feedbacks = new ArrayList<>(); this.category = ""; } + /** - * Contructor for creating a new charity. Taylored to match data given from DATABASE. Other attributes - * will just be initialized as empty + * Contructor for creating a new charity. Taylored to match data given from DATABASE. Other + * attributes will just be initialized as empty * * @param org_number matches from innsamlingkontrollen * @param name matches from innsamlingkontrollen * @param is_pre_approved name matches from innsamlingkontrollen * @param status name matches from innsamlingkontrollen */ - public Charity(String uuid, - String org_number, String link, String name, boolean is_pre_approved, String status) { + public Charity( + String uuid, + String org_number, + String link, + String name, + boolean is_pre_approved, + String status) { this.UUID = UUID.fromString(uuid); this.org_number = org_number.replaceAll("\\s", ""); this.name = name; diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Donation.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Donation.java index 63ca280..64d8733 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Donation.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Donation.java @@ -1,8 +1,6 @@ package ntnu.systemutvikling.team6.models; import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.Date; import java.util.UUID; import ntnu.systemutvikling.team6.models.user.User; @@ -44,7 +42,8 @@ public Donation(double amount, LocalDate date, Charity charity, User donor) { } /** - * Constructor for creating a new donation. Taylored for getting info FROM DATABASE. NEEDS TO BE CHANGED in phase 3. + * Constructor for creating a new donation. Taylored for getting info FROM DATABASE. NEEDS TO BE + * CHANGED in phase 3. * * @param amount * @param date diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/scraper/APICharityData.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/scraper/APICharityData.java index d4a6e90..10a489d 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/scraper/APICharityData.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/scraper/APICharityData.java @@ -19,8 +19,8 @@ public class APICharityData { private final boolean is_pre_approved; /** - * Constructs a new APICharityData object. - * This class represents the data provided from the IK Api, and is used expand and provide data to our design of a charity. + * Constructs a new APICharityData object. This class represents the data provided from the IK + * Api, and is used expand and provide data to our design of a charity. * * @param org_number a unique number that identifies the organization * @param name the name of the organization diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/scraper/APICharityScraper.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/scraper/APICharityScraper.java index 7b341b7..89422a1 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/scraper/APICharityScraper.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/scraper/APICharityScraper.java @@ -64,9 +64,8 @@ public String getJSONData() throws IOException, InterruptedException { } /** - * Parses the JSON data using gson and translates the {@code APICharityData} into our predefined charity classes - * and puts it in a CharityRegistry object. - * + * Parses the JSON data using gson and translates the {@code APICharityData} into our predefined + * charity classes and puts it in a CharityRegistry object. * * @param JSONData the {@code String} of JSON data to be parsed * @return a CharityRegistry class object diff --git a/helpmehelpapplication/src/main/resources/fxml/charityPage.fxml b/helpmehelpapplication/src/main/resources/fxml/charityPage.fxml index 205c14b..041b51b 100644 --- a/helpmehelpapplication/src/main/resources/fxml/charityPage.fxml +++ b/helpmehelpapplication/src/main/resources/fxml/charityPage.fxml @@ -35,497 +35,484 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - + + + + - - + - + - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - diff --git a/helpmehelpapplication/src/main/resources/fxml/donationPage.fxml b/helpmehelpapplication/src/main/resources/fxml/donationPage.fxml index 832d44d..d2fcb6c 100644 --- a/helpmehelpapplication/src/main/resources/fxml/donationPage.fxml +++ b/helpmehelpapplication/src/main/resources/fxml/donationPage.fxml @@ -141,20 +141,15 @@ - - - - -