Skip to content

Commit

Permalink
docs: renamed LoginController to AuthController and updated javadoc i…
Browse files Browse the repository at this point in the history
…n controller clases to be more descriptive
  • Loading branch information
emilfa committed Apr 9, 2026
1 parent 4dcccb2 commit 69ec247
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,48 @@
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}.
* Controller responsible for authentication-related operations.
*
* <p>Coordinates between {@link AppState}, {@link NavigationController}
* and {@link UserService} to:
* <ul>
* <li>Sign-up a new user</li>
* <li>Login in a user</li>
* <li>Logout a user</li>
* </ul>
* </p>
*/
public class LoginController {
public class AuthController {
private final AppState appState;
private final NavigationController nav;
private final UserService userService;

public LoginController(AppState appState, NavigationController nav, UserService userService) {
public AuthController(AppState appState, NavigationController nav, UserService userService) {
this.appState = appState;
this.nav = nav;
this.userService = userService;
}

/**
* Handles the sign in of a new {@link User}.
* Handles the registration of a {@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}.
* <ul>
* <li>Validates the firstname, lastname, email and password fields</li>
* <li>Encrypts the password</li>
* <li>Invokes {@link UserService#registerUser(String, String, String, String, String)} to register the user</li>
* </ul>
*
* <p>If the registration is successful, the user is stored in {@link AppState} and
* the application navigates to the home page. Otherwise, an error message
* is displayed in the provided view.</p>
*
* @param view the view used to display feedback to the user
* @param firstName the user's first name
* @param lastName the user's last name
* @param email the user's email
* @param passwordChars the user's password
*/
public void handleSignIn(SignInPageView view, String firstName, String lastName, String email, char[] passwordChars) {
public void handleSignUp(SignInPageView view, String firstName, String lastName, String email, char[] passwordChars) {
if (firstName == null || firstName.trim().isEmpty() ||
lastName == null || lastName.trim().isEmpty() ||
email == null || email.trim().isEmpty() ||
Expand Down Expand Up @@ -60,9 +78,18 @@ 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}.
* <ul>
* <li>Validates the email and password of the user</li>
* <li>Invokes {@link UserService#login(String, char[])} to login in the user</li>
* </ul>
*
* If the login is successful, the user is stored in {@link AppState} and the
* application navigates to the home page. Otherwise, an error message is
* displayed within the provided view.
*
* @param view the view used to display feedback to the user
* @param email the user's email
* @param passwordChars the user's password
*/
public void handleLogin(LoginPageView view, String email, char[] passwordChars) {
if (email == null || email.trim().isEmpty() || passwordChars == null || passwordChars.length == 0) {
Expand All @@ -82,11 +109,15 @@ public void handleLogin(LoginPageView view, String email, char[] passwordChars)

/**
* Handles the logout of a {@link User}.
*
* <p>Clears states in {@link AppState} and the application
* navigates to the login page.</p>
*/
public void handleLogout() {
appState.setCurrentUser(null);
appState.setCurrentOrganization(null);
appState.setCurrentDonationAmount(null);
appState.setCurrentPaymentMethod(null);
nav.showLoginPage();
}
}
39 changes: 34 additions & 5 deletions src/main/java/edu/group5/app/control/DonationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@
import java.util.Set;

/**
* A controller that handles the logic pertaining to
* making donations and getting data via {@link DonationService}.
* Controller responsible for donation-related operations.
*
* <p>
* Coordinates between {@link AppState}, {@link DonationService}
* and {@link NavigationController} to:
* <ul>
* <li>Retrieve donation data for the current user</li>
* <li>Process new donations</li>
* <li>Handle navigation after donation completion</li>
* </ul>
* </p>
*/
public class DonationController {
private final AppState appState;
Expand All @@ -27,11 +36,23 @@ public DonationController(AppState appState, NavigationController nav, DonationS
this.service = service;
}

/**
* Retrieves all donations made by a specific user.
*
* @param userId the ID of the user
* @return a map of donations.
*/
public Map<Integer, Donation> getUserDonations(int userId) {
return service.getDonationRepository().filterByUser(userId);
}

public Set<Integer> getUniqueOrganizations() {
/**
* Returns a set of unique organization IDs that the current user
* has donated to.
*
* @return a set of organization IDs
*/
public Set<Integer> getUniqueOrganizationIDs() {
Map<Integer, Donation> userDonations = getUserDonations(appState.getCurrentUser().getUserId());

Set<Integer> uniqueOrganizations = new HashSet<>();
Expand All @@ -43,8 +64,16 @@ public Set<Integer> getUniqueOrganizations() {
}

/**
* Handles the creation of a new donation via {@link DonationService}
* and {@link AppState}.
* Processes a donation using data stored in {@link AppState}.
*
* <p>
* <ul>
* <li>Validates the current user, organization, amount and payment method</li>
* <li>Invokes {@link DonationService#donate(Customer, int, BigDecimal, String)} to create the donation</li>
* <li>Clears temporary donation state</li>
* <li>Navigates to the payment complete view</li>
* </ul>
* </p>
*/
public void handleDonate() {
// Get session data from MainController
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/edu/group5/app/control/NavigationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import javafx.scene.layout.BorderPane;

/**
* A controller that handles the switching of views in the root node.
* Controller responsible for navigating between views within the root node.
*/
public class NavigationController {
private final BorderPane root;
Expand All @@ -26,7 +26,7 @@ public class NavigationController {

private final AppState appState;

private final LoginController loginController;
private final AuthController authController;
private final DonationController donationController;
private final OrganizationController organizationController;

Expand All @@ -37,9 +37,9 @@ public NavigationController(BorderPane root, AppState appState, UserService user

this.appState = appState;

this.loginController = new LoginController(appState, this, userService);
this.authController = new AuthController(appState, this, userService);
this.donationController = new DonationController(appState, this, donationService);
this.organizationController = new OrganizationController(appState, this, organizationService);
this.organizationController = new OrganizationController(organizationService);
}

public void showHomePage() {
Expand All @@ -49,12 +49,12 @@ public void showHomePage() {

public void showLoginPage() {
root.setTop(loginHeader);
root.setCenter(new LoginPageView(appState, this, loginController));
root.setCenter(new LoginPageView(appState, this, authController));
}

public void showSignInPage() {
root.setTop(loginHeader);
root.setCenter(new SignInPageView(appState, this, loginController));
root.setCenter(new SignInPageView(appState, this, authController));
}

public void showPaymentCompletePage() {
Expand Down Expand Up @@ -83,6 +83,6 @@ public void showAboutUsPage() {

public void showUserPage() {
root.setTop(header);
root.setCenter(new UserPageView(appState, this, loginController, donationController, organizationController));
root.setCenter(new UserPageView(appState, this, authController, donationController, organizationController));
}
}
14 changes: 4 additions & 10 deletions src/main/java/edu/group5/app/control/OrganizationController.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
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 java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
* A controller that handles the data being passed to
* the view via the {@link OrganizationService}.
* Controller responsible for organization-related operations.
*/
public class OrganizationController {
private final AppState appState;
private final NavigationController nav;
private final OrganizationService service;

public OrganizationController(AppState appState, NavigationController nav, OrganizationService service) {
this.appState = appState;
this.nav = nav;
public OrganizationController(OrganizationService service) {
this.service = service;
}

public Organization getOrgById(int orgId) {
public Organization getOrganizationById(int orgId) {
return service.findByOrgNumber(orgId);
}

public Map<Integer, Organization> getTrustedOrgs() {
public Map<Integer, Organization> getTrustedOrganizations() {
return service.getTrustedOrganizations();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private GridPane createOrganizationSection(String searchTerm) {
}

if (allOrganizations == null) {
allOrganizations = orgController.getTrustedOrgs();
allOrganizations = orgController.getTrustedOrganizations();

//Show loading text while organizations and logos are fetched
grid.add(new javafx.scene.control.Label("Loading..."), 0, 0);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/edu/group5/app/view/loginpage/LoginPageView.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package edu.group5.app.view.loginpage;

import edu.group5.app.control.NavigationController;
import edu.group5.app.control.LoginController;
import edu.group5.app.control.AuthController;
import edu.group5.app.model.AppState;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
Expand All @@ -15,16 +15,16 @@
public class LoginPageView extends BorderPane {
private final AppState appState;
private final NavigationController nav;
private final LoginController loginController;
private final AuthController authController;

private TextField emailField;
private PasswordField passwordField;
private Label errorLabel;

public LoginPageView(AppState appState, NavigationController nav, LoginController loginController) {
public LoginPageView(AppState appState, NavigationController nav, AuthController authController) {
this.appState = appState;
this.nav = nav;
this.loginController = loginController;
this.authController = authController;

HBox content = new HBox();
content.setFillHeight(true);
Expand Down Expand Up @@ -97,7 +97,7 @@ private Button getLoginBtn() {
Button loginBtn = new Button("Log In");
loginBtn.setMaxWidth(300);
loginBtn.setId("login-btn");
loginBtn.setOnMouseClicked(e -> loginController.handleLogin(
loginBtn.setOnMouseClicked(e -> authController.handleLogin(
this,
getEmail(),
getPassword()
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/edu/group5/app/view/loginpage/SignInPageView.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package edu.group5.app.view.loginpage;

import edu.group5.app.control.NavigationController;
import edu.group5.app.control.LoginController;
import edu.group5.app.control.AuthController;
import edu.group5.app.model.AppState;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
Expand All @@ -16,18 +16,18 @@
public class SignInPageView extends BorderPane {
private final AppState appState;
private final NavigationController nav;
private final LoginController loginController;
private final AuthController authController;

private TextField nameField;
private TextField surnameField;
private TextField emailField;
private PasswordField passwordField;
private Label errorLabel;

public SignInPageView(AppState appState, NavigationController nav, LoginController loginController) {
public SignInPageView(AppState appState, NavigationController nav, AuthController authController) {
this.appState = appState;
this.nav = nav;
this.loginController = loginController;
this.authController = authController;

HBox content = new HBox();
content.setFillHeight(true);
Expand Down Expand Up @@ -130,7 +130,7 @@ private Button getSignInBtn() {
Button signInBtn = new Button("Sign In");
signInBtn.setMaxWidth(300);
signInBtn.setId("login-btn");
signInBtn.setOnMouseClicked(e -> loginController.handleSignIn(
signInBtn.setOnMouseClicked(e -> authController.handleSignUp(
this,
getFirstName(),
getLastName(),
Expand Down
Loading

0 comments on commit 69ec247

Please sign in to comment.