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/controller/UserController.java | 16 | ||||
| -rw-r--r-- | ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java | 12 | 
2 files changed, 15 insertions, 13 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java index 223963d..bf3f7a1 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java @@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping;  import org.springframework.web.bind.annotation.RequestParam;  import org.springframework.web.bind.annotation.RestController; -import com.ufund.api.ufundapi.model.Need; +import com.ufund.api.ufundapi.model.User;  import com.ufund.api.ufundapi.persistence.UserDAO;  @RestController @@ -41,16 +41,14 @@ public class UserController {       * @return OK response and the need if it was successful, INTERNAL_SERVER_ERROR otherwise       */      @PostMapping("") -    public ResponseEntity<User> createUser(@RequestBody Need need) { +    public ResponseEntity<User> createUser(@RequestBody User user) {          try { -            if (need.getMaxGoal() <= 0) { -                return new ResponseEntity<>(HttpStatus.BAD_REQUEST); -            } -            if (need.getMaxGoal() < need.getCurrent()) { -                return new ResponseEntity<>(HttpStatus.BAD_REQUEST); +            if (UserDAO.createUser(user) != null) { +                return new ResponseEntity<>(user, HttpStatus.OK); +            } else { +                return new ResponseEntity<>(HttpStatus.CONFLICT);              } -            UserDAO.createNeed(need); -            return new ResponseEntity<>(need, HttpStatus.OK); +                      } catch (IOException ex) {              return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);          } diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java index ebfa9f2..0f30824 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java @@ -95,10 +95,14 @@ public class UserFileDAO implements UserDAO {      @Override      public User createUser(User user) throws IOException {          synchronized (users) { -            User newUser = new User(user); -            users.put(newUser.getName(), newUser); -            save(); -            return newUser; +            if (getUser(user.getName()) != null) { +                User newUser = new User(user); +                users.put(newUser.getName(), newUser); +                save(); +                return newUser; +            } else { +                return null; +            }          }      }  | 
