-
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.
Merge pull request #55 from Group-5/workaround/ntnu-git-is-suboptimal
Merge Workaround/ntnu git is suboptimal into release/v1.0.0
- Loading branch information
Showing
63 changed files
with
2,958 additions
and
120 deletions.
There are no files selected for viewing
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
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 |
|---|---|---|
| @@ -1,10 +1,100 @@ | ||
| package edu.group5.app; | ||
|
|
||
| import edu.group5.app.control.MainController; | ||
| import edu.group5.app.control.wrapper.DbWrapper; | ||
| import edu.group5.app.control.wrapper.OrgApiWrapper; | ||
| import edu.group5.app.model.donation.Donation; | ||
| import edu.group5.app.model.donation.DonationRepository; | ||
| import edu.group5.app.model.donation.DonationService; | ||
| import edu.group5.app.model.organization.OrganizationRepository; | ||
| import edu.group5.app.model.organization.OrganizationService; | ||
| import edu.group5.app.model.user.User; | ||
| import edu.group5.app.model.user.UserRepository; | ||
| import edu.group5.app.model.user.UserService; | ||
| import javafx.application.Application; | ||
| import javafx.scene.Scene; | ||
| import javafx.scene.image.Image; | ||
| import javafx.stage.Stage; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import java.util.logging.Logger; | ||
|
|
||
| /** | ||
| * Hello world! | ||
| * Main entry point for the Help-Me-Help charity donation application. | ||
| * Handles database connection, data loading, and application setup. | ||
| */ | ||
| public class App { | ||
| public static void main(String[] args) throws InterruptedException { | ||
| System.out.println("Hello World!"); | ||
| public class App extends Application { | ||
| DbWrapper dbWrapper; | ||
| UserRepository userRepository; | ||
| DonationRepository donationRepository; | ||
| private Logger logger; | ||
| private MainController controller; | ||
| private Scene scene; | ||
|
|
||
| @Override | ||
| public void init() { | ||
| this.logger = Logger.getLogger(App.class.getName()); | ||
| this.logger.info("Application starting"); | ||
|
|
||
| this.dbWrapper = new DbWrapper(false); | ||
| OrgApiWrapper orgApiWrapper = new OrgApiWrapper("https://app.innsamlingskontrollen.no/api/public/v1/all"); | ||
|
|
||
| while (!dbWrapper.connect()) { | ||
| this.logger.warning("Failed to connect to database"); | ||
| } | ||
|
|
||
| // Load data from database | ||
| List<Object[]> userData = dbWrapper.importUsers(); | ||
| List<Object[]> donationData = dbWrapper.fetchAllDonations(); | ||
| dbWrapper.disconnect(); | ||
|
|
||
| // Load organizations from API | ||
| Object[] organizationData = new Object[0]; | ||
| try { | ||
| if (orgApiWrapper.importData()) { | ||
| organizationData = orgApiWrapper.getData(); | ||
| } | ||
| } catch (InterruptedException e) { | ||
| System.err.println("Failed to load organization data: " + e.getMessage()); | ||
| } | ||
|
|
||
| // Create repositories with fetched data | ||
| this.userRepository = new UserRepository(userData); | ||
| this.donationRepository = new DonationRepository(donationData); | ||
| OrganizationRepository organizationRepository = new OrganizationRepository(organizationData); | ||
|
|
||
| // Create services (backend wiring) | ||
| UserService userService = new UserService(this.userRepository); | ||
| DonationService donationService = new DonationService(this.donationRepository, organizationRepository); | ||
| OrganizationService organizationService = new OrganizationService(organizationRepository); | ||
|
|
||
| this.controller = new MainController(userService, donationService, organizationService); | ||
|
|
||
| this.scene = controller.getMainView().getScene(); | ||
| } | ||
|
|
||
| @Override | ||
| public void start(Stage stage) { | ||
| this.controller.showLoginPage(); | ||
|
|
||
| stage.getIcons().add(new Image(getClass().getResource("/header/images/hmh-logo.png").toExternalForm())); | ||
| stage.setTitle("Help-Me-Help"); | ||
| stage.setScene(this.scene); | ||
| stage.show(); | ||
| } | ||
|
|
||
| @Override | ||
| public void stop() throws Exception { | ||
| super.stop(); | ||
| this.logger.info("Application stopping"); | ||
| this.dbWrapper.connect(); | ||
| this.dbWrapper.exportUsers(this.userRepository.export()); | ||
| this.dbWrapper.exportDonations(this.donationRepository.export()); | ||
| this.dbWrapper.disconnect(); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| launch(args); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/main/java/edu/group5/app/control/BrowseCardController.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,16 @@ | ||
| package edu.group5.app.control; | ||
|
|
||
| import edu.group5.app.model.organization.Organization; | ||
|
|
||
| public class BrowseCardController { | ||
| private final MainController controller; | ||
|
|
||
| public BrowseCardController(MainController mainController) { | ||
| this.controller = mainController; | ||
| } | ||
|
|
||
| public void handleCardClick(Organization organization) { | ||
| controller.setCurrentOrganization(organization); | ||
| controller.showOrganizationPage(); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/edu/group5/app/control/BrowsePageController.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,9 @@ | ||
| package edu.group5.app.control; | ||
|
|
||
| public class BrowsePageController { | ||
| private final MainController controller; | ||
|
|
||
| public BrowsePageController(MainController mainController) { | ||
| this.controller = mainController; | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
src/main/java/edu/group5/app/control/HeaderController.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,28 @@ | ||
| package edu.group5.app.control; | ||
|
|
||
| public class HeaderController { | ||
| private final MainController controller; | ||
|
|
||
| public HeaderController(MainController controller) { | ||
| this.controller = controller; | ||
| } | ||
|
|
||
| public void handleHomeBtn() { | ||
| System.out.println("Home button pressed"); | ||
| controller.showHomePage(); | ||
| } | ||
|
|
||
| public void handleCausesBtn() { | ||
| System.out.println("Causes button pressed"); | ||
| controller.showBrowsePage(); | ||
| } | ||
|
|
||
| public void handleAboutBtn() { | ||
| System.out.println("About button pressed"); | ||
| } | ||
|
|
||
| public void handleProfileBtn() { | ||
| System.out.println("profileSection"); | ||
| controller.showUserPage(); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/main/java/edu/group5/app/control/HomePageController.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,19 @@ | ||
| package edu.group5.app.control; | ||
|
|
||
| public class HomePageController { | ||
| private final MainController controller; | ||
|
|
||
| public HomePageController(MainController controller) { | ||
| this.controller = controller; | ||
| } | ||
|
|
||
| public void handleDonateToACauseBtn() { | ||
| System.out.println("Donate to a cause button pressed"); | ||
| controller.showBrowsePage(); | ||
| } | ||
|
|
||
| public void handleAboutUsBtn() { | ||
| System.out.println("About us button pressed"); | ||
| controller.showAboutUsPage(); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
src/main/java/edu/group5/app/control/LoginPageController.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,44 @@ | ||
| package edu.group5.app.control; | ||
|
|
||
| import edu.group5.app.model.user.User; | ||
| import edu.group5.app.model.user.UserService; | ||
| import edu.group5.app.view.loginpage.LoginPageView; | ||
|
|
||
| public class LoginPageController { | ||
| private final MainController controller; | ||
| private final UserService userService; | ||
| private LoginPageView view; | ||
|
|
||
| public LoginPageController(MainController controller, UserService userService) { | ||
| this.controller = controller; | ||
| this.userService = userService; | ||
| } | ||
|
|
||
| public void setView(LoginPageView view) { | ||
| this.view = view; | ||
| } | ||
|
|
||
| public void handleLoginBtn() { | ||
| String email = view.getEmail(); | ||
| char[] passwordChars = view.getPassword(); | ||
|
|
||
| if (email == null || email.trim().isEmpty() || passwordChars == null || passwordChars.length == 0) { | ||
| view.showError("Email and password are required"); | ||
| return; | ||
| } | ||
|
|
||
| User user = userService.login(email, passwordChars); | ||
|
|
||
| if (user != null) { | ||
| controller.setCurrentUser(user); | ||
| controller.showHomePage(); | ||
| } else { | ||
| view.showError("Invalid email or password"); | ||
| } | ||
| } | ||
|
|
||
| public void handleRegisterBtn() { | ||
| System.out.println("Sign in button pressed"); | ||
| controller.showSignInPage(); | ||
| } | ||
| } |
121 changes: 121 additions & 0 deletions
121
src/main/java/edu/group5/app/control/MainController.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,121 @@ | ||
| package edu.group5.app.control; | ||
|
|
||
| import edu.group5.app.control.donationpage.DonationPageController; | ||
| import edu.group5.app.model.donation.DonationService; | ||
| import edu.group5.app.model.organization.Organization; | ||
| import edu.group5.app.model.organization.OrganizationService; | ||
| import edu.group5.app.model.user.User; | ||
| import edu.group5.app.model.user.UserService; | ||
| import edu.group5.app.view.MainView; | ||
| import edu.group5.app.view.donationpage.DonationPageView; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| public class MainController { | ||
| private final MainView view; | ||
| private final HeaderController headerController; | ||
| private final HomePageController homePageController; | ||
| private final BrowsePageController browsePageController; | ||
| private final BrowseCardController browseCardController; | ||
| private final OrganizationPageController organizationPageController; | ||
| private final DonationPageController donationPageController; | ||
| private final UserService userService; | ||
| private final DonationService donationService; | ||
| private final OrganizationService organizationService; | ||
| private User currentUser; | ||
| private Organization currentOrganization; | ||
| private BigDecimal currentDonationAmount; | ||
|
|
||
| public MainController(UserService userService, DonationService donationService, | ||
| OrganizationService organizationService) { | ||
| this.userService = userService; | ||
| this.donationService = donationService; | ||
| this.organizationService = organizationService; | ||
|
|
||
| this.view = new MainView(this, userService); | ||
| this.headerController = new HeaderController(this); | ||
| this.homePageController = new HomePageController(this); | ||
| this.browsePageController = new BrowsePageController(this); | ||
| this.browseCardController = new BrowseCardController(this); | ||
| this.organizationPageController = new OrganizationPageController(this); | ||
| this.donationPageController = new DonationPageController(this); | ||
| } | ||
|
|
||
| public UserService getUserService() { | ||
| return userService; | ||
| } | ||
|
|
||
| public DonationService getDonationService() { | ||
| return donationService; | ||
| } | ||
|
|
||
| public OrganizationService getOrganizationService() { | ||
| return organizationService; | ||
| } | ||
|
|
||
| public void setCurrentUser(User user) { | ||
| this.currentUser = user; | ||
| } | ||
|
|
||
| public User getCurrentUser() { | ||
| return this.currentUser; | ||
| } | ||
|
|
||
| public void setCurrentOrganization(Organization organization) { | ||
| this.currentOrganization = organization; | ||
| } | ||
|
|
||
| public Organization getCurrentOrganization() { | ||
| return this.currentOrganization; | ||
| } | ||
|
|
||
| public void setCurrentDonationAmount(BigDecimal amount) { | ||
| this.currentDonationAmount = amount; | ||
| } | ||
|
|
||
| public BigDecimal getCurrentDonationAmount() { | ||
| return this.currentDonationAmount; | ||
| } | ||
|
|
||
| public void logout() { | ||
| currentUser = null; | ||
| currentOrganization = null; | ||
| currentDonationAmount = null; | ||
| showLoginPage(); | ||
| } | ||
|
|
||
| public MainView getMainView() { | ||
| return view; | ||
| } | ||
|
|
||
| public void showHomePage() { | ||
| view.showHomePage(homePageController, headerController); | ||
| } | ||
|
|
||
| public void showLoginPage() { | ||
| view.showLoginPage(); | ||
| } | ||
| public void showSignInPage() { | ||
| view.showSignInPage(); | ||
| } | ||
| public void showPaymentCompletePage() { | ||
| view.showPaymentCompletePage(); | ||
| } | ||
| public void showBrowsePage() { | ||
| view.showBrowsePage(browsePageController, browseCardController, headerController); | ||
| } | ||
|
|
||
| public void showOrganizationPage() { | ||
| view.showOrganizationPage(organizationPageController, headerController); | ||
| } | ||
|
|
||
| public void showDonationPage() { | ||
| view.showDonationPage(); | ||
| } | ||
|
|
||
| public void showAboutUsPage() {} | ||
|
|
||
| public void showUserPage() { | ||
| view.showUserPage(); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/main/java/edu/group5/app/control/OrganizationPageController.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,13 @@ | ||
| package edu.group5.app.control; | ||
|
|
||
| public class OrganizationPageController { | ||
| private final MainController controller; | ||
|
|
||
| public OrganizationPageController(MainController controller) { | ||
| this.controller = controller; | ||
| } | ||
|
|
||
| public void handleDonateClick() { | ||
| controller.showDonationPage(); | ||
| } | ||
| } |
Oops, something went wrong.