-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: We'll see if feedback work/messages work
- Loading branch information
AdrianBalunan
committed
Apr 21, 2026
1 parent
a5fdf85
commit 35f72aa
Showing
6 changed files
with
349 additions
and
187 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...rc/main/java/ntnu/systemutvikling/team6/controller/components/FeedbackCardController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package ntnu.systemutvikling.team6.controller.components; | ||
|
|
||
| import javafx.fxml.FXML; | ||
| import javafx.scene.control.Label; | ||
| import ntnu.systemutvikling.team6.models.Feedback; | ||
| import ntnu.systemutvikling.team6.models.user.Message; | ||
|
|
||
| public class FeedbackCardController extends BaseController { | ||
| @FXML private Label usernameLabel; | ||
| @FXML private Label dateLabel; | ||
| @FXML private Label commentLabel; | ||
|
|
||
| private Feedback feedback; | ||
|
|
||
| @Override | ||
| protected void authTokenisSet() { | ||
|
|
||
| } | ||
|
|
||
| public void setMessage(Feedback feedback) { | ||
| this.feedback = feedback; | ||
|
|
||
| usernameLabel.setText(feedback.isAnonymous() ? "Anonymous Doner" : feedback.getUser().getUsername()); | ||
| dateLabel.setText(feedback.getDate().toString()); | ||
| commentLabel.setText(feedback.getComment()); | ||
| } | ||
| } |
138 changes: 138 additions & 0 deletions
138
.../java/ntnu/systemutvikling/team6/controller/profileCharity/profileOrgInboxController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| 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.FlowPane; | ||
| import javafx.stage.Stage; | ||
| import ntnu.systemutvikling.team6.controller.components.*; | ||
| import ntnu.systemutvikling.team6.database.DAO.MessageDAO; | ||
| import ntnu.systemutvikling.team6.database.DatabaseConnection; | ||
| import ntnu.systemutvikling.team6.database.Readers.CharitySelect; | ||
| import ntnu.systemutvikling.team6.models.Charity; | ||
| import ntnu.systemutvikling.team6.models.Feedback; | ||
| import ntnu.systemutvikling.team6.models.user.Inbox; | ||
| import ntnu.systemutvikling.team6.models.user.Message; | ||
| import ntnu.systemutvikling.team6.models.user.User; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Date; | ||
| import java.util.List; | ||
|
|
||
| public class profileOrgInboxController extends BaseController { | ||
| @FXML | ||
| private NavbarController navbarController; | ||
| @FXML | ||
| private FlowPane cardsContainer; | ||
| @FXML private Label charityNameLabel; | ||
| @FXML private TextField messageTitleField; | ||
| @FXML private TextArea messageContentField; | ||
|
|
||
|
|
||
| @Override | ||
| protected void authTokenisSet() { | ||
| if (!isLoggedin() || authToken.isCharityUser() == null) { | ||
| showAlert(Alert.AlertType.ERROR, "Not logged inn", "You need to be logged inn to donate."); | ||
| 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); | ||
| } | ||
| }); | ||
| } | ||
| navbarController.setAuthToken(authToken); | ||
| populateFields(); | ||
| } | ||
|
|
||
| public void populateFields() { | ||
| Charity usersCharity = authToken.isCharityUser(); | ||
| charityNameLabel.setText(usersCharity.getName()); | ||
|
|
||
| // Messages | ||
| DatabaseConnection conn = new DatabaseConnection(); | ||
| CharitySelect charitySelect = new CharitySelect(conn); | ||
| ArrayList<Feedback> feedbacks = charitySelect.getFeedbackforCharityUUID(authToken.isCharityUser().getUUID().toString()); | ||
| displayFeedbacks(feedbacks); | ||
| } | ||
|
|
||
| private void displayFeedbacks(ArrayList<Feedback> feedbacks){ | ||
| cardsContainer.getChildren().clear(); | ||
| if (feedbacks.isEmpty()) { | ||
| Label empty = new Label("You have no Feedbacks"); | ||
| empty.setStyle("-fx-text-fill: #777777; -fx-font-size: 14;"); | ||
| cardsContainer.getChildren().add(empty); | ||
| } | ||
|
|
||
| for (Feedback feedback : feedbacks) { | ||
| try { | ||
| FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/components/feedbackCard.fxml")); | ||
| Parent card = loader.load(); | ||
| FeedbackCardController cardController = loader.getController(); | ||
| cardController.setMessage(feedback); | ||
| cardController.setAuthToken(authToken); | ||
| cardsContainer.getChildren().add(card); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException("Could not load organization card.", e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @FXML | ||
| private void handleSendMessage(ActionEvent event) { | ||
| String title = messageTitleField.getText().trim(); | ||
| String content = messageContentField.getText().trim(); | ||
|
|
||
| if (title.isBlank() || content.isBlank()) { | ||
| showAlert(Alert.AlertType.ERROR, "Empty fields", "Please fill in both title and message."); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| DatabaseConnection conn = new DatabaseConnection(); | ||
| MessageDAO messageDAO = new MessageDAO(conn); | ||
| Charity charity = authToken.isCharityUser(); | ||
| Message message = new Message(title, authToken.isCharityUser(), content); | ||
| messageDAO.addMessage(message, authToken.getCurrentUser().getId().toString()); | ||
| showAlert(Alert.AlertType.INFORMATION, "Sent!", "Your message has been sent to all donors."); | ||
| messageTitleField.clear(); | ||
| messageContentField.clear(); | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| showAlert(Alert.AlertType.ERROR, "Error", "Something went wrong sending the message."); | ||
| } | ||
| } | ||
|
|
||
| // Sidebar Methods | ||
| @FXML | ||
| private void switchToPaymentsPage(ActionEvent event) { | ||
| LoaderScene.LoadScene("profile_org_Payments", event, null, null, authToken); | ||
| } | ||
|
|
||
| @FXML | ||
| private void switchToEditPage(ActionEvent event) { | ||
| LoaderScene.LoadScene("profile_org_edit", 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); | ||
| } | ||
| } |
76 changes: 76 additions & 0 deletions
76
helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/MessageDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package ntnu.systemutvikling.team6.database.DAO; | ||
|
|
||
| import ntnu.systemutvikling.team6.database.DatabaseConnection; | ||
| import ntnu.systemutvikling.team6.models.user.Message; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.Date; | ||
| import java.sql.PreparedStatement; | ||
| import java.sql.ResultSet; | ||
| import java.sql.SQLException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class MessageDAO { | ||
| private final DatabaseConnection connection; | ||
|
|
||
| public MessageDAO(DatabaseConnection connection){ | ||
| this.connection = connection; | ||
| } | ||
| public boolean addMessage(Message message, String user_id){ | ||
| // First fetch all unique donors for this charity | ||
| List<String> donorIds = getDonorIdsForCharity(message.getFrom().getUUID().toString()); | ||
|
|
||
| if (donorIds.isEmpty()) return false; | ||
| String sql = """ | ||
| INSERT INTO Messages | ||
| (UUID_message, message_title, message_content, message_date, sender_charity_id, user_id) | ||
| VALUES (?, ?, ?, ?, ?, ?) | ||
| """; | ||
|
|
||
| try (Connection conn = connection.getMySqlConnection(); | ||
| PreparedStatement stmt = conn.prepareStatement(sql)) { | ||
|
|
||
| for (String donorId : donorIds) { | ||
| stmt.setString(1, message.getId().toString()); | ||
| stmt.setString(2, message.getTitle()); | ||
| stmt.setString(3, message.getContent()); | ||
| stmt.setDate(4, Date.valueOf(message.getTimeAndDate())); | ||
| stmt.setString(5, message.getFrom().getUUID().toString()); | ||
| stmt.setString(6, user_id); | ||
| stmt.addBatch(); | ||
| } | ||
|
|
||
| int[] results = stmt.executeBatch(); | ||
| return results.length > 0; | ||
|
|
||
| } catch (SQLException e) { | ||
| e.printStackTrace(); | ||
| throw new RuntimeException("ERROR: Failed to send messages to donors."); | ||
| } | ||
| } | ||
|
|
||
| private List<String> getDonorIdsForCharity(String charityId) { | ||
| List<String> donorIds = new ArrayList<>(); | ||
| String sql = """ | ||
| SELECT DISTINCT user_id | ||
| FROM Donations | ||
| WHERE charity_id = ? | ||
| """; | ||
|
|
||
| try (Connection conn = connection.getMySqlConnection(); | ||
| PreparedStatement stmt = conn.prepareStatement(sql)) { | ||
|
|
||
| stmt.setString(1, charityId); | ||
| try (ResultSet rs = stmt.executeQuery()) { | ||
| while (rs.next()) { | ||
| donorIds.add(rs.getString("user_id")); | ||
| } | ||
| } | ||
| } catch (SQLException e) { | ||
| e.printStackTrace(); | ||
| throw new RuntimeException("ERROR: Failed to fetch donor IDs."); | ||
| } | ||
| return donorIds; | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,5 @@ | |
| public enum Role { | ||
| NORMAL_USER, | ||
| CHARITY_USER, | ||
| ADMIN, | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
helpmehelpapplication/src/main/resources/fxml/components/feedbackCard.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <?import javafx.scene.control.*?> | ||
| <?import javafx.scene.layout.*?> | ||
| <?import javafx.scene.shape.*?> | ||
| <?import javafx.scene.text.*?> | ||
|
|
||
| <HBox alignment="CENTER_LEFT" | ||
| spacing="16.0" | ||
| style="-fx-background-color: #FFFFFF; | ||
| -fx-border-color: transparent transparent #EEEEEE transparent; | ||
| -fx-border-width: 1; | ||
| -fx-padding: 14 20 14 20;" | ||
| xmlns="http://javafx.com/javafx/25" | ||
| xmlns:fx="http://javafx.com/fxml/1" | ||
| fx:controller="ntnu.systemutvikling.team6.controller.components.FeedbackCardController"> | ||
| <children> | ||
|
|
||
| <Circle fx:id="avatar" fill="#D9D9D9" radius="20.0" /> | ||
|
|
||
| <VBox spacing="4.0" HBox.hgrow="ALWAYS"> | ||
| <children> | ||
| <HBox spacing="10.0" alignment="CENTER_LEFT"> | ||
| <children> | ||
| <Label fx:id="usernameLabel" style="-fx-text-fill: #111111;"> | ||
| <font><Font name="System Bold" size="13.0" /></font> | ||
| </Label> | ||
| <Label fx:id="dateLabel" style="-fx-text-fill: #AAAAAA;"> | ||
| <font><Font size="11.0" /></font> | ||
| </Label> | ||
| </children> | ||
| </HBox> | ||
| <Label fx:id="commentLabel" style="-fx-text-fill: #555555;" wrapText="true"> | ||
| <font><Font size="12.0" /></font> | ||
| </Label> | ||
| </children> | ||
| </VBox> | ||
|
|
||
| </children> | ||
| </HBox> |
Oops, something went wrong.