Skip to content

Contain fix to BatchExecption Thing #70

Merged
merged 27 commits into from
Apr 15, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fa1694d
Added Installation Guide HmH.pdf
roaraf Apr 14, 2026
34064d7
Added media folder
roaraf Apr 14, 2026
0647b67
Add files via upload
cathrkri Apr 14, 2026
02dfb32
Feat: Moved DAO objects into database, cuz they interact with database
Apr 15, 2026
a0b4e49
Feat: Moved DAO objects into database, cuz they interact with database
Apr 15, 2026
72045a1
Fix: Forgot about displayName column in users
Apr 15, 2026
939ef16
Feat: Turned DAO objects into non-static object for coupling
Apr 15, 2026
303b852
Feat: Added AuthenticationService object and added new method to chec…
Apr 15, 2026
b786226
Create 1
cathrkri Apr 15, 2026
80c2b3b
Add files via upload
cathrkri Apr 15, 2026
47a6427
Create 1
cathrkri Apr 15, 2026
98e3382
Add files via upload
cathrkri Apr 15, 2026
8794424
Delete docs/persistence/1
cathrkri Apr 15, 2026
1923833
Delete docs/design/1
cathrkri Apr 15, 2026
a365f81
Feat: Tried to split navbar into a component with dedicated controlle…
Apr 15, 2026
3d26424
Feat: Tried to split navbar into a component with dedicated controlle…
Apr 15, 2026
99b0280
Feat: NavvarFoorterController attempt
Apr 15, 2026
a305dec
Fix: Missing u.userdisplay on new user object
Apr 15, 2026
fce473b
Fix: Missing u.userdisplay on new user object
Apr 15, 2026
68bbbd0
Fix: DonationDAO turned into non-static so changes
Apr 15, 2026
8315fcf
Feat: Attempt to make a base controller manual that everycontroller w…
Apr 15, 2026
c348161
Feat: Attempt to use said base controller
Apr 15, 2026
b759941
Fix: removed comment
Apr 15, 2026
740b8b5
Merge branch '56-2-startup/database-fix' of git.ntnu.no:cathrkri/syst…
Apr 15, 2026
bb4a227
Fix 1: DonationSelect had syntax error and DonationTable was missing …
Apr 15, 2026
0553bf4
Fix 2: BatchExecqution is no more, maybe because of foreign key being…
Apr 15, 2026
534e851
Merge pull request #69 from cathrkri/56-2-startup/database-fix
apbaluna Apr 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/Domenemodell/Domene Diagram 2.pdf
Binary file not shown.
Binary file added docs/Manuals/Installation Guide HmH.pdf
Binary file not shown.
Binary file added docs/Manuals/media/image1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Manuals/media/image2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Manuals/media/image3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Manuals/media/image4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Manuals/media/image5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Manuals/media/image6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/design/Universal Design.pdf
Binary file not shown.
Binary file added docs/persistence/Persistence.pdf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import static javafx.application.Application.launch;

