aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src
diff options
context:
space:
mode:
authorGunther6070 <haydenhartman10@yahoo.com>2025-02-16 14:54:43 -0500
committerGunther6070 <haydenhartman10@yahoo.com>2025-02-16 14:54:43 -0500
commit82479c054fbbd7fca52e2cabd7b646a4455d7e66 (patch)
tree44751a6d48c63f7c533e38fb7ec1cac84e454c26 /ufund-api/src
parent4d21f33fc117962ced59ca8a84b93df23eb37a6e (diff)
downloadJellySolutions-82479c054fbbd7fca52e2cabd7b646a4455d7e66.tar.gz
JellySolutions-82479c054fbbd7fca52e2cabd7b646a4455d7e66.tar.bz2
JellySolutions-82479c054fbbd7fca52e2cabd7b646a4455d7e66.zip
Manually edited getNeed in main
Diffstat (limited to 'ufund-api/src')
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java29
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