Skip to content

Commit

Permalink
docs: added javadoc to controller classes
Browse files Browse the repository at this point in the history
  • Loading branch information
emilfa committed Apr 9, 2026
1 parent ff2e953 commit 4dcccb2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/main/java/edu/group5/app/control/DonationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import java.util.Map;
import java.util.Set;

/**
* A controller that handles the logic pertaining to
* making donations and getting data via {@link DonationService}.
*/
public class DonationController {
private final AppState appState;
private final NavigationController nav;
Expand All @@ -27,17 +31,21 @@ public Map<Integer, Donation> getUserDonations(int userId) {
return service.getDonationRepository().filterByUser(userId);
}

public Set<Integer> getUniqueOrgs() {
public Set<Integer> getUniqueOrganizations() {
Map<Integer, Donation> userDonations = getUserDonations(appState.getCurrentUser().getUserId());

Set<Integer> uniqueOrgs = new HashSet<>();
Set<Integer> uniqueOrganizations = new HashSet<>();
for (Donation donation : userDonations.values()) {
uniqueOrgs.add(donation.organizationId());
uniqueOrganizations.add(donation.organizationId());
}

return uniqueOrgs;
return uniqueOrganizations;
}

/**
* Handles the creation of a new donation via {@link DonationService}
* and {@link AppState}.
*/
public void handleDonate() {
// Get session data from MainController
User currentUser = appState.getCurrentUser();
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/edu/group5/app/control/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import edu.group5.app.view.loginpage.SignInPageView;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
* A controller that handles the logic pertaining to {@link User}
* sign in, login and logout via {@link UserService}.
*/
public class LoginController {
private final AppState appState;
private final NavigationController nav;
Expand All @@ -18,6 +22,15 @@ public LoginController(AppState appState, NavigationController nav, UserService
this.userService = userService;
}

/**
* Handles the sign in of a new {@link User}.
*
* @param view view connected to the sign in.
* @param firstName first name of the {@link User}.
* @param lastName last name of the {@link User}.
* @param email email of the {@link User}.
* @param passwordChars password of the {@link User}.
*/
public void handleSignIn(SignInPageView view, String firstName, String lastName, String email, char[] passwordChars) {
if (firstName == null || firstName.trim().isEmpty() ||
lastName == null || lastName.trim().isEmpty() ||
Expand All @@ -44,6 +57,13 @@ public void handleSignIn(SignInPageView view, String firstName, String lastName,
}
}

/**
* Handles the login of a {@link User}.
*
* @param view view connected to the login.
* @param email email of the {@link User}.
* @param passwordChars password of the {@link User}.
*/
public void handleLogin(LoginPageView view, String email, char[] passwordChars) {
if (email == null || email.trim().isEmpty() || passwordChars == null || passwordChars.length == 0) {
view.showError("Email and password are required");
Expand All @@ -60,6 +80,9 @@ public void handleLogin(LoginPageView view, String email, char[] passwordChars)
}
}

/**
* Handles the logout of a {@link User}.
*/
public void handleLogout() {
appState.setCurrentUser(null);
appState.setCurrentOrganization(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import edu.group5.app.view.userpage.UserPageView;
import javafx.scene.layout.BorderPane;

/**
* A controller that handles the switching of views in the root node.
*/
public class NavigationController {
private final BorderPane root;
private final Header header;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
* A controller that handles the data being passed to
* the view via the {@link OrganizationService}.
*/
public class OrganizationController {
private final AppState appState;
private final NavigationController nav;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private VBox createCausesSection() {

User currentUser = appState.getCurrentUser();

Set<Integer> uniqueOrgs = donationController.getUniqueOrgs();
Set<Integer> uniqueOrgs = donationController.getUniqueOrganizations();

if (uniqueOrgs.isEmpty()) {
Label noCauses = new Label("No causes supported yet");
Expand Down

0 comments on commit 4dcccb2

Please sign in to comment.