getAllDonations() {
/**
* Adds a new donation to the repository
*
- * 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.
+ * 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
+ * {@code false} if a donation with the same ID already exists
*/
@Override
public boolean addContent(Donation donation) {
if (donation == null) {
throw new IllegalArgumentException("Donation cannot be null");
}
- if (content.containsKey(donation.donationId())){
- return false;
+ if (content.containsKey(donation.donationId())) {
+ return false;
}
this.content.put(donation.donationId(), donation);
return true;
@@ -116,12 +136,12 @@ public boolean addContent(Donation donation) {
* Returns all donations sorted by date (ascending).
*
*
- * The returned map preserves the sorted order.
+ * The returned map preserves the sorted order.
*
*
* @return a new {@link HashMap} containing the donations sorted by date
*/
- public HashMap sortByDate(){
+ public HashMap sortByDate() {
return content.entrySet().stream()
.sorted(Map.Entry.comparingByValue(
Comparator.comparing(Donation::date)))
@@ -136,7 +156,7 @@ public HashMap sortByDate(){
* Returns all donations sorted by amount (ascending).
*
*
- * The returned map preserves the sorted order from lowest to highest amount.
+ * The returned map preserves the sorted order from lowest to highest amount.
*
*
* @return a new {@link HashMap} containing the donations sorted by amount.
@@ -149,12 +169,12 @@ public HashMap sortByAmount() {
Map.Entry::getKey,
Map.Entry::getValue,
(e1, e2) -> e1,
- LinkedHashMap::new
- ));
+ LinkedHashMap::new));
}
/**
* Returns all donations associated with a specific organization.
+ *
* @param orgNumber the organization ID to filter by
* @return a map containing all donations that belong to the given organization
* @throws IllegalArgumentException if the orgNumber is not positive
@@ -165,17 +185,17 @@ public HashMap filterByOrganization(int orgNumber) {
}
return content.entrySet()
.stream()
- .filter(entry -> entry.getValue().organizationId() == orgNumber)
+ .filter(entry -> entry.getValue().organizationId() == orgNumber)
.collect(Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(e1, e2) -> e1,
- LinkedHashMap::new
- ));
+ LinkedHashMap::new));
}
/**
* Returns all donations made by a specific user.
+ *
* @param userId the user ID to filter by
* @return a map containing all donations that belong to the given user
* @throws IllegalArgumentException if the userId is not positive
@@ -190,7 +210,6 @@ public HashMap filterByUser(int userId) {
Map.Entry::getKey,
Map.Entry::getValue,
(e1, e2) -> e1,
- LinkedHashMap::new
- ));
+ LinkedHashMap::new));
}
}
diff --git a/src/main/java/edu/group5/app/model/organization/OrganizationService.java b/src/main/java/edu/group5/app/model/organization/OrganizationService.java
new file mode 100644
index 0000000..c5979f5
--- /dev/null
+++ b/src/main/java/edu/group5/app/model/organization/OrganizationService.java
@@ -0,0 +1,58 @@
+package edu.group5.app.model.organization;
+
+import java.util.Map;
+
+/**
+ * Service class for managing organization-related operations.
+ * It interacts with the OrganizationRepository to retrieve organization information
+ * and contains business logic associated with organization management.
+ */
+public class OrganizationService {
+ private OrganizationRepository organizationRepository;
+
+ /**
+ * Constructs an OrganizationService with the given OrganizationRepository.
+ * @param organizationRepository the OrganizationRepository to use for managing organization data; must not be null
+ * @throws IllegalArgumentException if organizationRepository is null
+ */
+ public OrganizationService(OrganizationRepository organizationRepository) {
+ if (organizationRepository == null) {
+ throw new IllegalArgumentException("OrganizationRepository cannot be null");
+ }
+ this.organizationRepository = organizationRepository;
+ }
+
+ /**
+ * Getter for the OrganizationRepository used by this service.
+ * @return the OrganizationRepository instance used by this service
+ */
+ public OrganizationRepository getOrganizationRepository() {
+ return this.organizationRepository;
+ }
+
+ /**
+ * Retrieves all trusted organizations.
+ * @return a map of trusted organizations by organization number
+ */
+ public Map getTrustedOrganizations() {
+ return organizationRepository.getTrustedOrganizations();
+ }
+
+ /**
+ * Finds an organization by its organization number.
+ * @param orgNumber the organization number to find
+ * @return the Organization if found, null otherwise
+ */
+ public Organization findByOrgNumber(int orgNumber) {
+ return organizationRepository.findByOrgNumber(orgNumber);
+ }
+
+ /**
+ * Finds an organization by its name.
+ * @param name the name of the organization
+ * @return the Organization if found, null otherwise
+ */
+ public Organization findByOrgName(String name) {
+ return organizationRepository.findByOrgName(name);
+ }
+}
diff --git a/src/main/java/edu/group5/app/model/user/UserRepository.java b/src/main/java/edu/group5/app/model/user/UserRepository.java
index 692126f..193f433 100644
--- a/src/main/java/edu/group5/app/model/user/UserRepository.java
+++ b/src/main/java/edu/group5/app/model/user/UserRepository.java
@@ -6,11 +6,13 @@
import edu.group5.app.model.DBRepository;
-public class UserRepository extends DBRepository{
+public class UserRepository extends DBRepository {
public final static String ROLE_CUSTOMER = "Customer";
+
/**
* Constructs UserRepository using Hashmap,
* and extends the content from DBRepository.
+ *
* @param content the underlying map used to store users,
* where the key represents the user ID
*/
@@ -20,7 +22,7 @@ public UserRepository(List