aboutsummaryrefslogtreecommitdiff
path: root/ufund-api
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-04-07 16:49:21 -0400
committersowgro <tpoke.ferrari@gmail.com>2025-04-07 16:49:21 -0400
commit8b64b8bd43f987b924d74d0ea597b7b606ca9357 (patch)
treec8c3229c54955a4a037b0ce0a016221e8784af42 /ufund-api
parentbb4e0e55fee7ec8f34c36e6299301d612a0de2ce (diff)
parent7635188ed6182a72facd8ab3299f13c7217a8abd (diff)
downloadJellySolutions-8b64b8bd43f987b924d74d0ea597b7b606ca9357.tar.gz
JellySolutions-8b64b8bd43f987b924d74d0ea597b7b606ca9357.tar.bz2
JellySolutions-8b64b8bd43f987b924d74d0ea597b7b606ca9357.zip
Merge branch 'main' into light-mode
# Conflicts: # ufund-ui/src/styles.css
Diffstat (limited to 'ufund-api')
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java10
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java4
2 files changed, 13 insertions, 1 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java
index 5452c81..889abc5 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java
@@ -58,7 +58,15 @@ public class CupboardController {
String name = (String) params.get("name");
String image = (String) params.get("image");
String location = (String) params.get("location");
- double maxGoal = ((Number) params.get("maxGoal")).doubleValue();
+
+ double maxGoal;
+ try {
+ maxGoal = ((Number) params.get("maxGoal")).doubleValue();
+ } catch (NullPointerException ex) {
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>("Required fields cannot be blank", HttpStatus.BAD_REQUEST);
+ }
+
boolean urgent = (Boolean) params.get("urgent");
String description = (String) params.get("description");
Need.GoalType goalType = GoalType.valueOf((String) params.get("type"));
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 859194a..33b272b 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
@@ -41,6 +41,8 @@ public class CupboardService {
throw new IllegalArgumentException("Max Goal must be greater than zero");
} else if (goalType.equals(Need.GoalType.PHYSICAL) && maxGoal % 1 != 0) {
throw new IllegalArgumentException("Cannot have non whole number value for physical goal");
+ } else if (name == null || name.isEmpty()) {
+ throw new IllegalArgumentException("Required fields cannot be blank");
}
for (Need searchNeed : cupboardDAO.getNeeds()) {
@@ -103,6 +105,8 @@ public class CupboardService {
throw new IllegalArgumentException("Goal must be greater than 0");
} else if (need.getType().equals(Need.GoalType.PHYSICAL) && need.getMaxGoal() % 1 != 0) {
throw new IllegalArgumentException("Cannot have non whole number value for physical goal");
+ } else if (need.getName() == null || need.getName().isEmpty()) {
+ throw new IllegalArgumentException("Required fields cannot be blank");
}
return cupboardDAO.updateNeed(need);
}