aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/main/java/com
diff options
context:
space:
mode:
authorGunther6070 <haydenhartman10@yahoo.com>2025-03-15 23:18:54 -0400
committerGunther6070 <haydenhartman10@yahoo.com>2025-03-15 23:18:54 -0400
commit4ac7711c4d9dd3275ae4037f843347e4fbcb1f2a (patch)
tree8e48e0646910240e720af87b1b720327380e5e2b /ufund-api/src/main/java/com
parent4f2f1d0944b15ced834255cd2934516a953b97a5 (diff)
downloadJellySolutions-4ac7711c4d9dd3275ae4037f843347e4fbcb1f2a.tar.gz
JellySolutions-4ac7711c4d9dd3275ae4037f843347e4fbcb1f2a.tar.bz2
JellySolutions-4ac7711c4d9dd3275ae4037f843347e4fbcb1f2a.zip
Added additional check to createNeed method
Diffstat (limited to 'ufund-api/src/main/java/com')
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java15
1 files changed, 9 insertions, 6 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java
index c8609ab..6dd120c 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java
@@ -3,10 +3,11 @@ package com.ufund.api.ufundapi.service;
import java.io.IOException;
import java.util.Arrays;
-import com.ufund.api.ufundapi.model.Need;
-import com.ufund.api.ufundapi.persistence.CupboardDAO;
import org.springframework.stereotype.Component;
+
import com.ufund.api.ufundapi.DuplicateKeyException;
+import com.ufund.api.ufundapi.model.Need;
+import com.ufund.api.ufundapi.persistence.CupboardDAO;
@Component
public class CupboardService {
@@ -27,16 +28,18 @@ public class CupboardService {
* @throws IOException Thrown if there was any issue saving the data
* @throws DuplicateKeyException If there already exists a need with the same name
*/
- public Need createNeed(String name, int maxGoal, Need.GoalType goalType) throws IOException, DuplicateKeyException {
+ public Need createNeed(String name, double maxGoal, Need.GoalType goalType) throws IOException, DuplicateKeyException {
Need need = new Need(name, goalType, maxGoal);
if (need.getMaxGoal() <= 0) {
throw new IllegalArgumentException("Max Goal must be greater than zero");
} else {
- for (Need searchNeed : cupboardDAO.getNeeds()) {
- if (need.getName().equalsIgnoreCase(searchNeed.getName())) {
- throw new DuplicateKeyException("Duplicate names are not allowed");
+ if (cupboardDAO.getNeeds().length > 0) {
+ for (Need searchNeed : cupboardDAO.getNeeds()) {
+ if (need.getName().equalsIgnoreCase(searchNeed.getName())) {
+ throw new DuplicateKeyException("Duplicate names are not allowed");
+ }
}
}
return cupboardDAO.addNeed(need);