aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java
diff options
context:
space:
mode:
authorGunther6070 <haydenhartman10@yahoo.com>2025-03-07 15:43:17 -0500
committerGunther6070 <haydenhartman10@yahoo.com>2025-03-07 15:43:17 -0500
commit94869200a0d2f80f71fcd0efd4f82c0138b5440d (patch)
tree52eff6463b3cec7c3d6bda18e186f9272f528a2c /ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java
parentfa1f1140b1e13d495c8e06e80928efb333917d31 (diff)
parentcaaf278d1fa69fef69c210edb337fa54102d2737 (diff)
downloadJellySolutions-94869200a0d2f80f71fcd0efd4f82c0138b5440d.tar.gz
JellySolutions-94869200a0d2f80f71fcd0efd4f82c0138b5440d.tar.bz2
JellySolutions-94869200a0d2f80f71fcd0efd4f82c0138b5440d.zip
Merge branch 'api-auth' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b into api-auth
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java')
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java13
1 files changed, 8 insertions, 5 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 dfcb8a3..7773028 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
@@ -1,6 +1,7 @@
package com.ufund.api.ufundapi.controller;
import java.io.IOException;
+import java.security.InvalidParameterException;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -20,7 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
import com.ufund.api.ufundapi.model.Need;
import com.ufund.api.ufundapi.model.Need.GoalType;
import com.ufund.api.ufundapi.service.CupboardService;
-import com.ufund.api.ufundapi.service.CupboardService.DuplicateKeyException;
+import com.ufund.api.ufundapi.DuplicateKeyException;
@RestController
@RequestMapping("cupboard")
@@ -50,7 +51,7 @@ public class CupboardController {
public ResponseEntity<Need> createNeed(@RequestBody Map<String, String> params) {
String name = params.get("name");
int maxGoal = Integer.parseInt(params.get("maxGoal"));
- Need.GoalType goalType = GoalType.valueOf(params.get("maxGoal"));
+ Need.GoalType goalType = GoalType.valueOf(params.get("goalType"));
try {
Need need = cupboardService.createNeed(name, maxGoal, goalType);
@@ -141,15 +142,17 @@ public class CupboardController {
* @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<Need> updateNeed(@RequestBody Need need) {
+ @PutMapping("/{id}")
+ public ResponseEntity<Need> updateNeed(@RequestBody Need need, @PathVariable int id) {
try {
- Need updatedNeed = cupboardService.updateNeed(need);
+ Need updatedNeed = cupboardService.updateNeed(need, id);
if (updatedNeed != null) {
return new ResponseEntity<>(need, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
+ } catch (InvalidParameterException ex) {
+ return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
} catch (IOException e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}