diff options
Diffstat (limited to 'ufund-api/src')
-rw-r--r-- | ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java | 94 |
1 files changed, 36 insertions, 58 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 bf3f7a1..ae75179 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 @@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; 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.User; @@ -35,10 +34,10 @@ public class UserController { } /** - * Creates a Need with the provided object + * Creates a User with the provided object * - * @param need The need to create - * @return OK response and the need if it was successful, INTERNAL_SERVER_ERROR otherwise + * @param user The user to create + * @return OK response and the user if it was successful, INTERNAL_SERVER_ERROR otherwise */ @PostMapping("") public ResponseEntity<User> createUser(@RequestBody User user) { @@ -55,68 +54,44 @@ public class UserController { } /** - * Responds to the GET request for all {@linkplain Need needs} + * Responds to the GET request for all {@linkplain User user} * - * @return ResponseEntity with array of {@link Need needs} objects (may be empty) + * @return ResponseEntity with array of {@link User user} objects (may be empty) * and * HTTP status of OK<br> * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise */ @GetMapping("") - public ResponseEntity<Need[]> getNeeds() { - LOG.info("GET /needs"); + public ResponseEntity<User[]> getUseers() { + LOG.info("GET /users"); try { - Need[] needs = UserDAO.getNeeds(); - return new ResponseEntity<>(needs, HttpStatus.OK); + User[] users = UserDAO.getUsers(); + return new ResponseEntity<>(users, HttpStatus.OK); } catch (IOException e) { LOG.log(Level.SEVERE, e.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } - /** - * Responds to the GET request for all {@linkplain Need need} whose name contains - * the text in name - * - * @param name The name parameter which contains the text used to find the {@link Need need} - * - * @return ResponseEntity with array of {@link Need need} objects (may be empty) and - * HTTP status of OK<br> - * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise - * <p> - */ - @GetMapping("/") - public ResponseEntity<Need[]> searchNeeds(@RequestParam String name) { - LOG.info("GET /need/?name="+name); - - try { - Need[] needArray = UserDAO.findNeeds(name); - return new ResponseEntity<>(needArray, HttpStatus.OK); - } catch (IOException e) { - LOG.log(Level.SEVERE,e.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); - } - } - /** - * Responds to the GET request for a {@linkplain Need need} for the given id + * Responds to the GET request for a {@linkplain User user} for the given id * - * @param id The id used to locate the {@link Need need} + * @param id The id used to locate the {@link User user} * - * @return ResponseEntity with {@link Need need} object and HTTP status of OK if + * @return ResponseEntity with {@link User user} object and HTTP status of OK if * found<br> * ResponseEntity with HTTP status of NOT_FOUND if not found<br> * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise */ - @GetMapping("/{id}") - public ResponseEntity<Need> getNeed(@PathVariable int id) { - LOG.log(Level.INFO, "GET /need/{0}", id); + @GetMapping("/{name}") + public ResponseEntity<User> getUser(@PathVariable String name) { + LOG.log(Level.INFO, "GET /user/{0}", name); try { - Need need = UserDAO.getNeed(id); - if (need != null) { - return new ResponseEntity<>(need, HttpStatus.OK); + User user = UserDAO.getUser(name); + if (user != null) { + return new ResponseEntity<>(user, HttpStatus.OK); } else { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } @@ -129,33 +104,36 @@ public class UserController { } /** - * Updates a Need with the provided one - * - * @param need The need to update - * @return OK response and the need if it was successful, or INTERNAL_SERVER_ERROR if there was an issue + * Updates a User with the provided one + * + * @param user The user to update + * @return OK response and the user if it was successful, or INTERNAL_SERVER_ERROR if there was an issue */ - @PutMapping("") - public ResponseEntity<Need> updateNeed(@RequestBody Need need) { + public ResponseEntity<User> updateUser(@RequestBody User user, String string) { try { - need = UserDAO.updateNeed(need); - return new ResponseEntity<>(need, HttpStatus.OK); + user = UserDAO.updateUser(user, string); + if (user != null) { + return new ResponseEntity<>(user, HttpStatus.OK); + } else { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + } catch (IOException e) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } /** - * Deletes a single need from the cupboard using the Need's id + * Deletes a user with the desired name * - * @param id The need's ID - * @return OK if the need was deleted, NOT_FOUND if the need was not found, or INTERNAL_SERVER_ERROR if an error occurred + * @param name The name of the user + * @return OK if the user was deleted, NOT_FOUND if the user was not found, or INTERNAL_SERVER_ERROR if an error occurred */ - @DeleteMapping("/{id}") - public ResponseEntity<Need> deleteNeed(@PathVariable int id) { + @DeleteMapping("/{name}") + public ResponseEntity<User> deleteUser(@PathVariable String name) { try { - if (UserDAO.getNeed(id) != null) { - UserDAO.deleteNeed(id); + if (UserDAO.deleteUser(name)) { return new ResponseEntity<>(HttpStatus.OK); } else { return new ResponseEntity<>(HttpStatus.NOT_FOUND); |