diff options
author | Tyler Ferrari <69283684+Sowgro@users.noreply.github.com> | 2025-02-16 14:52:21 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-16 14:52:21 -0500 |
commit | 61663465d01fcec6d259ecf393fae2668823a527 (patch) | |
tree | 130054861c1cd678d32dff706057e833f2495da2 /ufund-api/src/main/java | |
parent | 865d3d0db661223e446391eb52b824df4858adb3 (diff) | |
parent | 02375260e51380499f3c7e2e5abbabf606fdd0c8 (diff) | |
download | JellySolutions-61663465d01fcec6d259ecf393fae2668823a527.tar.gz JellySolutions-61663465d01fcec6d259ecf393fae2668823a527.tar.bz2 JellySolutions-61663465d01fcec6d259ecf393fae2668823a527.zip |
Merge pull request #2 from RIT-SWEN-261-02/get-cupboard
Merge get-cupboard to main
Diffstat (limited to 'ufund-api/src/main/java')
-rw-r--r-- | ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java | 22 |
1 files changed, 18 insertions, 4 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 1fdd435..8af3fee 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 @@ -11,13 +11,11 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.io.IOException; -import java.util.ArrayList; @RestController @RequestMapping("cupboard") public class CupboardController { private static final Logger LOG = Logger.getLogger(CupboardController.class.getName()); - private ArrayList<Need> needs; private Cupboard cupboard; /** @@ -36,9 +34,25 @@ public class CupboardController { } } + /** + * Responds to the GET request for all {@linkplain Need needs} + * + * @return ResponseEntity with array of {@link Need needs} objects (may be empty) + * and + * HTTP status of OK<br> + * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise + */ @GetMapping("") - public Need[] getNeeds() { - return cupboard.getNeeds(); + public ResponseEntity<Need[]> getNeeds() { + LOG.info("GET /needs"); + + try { + Need[] needs = cupboard.getNeeds(); + return new ResponseEntity<>(needs, HttpStatus.OK); + } catch (IOException e) { + LOG.log(Level.SEVERE, e.getLocalizedMessage()); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } } @GetMapping("/") |