diff options
author | Akash Keshav <112591754+domesticchores@users.noreply.github.com> | 2025-02-16 14:44:55 -0500 |
---|---|---|
committer | Akash Keshav <112591754+domesticchores@users.noreply.github.com> | 2025-02-16 14:44:55 -0500 |
commit | c5455e51a289a7d1ccdf42fe3b145aa1a3135241 (patch) | |
tree | 93dc8fccd175bbd6b5c125b33774dfb60b1d781b /ufund-api/src/main/java | |
parent | 5e073d64d3d364c090f21c5e34ae273955009a1a (diff) | |
download | JellySolutions-c5455e51a289a7d1ccdf42fe3b145aa1a3135241.tar.gz JellySolutions-c5455e51a289a7d1ccdf42fe3b145aa1a3135241.tar.bz2 JellySolutions-c5455e51a289a7d1ccdf42fe3b145aa1a3135241.zip |
added searchNeeds() function to CupboardController -ak
Diffstat (limited to 'ufund-api/src/main/java')
-rw-r--r-- | ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java index 106b2e0..9c9e67a 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java @@ -30,9 +30,28 @@ public class CupboardController { return cupboard.getNeeds(); } + /** + * 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 Need searchNeeds(@RequestParam String name) { - return cupboard.findNeeds(name); + public ResponseEntity<Need[]> searchNeeds(@RequestParam String name) { + LOG.info("GET /need/?name="+name); + + try { + Need[] needArray = cupboard.findNeeds(name); + return new ResponseEntity<Need[]>(needArray,HttpStatus.OK); + } catch (IOException e) { + LOG.log(Level.SEVERE,e.getLocalizedMessage()); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } } @GetMapping("/{id}") |