diff --git a/src/main/java/edu/group5/app/model/donation/DonationRepository.java b/src/main/java/edu/group5/app/model/donation/DonationRepository.java index f179b01..596ea60 100644 --- a/src/main/java/edu/group5/app/model/donation/DonationRepository.java +++ b/src/main/java/edu/group5/app/model/donation/DonationRepository.java @@ -1,4 +1,110 @@ package edu.group5.app.model.donation; -public class DonationRepository { +import edu.group5.app.model.DBRepository; + +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Repository class for Donation. + * + *
+ * Extends {@link DBRepository} and manages Donation entities. + *
+ */ +public class DonationRepository extends DBRepository+ * The donation is stored using its {@code donationId} as the key. + * If a donation with the same ID already exists, the donation + * will not be added. + *
+ * + * @param donation the donation to add + * @return {@code true} if the donation was successfully added, and + * {@code false} if a donation with the same ID already exists + */ + public boolean addDonation(Donation donation) { + if(content.containsKey(donation.donationId())){ + return false; + } + content.put(donation.donationId(), donation); + return true; + } + + /** + * Returns all donations sorted by date (ascending). + * + *+ * The returned map preserves the sorted order. + *
+ * + * @return a new {@link HashMap} containing the donations sorted by date + */ + public HashMap+ * The returned map preserves the sorted order from lowest to highest amount. + *
+ * + * @return a new {@link HashMap} containing the donations sorted by amount. + */ + public HashMap