Skip to content

Commit

Permalink
Fix: Added another contructor to charity and fixed naming on donation
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Apr 13, 2026
1 parent cda2d21 commit 4ed3002
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ public CharityRegistry getCharitiesFromDB() {
conn = connection.getMySqlConnection();
String sql_query =
"""
SELECT
c.UUID_charities, c.org_number, c.pre_approved, c.status,
f.UUID_feedback, f.feedback_comment, f.feedback_date, f.isAnonymous, f.charity_id, f.user_id,
cv.charity_name, cv.charity_link, cv.description, cv.logoURL, cv.key_values, cv.logoBLOB,
u.UUID_user, u.user_name, u.user_email, u.user_password, u.role
cat.category
FROM Charities c
LEFT JOIN Feedback f ON f.charity_id = c.UUID_charities
LEFT JOIN User u ON f.user_id = u.UUID_user
LEFT JOIN Charity_Categories cc ON cc.Charities_UUID_charities = c.UUID.charities
LEFT JOIN Cateegories cat ON cat.category_id = cc.Categories_category_id
INNER JOIN CharityVanity cv ON cv.UUID_charity = c.UUID_charities;
""";
SELECT
c.UUID_charities, c.org_number, c.pre_approved, c.status,
f.UUID_feedback, f.feedback_comment, f.feedback_date, f.isAnonymous, f.charity_id, f.user_id,
cv.charity_name, cv.charity_link, cv.description, cv.logoURL, cv.key_values, cv.logoBLOB,
u.UUID_user, u.user_name, u.user_email, u.user_password, u.role
cat.category
FROM Charities c
LEFT JOIN Feedback f ON f.charity_id = c.UUID_charities
LEFT JOIN User u ON f.user_id = u.UUID_user
LEFT JOIN Charity_Categories cc ON cc.Charities_UUID_charities = c.UUID.charities
LEFT JOIN Cateegories cat ON cat.category_id = cc.Categories_category_id
INNER JOIN CharityVanity cv ON cv.UUID_charity = c.UUID_charities;
""";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql_query);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ public class Charity {
/* Bytecode for the charity logo */
private byte[] logoBlob;

/**
* Minimal contructor JUST FOR DONATIONSSELECT.
* Just cause donation object needs to only contain information about receiver {@code Chairty } and donator {@code User}, and not necessarily Urls, logos, and etc.
*
* @param uuid from DonationSelect
* @param org_number matches from DonationSelect
* @param is_pre_approved name matches from DonationSelect
* @param status name matches from DonationSelect
*/
public Charity(
String uuid, String org_number, Boolean is_pre_approved, String status){
this.UUID = java.util.UUID.fromString(uuid);
this.org_number = org_number.replaceAll("\\s", "");
this.is_pre_approved = is_pre_approved;
this.status = status;
}

/**
* Contructor for creating a new charity. Taylored to match data given from Api. Other attributes
* will just be initialized as empty
Expand All @@ -69,7 +86,7 @@ public Charity(

/**
* Contructor for creating a new charity. Taylored to match data given from DATABASE. Expects
* paramaters that will fill all attributes. EXECPT for feedbacks and categories.
* paramaters that will fill all attributes. EXECPT for feedbacks and categories (which is done right after).
*
* @param org_number matches from innsamlingkontrollen
* @param name matches from innsamlingkontrollen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class Donation {
/* UUID for uniquely identifying each donation */
private UUID charityId;
private UUID donationID;

/* Ammount of money donated */
private double amount;
Expand All @@ -20,6 +20,7 @@ public class Donation {
/* The user/donor that made the donation */
private User donor;


/** Is the donation made anonymously? This can be null if the donation was made anonymously. */
private boolean isAnonymous;

Expand All @@ -33,7 +34,7 @@ public class Donation {
* @param donor
*/
public Donation(double amount, LocalDate date, Charity charity, User donor) {
this.charityId = UUID.randomUUID();
this.donationID = UUID.randomUUID();
this.amount = amount;
this.date = date;
this.charity = charity;
Expand All @@ -42,21 +43,28 @@ public Donation(double amount, LocalDate date, Charity charity, User donor) {
}

/**
* Constructor for creating a new donation. Taylored for getting info FROM DATABASE. NEEDS TO BE
* CHANGED in phase 3.
* Constructor for creating a donation reed from the database.
*
* @param amount
* @param date
* @param charity
* @param uuid
* @param donationId the stored UUID string for this donation; must not be {@code null}
* @param amount the donated amount
* @param date the date the donation was made; must not be {@code null}
* @param charity the receiving charity; must not be {@code null}
* @param donor the donating user, or {@code null} if anonymous
* @param isAnonymous whether the donation was recorded as anonymous
*/
public Donation(String uuid, double amount, LocalDate date, Charity charity) {
this.charityId = UUID.fromString(uuid);
public Donation(
String donationId,
double amount,
LocalDate date,
Charity charity,
User donor,
boolean isAnonymous) {
this.donationID = UUID.fromString(donationId);
this.amount = amount;
this.date = date;
this.charity = charity;
this.donor = null;
this.isAnonymous = true;
this.donor = donor;
this.isAnonymous = isAnonymous;
}

/* Getters for the donation's attributes */
Expand Down

0 comments on commit 4ed3002

Please sign in to comment.