diff options
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api')
| -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}")  | 
