From 0d1c11aa2738a622fc2ee6ecb23aef214c9520db Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Wed, 26 Feb 2025 13:33:03 -0500 Subject: Implemented createUser in the controller and modified logic in the UserFileDAO to check for conflict --- .../ufund/api/ufundapi/controller/UserController.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java') 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 createUser(@RequestBody Need need) { + public ResponseEntity 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); } -- cgit v1.2.3