Skip to content

Commit

Permalink
feat: convert Donation to record and add throws to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
MatheaGjerde committed Mar 2, 2026
1 parent 5787e12 commit d608890
Showing 1 changed file with 39 additions and 63 deletions.
102 changes: 39 additions & 63 deletions src/main/java/edu/group5/app/model/donation/Donation.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,49 @@

/**
* Represents a verified donation made by a user to an organization.
* @param donationId - the unique ID of this donation
* @param userId - the ID of the user making the donation
* @param organizationId - the ID of the organization receiving the donation
* @param amount - the donation amount
* @param date - the timestamp when the donation was made
* @param paymentMethod - the payment method used
*/
public class Donation {
private final int donationId;
private final int userId;
private final int organizationId;
private final BigDecimal amount;
private final Timestamp date;
private final String paymentMethod;
public record Donation(
int donationId,
int userId,
int organizationId,
BigDecimal amount,
Timestamp date,
String paymentMethod) {

/**
* Constructs a new Donation.
* Constructor with throws.
*
* @param donationId - the unique ID of this donation
* @param userId - the ID of the user making the donation
* @param organizationId - the ID of the organization receiving the donation
* @param amount - the donation amount
* @param date - the timestamp when the donation was made
* @param paymentMethod - the payment method used
* @param donationId - throws if donationID is negative or 0.
* @param userId - throws if userID is negative or 0.
* @param organizationId - throws if organizationID is negative or 0.
* @param amount - throws if amount is negative or null.
* @param date - throws if date is null.
* @param paymentMethod - throws if payment is null or blank.
*/
public Donation(int donationId, int userId, int organizationId, BigDecimal amount, Timestamp date, String paymentMethod) {
this.donationId = donationId;
this.userId = userId;
this.organizationId = organizationId;
this.amount = amount;
this.date = date;
this.paymentMethod = paymentMethod;
}

/**
* @return the donation ID
*/
public int getDonationId(){
return donationId;
}

/**
* @return the user ID of the donator
*/
public int getUserId(){
return userId;
}

/**
* @return the organization ID that receives the donation
*/
public int getOrganizationId() {
return organizationId;
}

/**
* @return the donated amount
*/
public BigDecimal getAmount() {
return amount;
}

/**
* @return the timestamp of the donation
*/
public Timestamp getDate() {
return date;
}

/**
* @return the payment method used
*/
public String getPaymentMethod() {
return paymentMethod;
public Donation {
if (donationId <= 0) {
throw new IllegalArgumentException("Donation ID must be positive");
}
if (userId <= 0) {
throw new IllegalArgumentException("User ID must be positive");
}
if (organizationId <= 0) {
throw new IllegalArgumentException("Organization ID must be positive");
}
if (amount == null || amount.compareTo(BigDecimal.ZERO) <= 0) {
throw new IllegalArgumentException("Amount must be positive and not null");
}
if (date == null) {
throw new IllegalArgumentException("Date must not be null");
}
if (paymentMethod == null || paymentMethod.isBlank()) {
throw new IllegalArgumentException("Payment method must not be empty");
}
}
}

0 comments on commit d608890

Please sign in to comment.