From 02375260e51380499f3c7e2e5abbabf606fdd0c8 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Sun, 16 Feb 2025 14:14:06 -0500 Subject: Implemented getNeeds method --- .../ufundapi/controller/CupboardController.java | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'ufund-api/src/main/java') 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..255eba0 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 needs; private Cupboard cupboard; @PostMapping("") @@ -25,9 +23,25 @@ public class CupboardController { cupboard.createNeed(need); } + /** + * 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
+ * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise + */ @GetMapping("") - public Need[] getNeeds() { - return cupboard.getNeeds(); + public ResponseEntity 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("/") -- cgit v1.2.3 From 6c32da25ccbcd0568f7b34cd81565609625435ef Mon Sep 17 00:00:00 2001 From: beanplebs Date: Sun, 16 Feb 2025 14:14:20 -0500 Subject: updateNeed Controller and Cupboard functionality --- .../com/ufund/api/ufundapi/controller/CupboardController.java | 10 ++++++++-- .../src/main/java/com/ufund/api/ufundapi/model/Cupboard.java | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'ufund-api/src/main/java') 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..0de3403 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 @@ -41,8 +41,14 @@ public class CupboardController { } @PutMapping("") - public void updateNeed(@RequestBody Need need) { - cupboard.updateNeed(need); + public ResponseEntity updateNeed(@RequestBody Need need) { + try { + need = cupboard.updateNeed(need); + return new ResponseEntity<>(need, HttpStatus.OK); + } catch (IOException e) { + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } @DeleteMapping("/{id}") diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java index a626561..0ce015c 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java @@ -23,8 +23,8 @@ public class Cupboard { return dao.findNeeds(name); } - public void updateNeed(Need need) throws IOException { - dao.updateNeed(need); + public Need updateNeed(Need need) throws IOException { + return dao.updateNeed(need); } public void removeNeed(int id) throws IOException { -- cgit v1.2.3 From 734128698a92a60c73d00d6aef4e78270c58283a Mon Sep 17 00:00:00 2001 From: sowgro Date: Sun, 16 Feb 2025 14:18:30 -0500 Subject: Complete createNeed() --- .../ufund/api/ufundapi/controller/CupboardController.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'ufund-api/src/main/java') 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..d6b71fd 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 @@ -20,9 +20,20 @@ public class CupboardController { private ArrayList needs; private Cupboard cupboard; + /** + * Creates a Need with the provided object + * + * @param need The need to create + * @return OK response and the need if it was successful, INTERNAL_SERVER_ERROR otherwise + */ @PostMapping("") - public void createNeed(@RequestBody Need need) { - cupboard.createNeed(need); + public ResponseEntity createNeed(@RequestBody Need need) { + try { + cupboard.createNeed(need); + return new ResponseEntity<>(need, HttpStatus.OK); + } catch (IOException ex) { + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } } @GetMapping("") -- cgit v1.2.3 From aacd3e7daa67d8fa30b4d0625b35eadab19e8730 Mon Sep 17 00:00:00 2001 From: Angelina Zhen Date: Sun, 16 Feb 2025 14:35:21 -0500 Subject: Completed Delete Need --- .../ufund/api/ufundapi/controller/CupboardController.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'ufund-api/src/main/java') 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..8fc1d5a 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 @@ -46,8 +46,17 @@ public class CupboardController { } @DeleteMapping("/{id}") - public void deleteNeed(@PathVariable int id) { - cupboard.removeNeed(id); + public ResponseEntity deleteNeed(@PathVariable int id) { + try { + if (cupboard.getNeed(id) != null) { + cupboard.removeNeed(id); + return new ResponseEntity<>(HttpStatus.OK); + } else { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + } catch (IOException e) { + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } } } -- cgit v1.2.3 From 2f4119f80731b62fce2eeff5f1c1dc77ae53c180 Mon Sep 17 00:00:00 2001 From: benal01 Date: Sun, 16 Feb 2025 14:41:34 -0500 Subject: javadoc --- .../com/ufund/api/ufundapi/controller/CupboardController.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'ufund-api/src/main/java') 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 0de3403..8d394c1 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 @@ -40,6 +40,14 @@ public class CupboardController { return cupboard.getNeed(id); } + + /** + * Updates a Need with the provided one + * + * @param need The need to update + * @return OK response and the need if it was successful, or INTERNAL_SERVER_ERROR if there was an issue + */ + @PutMapping("") public ResponseEntity updateNeed(@RequestBody Need need) { try { @@ -48,7 +56,6 @@ public class CupboardController { } catch (IOException e) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - } @DeleteMapping("/{id}") -- cgit v1.2.3 From c5455e51a289a7d1ccdf42fe3b145aa1a3135241 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Sun, 16 Feb 2025 14:44:55 -0500 Subject: added searchNeeds() function to CupboardController -ak --- .../ufundapi/controller/CupboardController.java | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'ufund-api/src/main/java') 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
+ * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise + *

+ */ @GetMapping("/") - public Need searchNeeds(@RequestParam String name) { - return cupboard.findNeeds(name); + public ResponseEntity searchNeeds(@RequestParam String name) { + LOG.info("GET /need/?name="+name); + + try { + Need[] needArray = cupboard.findNeeds(name); + return new ResponseEntity(needArray,HttpStatus.OK); + } catch (IOException e) { + LOG.log(Level.SEVERE,e.getLocalizedMessage()); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } } @GetMapping("/{id}") -- cgit v1.2.3 From 82479c054fbbd7fca52e2cabd7b646a4455d7e66 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Sun, 16 Feb 2025 14:54:43 -0500 Subject: Manually edited getNeed in main --- .../ufundapi/controller/CupboardController.java | 29 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'ufund-api/src/main/java') 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
+ * ResponseEntity with HTTP status of NOT_FOUND if not found
+ * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise + */ @GetMapping("/{id}") - public Need getNeed(@PathVariable int id) { - return cupboard.getNeed(id); - } + public ResponseEntity 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 -- cgit v1.2.3