From 34903015992ac0cd7719b662af3ceb54a801351c Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 7 Mar 2025 00:02:56 -0500 Subject: Finish update methods --- .../com/ufund/api/ufundapi/controller/CupboardController.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.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 15a741a..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; @@ -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 updateNeed(@RequestBody Need need) { + @PutMapping("/{id}") + public ResponseEntity 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); } -- cgit v1.2.3