diff options
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.java | 13 |
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); } |