diff options
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi')
| -rw-r--r-- | ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java | 15 | 
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);  | 
