-
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.
- Loading branch information
AdrianBalunan
committed
Mar 16, 2026
1 parent
b67c102
commit 52fb5df
Showing
24 changed files
with
829 additions
and
872 deletions.
There are no files selected for viewing
55 changes: 27 additions & 28 deletions
55
helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/DAO/DonationDAO.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 |
|---|---|---|
| @@ -1,44 +1,43 @@ | ||
| package ntnu.systemutvikling.team6.DAO; | ||
|
|
||
| import ntnu.systemutvikling.team6.database.DatabaseConnection; | ||
| import ntnu.systemutvikling.team6.models.Charity; | ||
|
|
||
| import java.sql.*; | ||
| import java.util.Calendar; | ||
| import java.util.UUID; | ||
| import ntnu.systemutvikling.team6.database.DatabaseConnection; | ||
| import ntnu.systemutvikling.team6.models.Charity; | ||
|
|
||
| /** | ||
| * This class is responsible for sending concurrent information about the donation to the Donation Database. | ||
| * Usally called from the DonationPageController, where the user confirms their donation. | ||
| * This class is responsible for sending concurrent information about the donation to the Donation | ||
| * Database. Usally called from the DonationPageController, where the user confirms their donation. | ||
| */ | ||
|
|
||
| public class DonationDAO { | ||
| private static final DatabaseConnection connection = new DatabaseConnection(); | ||
| private static final DatabaseConnection connection = new DatabaseConnection(); | ||
|
|
||
| /** | ||
| * 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, double amount){ | ||
| String sql_query = | ||
| """ | ||
| /** | ||
| * 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, double amount) { | ||
| String sql_query = | ||
| """ | ||
| INSERT INTO Donations (UUID_Donations, amount, date, Charities_UUID_charities) | ||
| VALUES (?, ?, ?, ?) | ||
| """; | ||
| try (Connection conn = connection.getMySqlConnection(); | ||
| PreparedStatement ps = conn.prepareStatement(sql_query)){ | ||
| conn.setAutoCommit(false); | ||
| try (Connection conn = connection.getMySqlConnection(); | ||
| PreparedStatement ps = conn.prepareStatement(sql_query)) { | ||
| conn.setAutoCommit(false); | ||
|
|
||
| ps.setString(1, UUID.randomUUID().toString()); | ||
| ps.setDouble(2, amount); | ||
| ps.setDate(3, new Date(System.currentTimeMillis())); | ||
| ps.setString(4, charity.getUUID().toString()); | ||
| ps.setString(1, UUID.randomUUID().toString()); | ||
| ps.setDouble(2, amount); | ||
| ps.setDate(3, new Date(System.currentTimeMillis())); | ||
| ps.setString(4, charity.getUUID().toString()); | ||
|
|
||
| ps.executeUpdate(); | ||
| conn.commit(); | ||
| } catch (SQLException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| ps.executeUpdate(); | ||
| conn.commit(); | ||
| } catch (SQLException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } |
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
1 change: 0 additions & 1 deletion
1
helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/Main.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
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
Oops, something went wrong.