From e64128bf191058ad03deae68275953473c8eb4cb Mon Sep 17 00:00:00 2001 From: AdrianBalunan Date: Tue, 21 Apr 2026 06:49:24 +0200 Subject: [PATCH] Feat: Updating descirptng (org_Edit) works. --- .../profileOrgEditController.java | 112 ++++++++++ .../profileOrgSettingsController.java | 4 +- .../team6/database/DAO/CharityUserDAO.java | 24 +++ .../main/resources/fxml/profile_org_edit.fxml | 193 +++++------------- .../resources/fxml/profile_user_history.fxml | 2 +- 5 files changed, 185 insertions(+), 150 deletions(-) create mode 100644 helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileCharity/profileOrgEditController.java diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileCharity/profileOrgEditController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileCharity/profileOrgEditController.java new file mode 100644 index 00000000..5ad1d174 --- /dev/null +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileCharity/profileOrgEditController.java @@ -0,0 +1,112 @@ +package ntnu.systemutvikling.team6.controller.profileCharity; + +import javafx.application.Platform; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.control.Alert; +import javafx.scene.control.Label; +import javafx.scene.control.TextArea; +import javafx.scene.control.TextField; +import javafx.scene.layout.HBox; +import javafx.stage.Stage; +import ntnu.systemutvikling.team6.controller.components.BaseController; +import ntnu.systemutvikling.team6.controller.components.CategoryTagController; +import ntnu.systemutvikling.team6.controller.components.LoaderScene; +import ntnu.systemutvikling.team6.controller.components.NavbarController; +import ntnu.systemutvikling.team6.database.DAO.CharityUserDAO; +import ntnu.systemutvikling.team6.database.DatabaseConnection; +import ntnu.systemutvikling.team6.models.Charity; + +import java.io.IOException; +import java.util.List; + +public class profileOrgEditController extends BaseController { + @FXML + private NavbarController navbarController; + @FXML private Label charityNameLabel; + @FXML private TextArea descriptionField; + + @Override + protected void authTokenisSet() { + if (!isLoggedin() || authToken.isCharityUser() == null){ + showAlert(Alert.AlertType.ERROR, "Not logged inn or dont have privileges", "You need to be logged inn an account with Charity User priviliges."); + Platform.runLater(() -> { + Stage stage = (Stage) Stage.getWindows().stream() + .filter(w -> w.isShowing()) + .findFirst() + .orElse(null); + if (stage != null) { + LoaderScene.LoadScene("loginSite", stage, null, null, authToken); + } + }); + return; + } + navbarController.setAuthToken(authToken); + populateFields(); + } + + private void populateFields(){ + Charity usersCharity = authToken.isCharityUser(); + charityNameLabel.setText(usersCharity.getName()); + descriptionField.setText(usersCharity.getDescription()); + } + + @FXML + private void handleSaveDescription(ActionEvent event){ + String descriptionFieldText = descriptionField.getText(); + + + if (descriptionFieldText.isBlank()) { + showAlert(Alert.AlertType.ERROR, "Empty input", "Yeah, maybe it was empty before but now it need one"); + return; + } + + boolean updateSuccess; + DatabaseConnection conn = new DatabaseConnection(); + CharityUserDAO userDataObject = new CharityUserDAO(conn); + Charity savedCharity = authToken.isCharityUser(); + Charity minimalCharityWithJustNewDescription = new Charity(savedCharity.getUUID().toString(), savedCharity.getOrg_number(), savedCharity.getName(), null, savedCharity.getStatus(), savedCharity.getPreApproved(),descriptionFieldText, null, null, null); + try { + updateSuccess = userDataObject.updateCharityVanityDescription(minimalCharityWithJustNewDescription); + } catch (Exception e) { + e.printStackTrace(); + showAlert(Alert.AlertType.ERROR, "Unexpected Error", "Unexpected error ocurred"); + return; + } + if (updateSuccess) { + showAlert( + Alert.AlertType.INFORMATION, + "Settings updated", + "You have successfully changed your settings"); + authToken.isCharityUser().setDescription(descriptionFieldText); + LoaderScene.LoadScene("profile_user_settings", event, null, null, authToken); + } else { + System.out.println("Something went wrong when updating Settings"); + } + } + + @FXML + private void switchToPaymentsPage(ActionEvent event){ + LoaderScene.LoadScene("profile_org_Payments", event, null, null, authToken); + } + + @FXML + private void switchToFeedbackPage(ActionEvent event){ + LoaderScene.LoadScene("profile_org_Inbox", event, null, null, authToken); + } + + @FXML + private void switchToSettingsPage(ActionEvent event){ + LoaderScene.LoadScene("profile_user_Settings", event, null, null, authToken); + } + + + @FXML + private void handleLogout(ActionEvent event){ + authToken.logout(); + showAlert(Alert.AlertType.INFORMATION, "Logging out", "Logging out..."); + LoaderScene.LoadScene("FrontPage", event, null, null, authToken); + } +} diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileCharity/profileOrgSettingsController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileCharity/profileOrgSettingsController.java index e494249a..c8b93dbc 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileCharity/profileOrgSettingsController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/profileCharity/profileOrgSettingsController.java @@ -126,12 +126,12 @@ private void switchToPaymentsPage(ActionEvent event){ @FXML private void switchToFeedbackPage(ActionEvent event){ - LoaderScene.LoadScene("profile_org_", event, null, null, authToken); + LoaderScene.LoadScene("profile_org_Inbox", event, null, null, authToken); } @FXML private void switchToEditPage(ActionEvent event){ - LoaderScene.LoadScene("profile_user_inbox", event, null, null, authToken); + LoaderScene.LoadScene("profile_org_edit", event, null, null, authToken); } diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/CharityUserDAO.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/CharityUserDAO.java index 3cff1c8e..99d9de82 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/CharityUserDAO.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/CharityUserDAO.java @@ -40,4 +40,28 @@ public boolean updateCharityVanityName(Charity charity){ } } + public boolean updateCharityVanityDescription(Charity charity){ + Connection conn = null; + String sql = """ + UPDATE CharityVanity SET + description = ? + WHERE UUID_charity = ?; + """; + try { + conn = connection.getMySqlConnection(); + PreparedStatement ps = conn.prepareStatement(sql); + + System.out.println(charity.getUUID().toString()); + ps.setString(1, charity.getDescription()); + ps.setString(2, charity.getUUID().toString()); + + return ps.executeUpdate() > 0; + + } catch (SQLException e) { + e.printStackTrace(); + System.out.println("Something went wrong when updating ah"); + return false; + } + + } } diff --git a/helpmehelpapplication/src/main/resources/fxml/profile_org_edit.fxml b/helpmehelpapplication/src/main/resources/fxml/profile_org_edit.fxml index 7d8cd8d3..755a8abe 100644 --- a/helpmehelpapplication/src/main/resources/fxml/profile_org_edit.fxml +++ b/helpmehelpapplication/src/main/resources/fxml/profile_org_edit.fxml @@ -19,7 +19,8 @@ - + + @@ -33,80 +34,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -147,7 +76,7 @@ -