From c5455e51a289a7d1ccdf42fe3b145aa1a3135241 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Sun, 16 Feb 2025 14:44:55 -0500 Subject: added searchNeeds() function to CupboardController -ak --- .../ufundapi/controller/CupboardController.java | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java') 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
+ * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise + *

+ */ @GetMapping("/") - public Need searchNeeds(@RequestParam String name) { - return cupboard.findNeeds(name); + public ResponseEntity searchNeeds(@RequestParam String name) { + LOG.info("GET /need/?name="+name); + + try { + Need[] needArray = cupboard.findNeeds(name); + return new ResponseEntity(needArray,HttpStatus.OK); + } catch (IOException e) { + LOG.log(Level.SEVERE,e.getLocalizedMessage()); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } } @GetMapping("/{id}") -- cgit v1.2.3