Skip to content

Commit

Permalink
update[control]: Update controller to handle control of the appstate
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Marjoni committed Apr 16, 2026
1 parent 996e43e commit c67227b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/main/java/edu/group5/app/control/AuthController.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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}.
*
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/edu/group5/app/control/DonationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/edu/group5/app/control/OrganizationController.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,13 +20,33 @@
* </p>
*/
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);
Expand Down

0 comments on commit c67227b

Please sign in to comment.