aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-api/src/main/java')
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java30
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java4
2 files changed, 28 insertions, 6 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 d6b71fd..1fdd435 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
@@ -51,14 +51,36 @@ 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 void updateNeed(@RequestBody Need need) {
- cupboard.updateNeed(need);
+ public ResponseEntity<Need> 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}")
- public void deleteNeed(@PathVariable int id) {
- cupboard.removeNeed(id);
+ public ResponseEntity<Need> 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);
+ }
}
}
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 {