diff options
author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-02-16 14:54:43 -0500 |
---|---|---|
committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-02-16 14:54:43 -0500 |
commit | 82479c054fbbd7fca52e2cabd7b646a4455d7e66 (patch) | |
tree | 44751a6d48c63f7c533e38fb7ec1cac84e454c26 /ufund-api/src/main/java/com/ufund/api | |
parent | 4d21f33fc117962ced59ca8a84b93df23eb37a6e (diff) | |
download | JellySolutions-82479c054fbbd7fca52e2cabd7b646a4455d7e66.tar.gz JellySolutions-82479c054fbbd7fca52e2cabd7b646a4455d7e66.tar.bz2 JellySolutions-82479c054fbbd7fca52e2cabd7b646a4455d7e66.zip |
Manually edited getNeed in main
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 | 29 |
1 files changed, 26 insertions, 3 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 3b99117..dbd4394 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 @@ -79,11 +79,34 @@ public class CupboardController { } } + /** + * Responds to the GET request for a {@linkplain Need need} for the given id + * + * @param id The id used to locate the {@link Need need} + * + * @return ResponseEntity with {@link Need need} 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 Need getNeed(@PathVariable int id) { - return cupboard.getNeed(id); - } + public ResponseEntity<Need> getNeed(@PathVariable int id) { + LOG.log(Level.INFO, "GET /need/{0}", id); + + try { + Need need = cupboard.getNeed(id); + if (need != null) { + return new ResponseEntity<>(need, HttpStatus.OK); + } else { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + } catch (IOException e) { + LOG.log(Level.SEVERE, e.getLocalizedMessage()); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } /** * Updates a Need with the provided one |