From c67227b549712138cbaf56e2c00e91c22c336cb8 Mon Sep 17 00:00:00 2001 From: Fredrik Marjoni Date: Thu, 16 Apr 2026 17:39:39 +0200 Subject: [PATCH] update[control]: Update controller to handle control of the appstate --- .../group5/app/control/AuthController.java | 18 +++++++++++ .../app/control/DonationController.java | 32 +++++++++++++++++++ .../app/control/NavigationController.java | 2 +- .../app/control/OrganizationController.java | 23 ++++++++++++- 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/group5/app/control/AuthController.java b/src/main/java/edu/group5/app/control/AuthController.java index 291e0df..c2f923b 100644 --- a/src/main/java/edu/group5/app/control/AuthController.java +++ b/src/main/java/edu/group5/app/control/AuthController.java @@ -1,6 +1,7 @@ package edu.group5.app.control; import edu.group5.app.model.AppState; +import edu.group5.app.model.organization.Organization; import edu.group5.app.model.user.User; import edu.group5.app.model.user.UserService; import edu.group5.app.utils.ParameterValidator; @@ -37,6 +38,23 @@ public AuthController(AppState appState, NavigationController nav, UserService u this.userService = userService; } + + /** + * Sets the current logged-in user. + * @param user the user to set as current + */ + public void setCurrentUser(User user) { + appState.setCurrentUser(user); + } + + /** + * Gets the current logged-in user. + * @return the current user, or null if no user logged in + */ + public User getCurrentUser() { + return appState.getCurrentUser(); + } + /** * Handles the registration of a {@link User}. * diff --git a/src/main/java/edu/group5/app/control/DonationController.java b/src/main/java/edu/group5/app/control/DonationController.java index 61ab172..70d6444 100644 --- a/src/main/java/edu/group5/app/control/DonationController.java +++ b/src/main/java/edu/group5/app/control/DonationController.java @@ -43,6 +43,38 @@ public DonationController(AppState appState, NavigationController nav, DonationS this.service = service; } + /** + * Sets the current donation amount. + * @param amount the amount to donate + */ + public void setDonationAmount(BigDecimal amount) { + appState.setCurrentDonationAmount(amount); + } + + /** + * Gets the current donation amount. + * @return the donation amount + */ + public BigDecimal getDonationAmount() { + return appState.getCurrentDonationAmount(); + } + + /** + * Sets the current payment method. + * @param paymentMethod the payment method + */ + public void setPaymentMethod(String paymentMethod) { + appState.setCurrentPaymentMethod(paymentMethod); + } + + /** + * Gets the current payment method. + * @return the payment method + */ + public String getPaymentMethod() { + return appState.getCurrentPaymentMethod(); + } + /** * Retrieves all donations made by a specific user. * diff --git a/src/main/java/edu/group5/app/control/NavigationController.java b/src/main/java/edu/group5/app/control/NavigationController.java index d94bb53..04fb5e2 100644 --- a/src/main/java/edu/group5/app/control/NavigationController.java +++ b/src/main/java/edu/group5/app/control/NavigationController.java @@ -54,7 +54,7 @@ public NavigationController(BorderPane root, AppState appState, UserService user this.authController = new AuthController(appState, this, userService); this.donationController = new DonationController(appState, this, donationService); - this.organizationController = new OrganizationController(organizationService); + this.organizationController = new OrganizationController(appState, organizationService); } /** diff --git a/src/main/java/edu/group5/app/control/OrganizationController.java b/src/main/java/edu/group5/app/control/OrganizationController.java index 064aab2..6ffe830 100644 --- a/src/main/java/edu/group5/app/control/OrganizationController.java +++ b/src/main/java/edu/group5/app/control/OrganizationController.java @@ -1,5 +1,6 @@ package edu.group5.app.control; +import edu.group5.app.model.AppState; import edu.group5.app.model.organization.Organization; import edu.group5.app.model.organization.OrganizationService; import edu.group5.app.utils.ParameterValidator; @@ -19,13 +20,33 @@ *

*/ public class OrganizationController { + private final AppState appState; private final OrganizationService service; - public OrganizationController(OrganizationService service) { + public OrganizationController(AppState appState, OrganizationService service) { + ParameterValidator.objectChecker(appState, "AppState"); ParameterValidator.objectChecker(service, "OrganizationService"); + this.appState = appState; this.service = service; } + + /** + * Sets the current selected organization. + * @param organization the organization to set as current + */ + public void setCurrentOrganization(Organization org) { + appState.setCurrentOrganization(org); + } + + /** + * Gets the current selected organization. + * @return the current organization, or null if none selected + */ + public Organization getCurrentOrganization() { + return appState.getCurrentOrganization(); + } + public Organization getOrganizationById(int orgId) { ParameterValidator.intChecker(orgId, "Organization ID"); return service.findByOrgNumber(orgId);