diff options
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api')
| -rw-r--r-- | ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java | 22 | 
1 files changed, 10 insertions, 12 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 6dd120c..78f8f85 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 @@ -29,22 +29,20 @@ public class CupboardService {       * @throws DuplicateKeyException If there already exists a need with the same name       */      public Need createNeed(String name, double maxGoal, Need.GoalType goalType) throws IOException, DuplicateKeyException { -         -        Need need = new Need(name, goalType, maxGoal); -        if (need.getMaxGoal() <= 0) { +        if (maxGoal <= 0) {              throw new IllegalArgumentException("Max Goal must be greater than zero"); -        } else { -            if (cupboardDAO.getNeeds().length > 0) { -                for (Need searchNeed : cupboardDAO.getNeeds()) { -                    if (need.getName().equalsIgnoreCase(searchNeed.getName())) { -                        throw new DuplicateKeyException("Duplicate names are not allowed"); -                    } -                } +        } + +        for (Need searchNeed : cupboardDAO.getNeeds()) { +            if (searchNeed.getName().equalsIgnoreCase(name)) { +                throw new DuplicateKeyException("Duplicate names are not allowed");              } -            return cupboardDAO.addNeed(need);          } -         + +        Need need = new Need(name, goalType, maxGoal); +        return cupboardDAO.addNeed(need); +      }      /**  | 
