diff options
author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-02-26 13:33:03 -0500 |
---|---|---|
committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-02-26 13:33:03 -0500 |
commit | 0d1c11aa2738a622fc2ee6ecb23aef214c9520db (patch) | |
tree | d52611457be95e41c6e47f3ab02877a56fffbe9d /ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java | |
parent | 380b0ca3f3ebd1564d2e961a67e0fc8a8dac80f2 (diff) | |
download | JellySolutions-0d1c11aa2738a622fc2ee6ecb23aef214c9520db.tar.gz JellySolutions-0d1c11aa2738a622fc2ee6ecb23aef214c9520db.tar.bz2 JellySolutions-0d1c11aa2738a622fc2ee6ecb23aef214c9520db.zip |
Implemented createUser in the controller and modified logic in the UserFileDAO to check for conflict
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java')
-rw-r--r-- | ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java | 16 |
1 files changed, 7 insertions, 9 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); } |