aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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