import java.net.http.HttpClient;
import java.util.Objects;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.database.DatabaseSetup;
Expand All @@ -15,7 +20,6 @@
public class HmHApplication extends Application {
@Override
public void start(Stage stage) throws Exception {
/*
FXMLLoader fxmlLoader =
new FXMLLoader(HmHApplication.class.getResource("/fxml/frontPage.fxml"));
Scene scene = new Scene(fxmlLoader.load());
Expand All @@ -30,8 +34,6 @@ public void start(Stage stage) throws Exception {
stage.setFullScreen(true);

stage.show();
*/

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import javafx.scene.Parent;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import ntnu.systemutvikling.team6.controller.components.BaseController;
import ntnu.systemutvikling.team6.controller.components.LoaderScene;
import ntnu.systemutvikling.team6.controller.components.NavbarFooterController;
import ntnu.systemutvikling.team6.controller.components.OrganizationCardController;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.database.Readers.CharitySelect;
import ntnu.systemutvikling.team6.models.Charity;
Expand All @@ -22,7 +26,7 @@
* on the featured charity to see more details about it. The user can also switch to the charity
* page or donation page for the selected charity.
*/
public class AvailableOrganizationController {
public class AvailableOrganizationController extends BaseController implements NavbarFooterController {

@FXML private TextField searchField;
@FXML private FlowPane cardsContainer;
Expand Down Expand Up @@ -88,7 +92,7 @@ private void displayCharities(List<Charity> charities) {

for (Charity charity : charities) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/organizationCard.fxml"));
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/components/organizationCard.fxml"));
Parent card = loader.load();

OrganizationCardController cardController = loader.getController();
Expand All @@ -115,15 +119,6 @@ public void setInitialSearch(String query) {
searchField.setText(query);
}

/**
* This method is used to switch to the front page.
*
* @param event action event from button click
*/
@FXML
public void switchToFrontPage(ActionEvent event) {
LoaderScene.LoadScene("FrontPage", event, charity, null);
}

/**
* This method is used to switch to the charity page for the selected charity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import ntnu.systemutvikling.team6.controller.components.LoaderScene;
import ntnu.systemutvikling.team6.models.Charity;

/**
Expand Down Expand Up @@ -40,16 +41,6 @@ public void setCharity(Charity charity) {
CharityName.setText(charity.getName());
}

/**
* This method is used to switch to the front page.
*
* @param event
*/
@FXML
public void switchToFrontPage(ActionEvent event) {
System.out.println("Click");
LoaderScene.LoadScene("FrontPage", event, charity, null);
}

/**
* This method is used to switch to the donation page.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import ntnu.systemutvikling.team6.DAO.DonationDAO;
import ntnu.systemutvikling.team6.controller.components.LoaderScene;
import ntnu.systemutvikling.team6.database.DAO.DonationDAO;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.user.User;

Expand All @@ -24,6 +26,8 @@ public class DonationPageController {

@FXML private TextField donationSearchField;

private DonationDAO donationSender = new DonationDAO(new DatabaseConnection());

/**
* Initialize method for the donation page. Sets the charity name label to the name of the charity
* that is being donated to. The charity is set from the original page it was called from when the
Expand Down Expand Up @@ -116,7 +120,7 @@ public void Donate(ActionEvent event) {
* @param amount
*/
public void processDonation(Charity charity, User user, double amount) {
DonationDAO.addDonation(charity, user, amount);
donationSender.addDonation(charity, user, amount);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import ntnu.systemutvikling.team6.controller.components.BaseController;
import ntnu.systemutvikling.team6.controller.components.LoaderScene;
import ntnu.systemutvikling.team6.controller.components.NavbarFooterController;
import ntnu.systemutvikling.team6.controller.components.OrganizationCardController;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.database.Readers.CharitySelect;
import ntnu.systemutvikling.team6.database.Readers.DonationSelect;
Expand All @@ -27,7 +31,7 @@
* it, or click on the featured charity to see more details about it. It also has buttons to switch
* to the charity page and the donation page for the featured charity
*/
public class FrontpageController {
public class FrontpageController extends BaseController implements NavbarFooterController {
@FXML private Charity featuredCharity;
@FXML private FlowPane cardsContainer;
@FXML private Label Carosel_Organisasjon;
Expand All @@ -43,6 +47,11 @@ public class FrontpageController {

private List<Charity> allCharities = new ArrayList<>();

@Override
protected void authTokenisSet(){

}

/**
* Initialize method for the front page. This method is called when the front page is loaded. It
* retrieves the list of charities and donations from the database. The list of charities is
Expand Down Expand Up @@ -88,6 +97,7 @@ public void initialize() {
}
}


/**
* This method is used to switch to the charity page for the selected charity
*
Expand Down Expand Up @@ -210,7 +220,7 @@ private void displayCharities(List<Charity> charities) {

for (Charity charity : charities) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/organizationCard.fxml"));
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/components/organizationCard.fxml"));
Parent card = loader.load();
OrganizationCardController cardController = loader.getController();
cardController.setOrganization(charity);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ntnu.systemutvikling.team6.controller.components;

import ntnu.systemutvikling.team6.service.AuthenticationService;

public abstract class BaseController {
protected AuthenticationService authToken;

public void setAuthToken(AuthenticationService authToken){
this.authToken = authToken;
authTokenisSet();
};
protected void authTokenisSet(){} // Do stuff after authtoken is set, on each controller

protected boolean isLoggedin(){
return authToken.isLoggedin() && authToken != null;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ntnu.systemutvikling.team6.controller;
package ntnu.systemutvikling.team6.controller.components;

import java.io.IOException;
import java.util.Objects;
Expand All @@ -10,6 +10,9 @@
import javafx.scene.image.Image;
import javafx.stage.Stage;
import ntnu.systemutvikling.team6.HmHApplication;
import ntnu.systemutvikling.team6.controller.AvailableOrganizationController;
import ntnu.systemutvikling.team6.controller.CharityPageController;
import ntnu.systemutvikling.team6.controller.DonationPageController;
import ntnu.systemutvikling.team6.models.Charity;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ntnu.systemutvikling.team6.controller.components;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;

public interface NavbarFooterController {

default void switchToFrontPage(ActionEvent event) {
System.out.println("Click!");
LoaderScene.LoadScene("FrontPage", event, null, null);
}

default void switchToAboutPage(ActionEvent event) {
System.out.println("Click!");
LoaderScene.LoadScene("aboutPage", event, null, null);
}

default void switchToProfilePage(ActionEvent event) {
System.out.println("Click!");
LoaderScene.LoadScene("aboutPage", event, null, null);
}

default void handleSearch(ActionEvent event) {
System.out.println("Click!");
LoaderScene.LoadScene("aboutPage", event, null, null);
}

default void switchToLoginPage(ActionEvent event) {
System.out.println("Click!");
LoaderScene.LoadScene("aboutPage", event, null, null);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ntnu.systemutvikling.team6.controller;
package ntnu.systemutvikling.team6.controller.components;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ntnu.systemutvikling.team6.DAO;
package ntnu.systemutvikling.team6.database.DAO;

import java.sql.*;
import java.util.UUID;
Expand All @@ -11,16 +11,20 @@
* Database. Usally called from the DonationPageController, where the user confirms their donation.
*/
public class DonationDAO {
private static final DatabaseConnection connection = new DatabaseConnection();
private final DatabaseConnection connection;

/**
public DonationDAO(DatabaseConnection connection) {
this.connection = connection;
}

/**
* Gets the total ammount of donations for a given charity, and sends it to the database throught
* MySQL.
*
* @param charity
* @param amount
*/
public static void addDonation(Charity charity, User user, double amount) {
public void addDonation(Charity charity, User user, double amount) {
String sql_query =
"""
INSERT INTO Donations (UUID_Donations, amount, date, charity_id, user_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ntnu.systemutvikling.team6.DAO;
package ntnu.systemutvikling.team6.database.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
Expand All @@ -14,16 +14,21 @@
*/
public class UserDAO {

private static final DatabaseConnection connection = new DatabaseConnection();
private final DatabaseConnection connection;

/**
public UserDAO(DatabaseConnection connection) {
this.connection = connection;
}

/**
* Gets the user and settings information and sends it to the database through MySQL.
*
*
* @param user the user to be saved in the database.
* @throws RuntimeException if a database error occurs during the operation
* @return true or false based on if the register is a success or not
*/
public static void registerUser(User user) {

public boolean registerUser(User user) {
String userSql =
"""
INSERT INTO User (
Expand All @@ -48,20 +53,23 @@ INSERT INTO Settings (
VALUES (?, ?, ?, ?)
""";

int psUserRows = 0;
int psSettingsRows = 0;

try (Connection conn = connection.getMySqlConnection()) {

conn.setAutoCommit(false);

try (PreparedStatement psUser = conn.prepareStatement(userSql)) {

psUser.setString(1, user.getId().toString());
psUser.setString(2, user.getName()); // display name
psUser.setString(3, user.getName()); // username
psUser.setString(2, user.getDisplayName()); // display name
psUser.setString(3, user.getUsername()); // username
psUser.setString(4, user.getEmail());
psUser.setString(5, user.getPasswordHash());
psUser.setString(6, user.getRole().name());

psUser.executeUpdate();
psUserRows = psUser.executeUpdate();
}

try (PreparedStatement psSettings = conn.prepareStatement(settingsSql)) {
Expand All @@ -71,13 +79,16 @@ INSERT INTO Settings (
psSettings.setString(3, user.getSettings().getLanguage().name());
psSettings.setBoolean(4, user.getSettings().isLightMode());

psSettings.executeUpdate();
psSettingsRows = psSettings.executeUpdate();

}

conn.commit();

return psUserRows > 0 && psSettingsRows > 0;
} catch (SQLException e) {
throw new RuntimeException("Failed to insert user into database", e);
e.printStackTrace();
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public boolean testConnection() {
System.out.println("Database connection failed.");
e.printStackTrace();
}

return false;
}

Expand Down Expand Up @@ -74,6 +73,7 @@ PRIMARY KEY (`UUID_charities`),
CREATE TABLE IF NOT EXISTS `apbaluna`.`Donations` (
`UUID_Donations` CHAR(36) NOT NULL,
`amount` DECIMAL NOT NULL,
`isAnonymous` TINYINT NOT NULL,
`date` DATE NOT NULL,
`charity_id` CHAR(36) NOT NULL,
`user_id` CHAR(36) NOT NULL,
Expand Down Expand Up @@ -260,12 +260,11 @@ FOREIGN KEY (`User_UUID_User`)
`key_values` TEXT NULL,
`logoBLOB` MEDIUMBLOB NULL,
INDEX `fk_CharityVanity_Charities1_idx` (`UUID_charity` ASC) VISIBLE,
PRIMARY KEY (`UUID_charity`),
CONSTRAINT `fk_CharityVanity_Charities1`
FOREIGN KEY (`UUID_charity`)
REFERENCES `apbaluna`.`Charities` (`UUID_charities`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ON UPDATE CASCADE)
ENGINE = InnoDB;
""";

Expand Down
Loading
Loading