Skip to content

Commit

Permalink
feat[app]: overwrite close method to export information to database o…
Browse files Browse the repository at this point in the history
…n exit
  • Loading branch information
Lucy Ciara Herud-Thomassen authored and Lucy Ciara Herud-Thomassen committed Mar 20, 2026
1 parent 44b0811 commit e746035
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions src/main/java/edu/group5/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
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;
Expand All @@ -16,19 +18,30 @@

import java.util.List;

import java.util.logging.Logger;

/**
* Main entry point for the Help-Me-Help charity donation application.
* Handles database connection, data loading, and application setup.
*/
public class App extends Application {
DbWrapper dbWrapper;
UserRepository userRepository;
DonationRepository donationRepository;
private Logger logger;
private MainController controller;
private Scene scene;

@Override
public void start(Stage stage) {
DbWrapper dbWrapper = new DbWrapper(true);
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");

if (!dbWrapper.connect()) {
System.err.println("Failed to connect to database");
return;
while (!dbWrapper.connect()) {
this.logger.warning("Failed to connect to database");
}

// Load data from database
Expand All @@ -47,26 +60,39 @@ public void start(Stage stage) {
}

// Create repositories with fetched data
UserRepository userRepository = new UserRepository(userData);
DonationRepository donationRepository = new DonationRepository(donationData);
this.userRepository = new UserRepository(userData);
this.donationRepository = new DonationRepository(donationData);
OrganizationRepository organizationRepository = new OrganizationRepository(organizationData);

// Create services (backend wiring)
UserService userService = new UserService(userRepository);
DonationService donationService = new DonationService(donationRepository, organizationRepository);
UserService userService = new UserService(this.userRepository);
DonationService donationService = new DonationService(this.donationRepository, organizationRepository);
OrganizationService organizationService = new OrganizationService(organizationRepository);

MainController controller = new MainController(userService, donationService, organizationService);
this.controller = new MainController(userService, donationService, organizationService);

Scene scene = controller.getMainView().getScene();
controller.showLoginPage();
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(scene);
stage.setScene(this.scene);
stage.show();
}

@Override
public void 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);
}
Expand Down

0 comments on commit e746035

Please sign in to comment.