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-25 08:21:01 -0400
committerGunther6070 <haydenhartman10@yahoo.com>2025-03-25 08:21:01 -0400
commitffbe2870d320c4127d32307f2646f39e2e284eec (patch)
treef9f46447c689c1667f04f17bfbf2e8d07ff0fcd0 /ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java
parentd31c1aec7f615646553a227c8e235d4ae2679c68 (diff)
parentc15aa3daab0cf9a640945d4e634d1327fb55d2db (diff)
downloadJellySolutions-ffbe2870d320c4127d32307f2646f39e2e284eec.tar.gz
JellySolutions-ffbe2870d320c4127d32307f2646f39e2e284eec.tar.bz2
JellySolutions-ffbe2870d320c4127d32307f2646f39e2e284eec.zip
Merge branch 'api-cleanup' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b into api-cleanup
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.java57
1 files changed, 33 insertions, 24 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 664b53b..8db8901 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
@@ -23,6 +23,8 @@ import com.ufund.api.ufundapi.model.Need;
import com.ufund.api.ufundapi.model.Need.GoalType;
import com.ufund.api.ufundapi.service.CupboardService;
+import static java.util.List.of;
+
@RestController
@RequestMapping("cupboard")
public class CupboardController {
@@ -49,7 +51,8 @@ public class CupboardController {
*/
@PostMapping("")
public ResponseEntity<Need> createNeed(@RequestBody Map<String, Object> params) {
- System.out.println(params);
+ LOG.log(Level.INFO, "POST /cupboard body: {0}", params);
+
String name = (String) params.get("name");
double maxGoal = (double) params.get("maxGoal");
Need.GoalType goalType = GoalType.valueOf((String) params.get("type"));
@@ -58,10 +61,13 @@ public class CupboardController {
Need need = cupboardService.createNeed(name, maxGoal, goalType);
return new ResponseEntity<>(need, HttpStatus.OK);
} catch (DuplicateKeyException ex) {
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
return new ResponseEntity<>(HttpStatus.CONFLICT);
} catch (IllegalArgumentException ex) {
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
} catch (IOException ex) {
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -76,7 +82,7 @@ public class CupboardController {
*/
@GetMapping("")
public ResponseEntity<Need[]> getNeeds() {
- LOG.info("GET /needs");
+ LOG.info("GET /cupboard");
try {
Need[] needs = cupboardService.getNeeds();
@@ -88,19 +94,21 @@ public class CupboardController {
}
/**
- * 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<br>
- * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise
- * <p>
- */
+ * 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}
+ *
+ * @deprecated Searching should now be done client side in the future
+ *
+ * @return ResponseEntity with array of {@link Need need} objects (may be empty) and
+ * HTTP status of OK<br>
+ * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise
+ * <p>
+ */
@GetMapping("/")
public ResponseEntity<Need[]> searchNeeds(@RequestParam String name) {
- LOG.info("GET /need/?name="+name);
+ LOG.info("GET /cupboard/?name="+name);
try {
Need[] needs = cupboardService.searchNeeds(name);
@@ -121,7 +129,7 @@ public class CupboardController {
*/
@GetMapping("/{id}")
public ResponseEntity<Need> getNeed(@PathVariable int id) {
- LOG.log(Level.INFO, "GET /need/{0}", id);
+ LOG.log(Level.INFO, "GET /cupboard/{0}", id);
try {
Need need = cupboardService.getNeed(id);
@@ -145,7 +153,7 @@ public class CupboardController {
*/
@PutMapping("/{id}")
public ResponseEntity<Need> updateNeed(@RequestBody Need need, @PathVariable int id) {
- LOG.log(Level.INFO, "Updating need: " + need);
+ LOG.log(Level.INFO, "PUT /cupboard/{0} body: {1}", of(id, need));
try {
Need updatedNeed = cupboardService.updateNeed(need, id);
if (updatedNeed != null) {
@@ -154,10 +162,10 @@ public class CupboardController {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
} catch (IllegalArgumentException ex) {
- ex.printStackTrace();
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
} catch (IOException ex) {
- ex.printStackTrace();
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -168,24 +176,23 @@ public class CupboardController {
* @param data JSON object with paramters needID and amount
* @param key Key used to authenticate user
* @return OK if successful, other statuses if failure
- * @throws IllegalAccessException
*/
@PutMapping("/checkout")
- public ResponseEntity<Object> checkoutNeeds(@RequestBody Map<String, Integer> data, @RequestHeader("jelly-api-key") String key) throws IllegalAccessException {
+ public ResponseEntity<Object> checkoutNeeds(@RequestBody Map<String, Integer> data, @RequestHeader("jelly-api-key") String key) {
int needID = data.get("needID");
int checkoutAmount = data.get("amount");
- LOG.log(Level.INFO, "Checking out need with ID: " + needID + " by " + checkoutAmount);
+ LOG.log(Level.INFO, "PUT /need/checkout body: {0}", data);
try {
cupboardService.checkoutNeed(needID, checkoutAmount, key);
return new ResponseEntity<>(HttpStatus.OK);
} catch (IllegalArgumentException ex) {
- ex.printStackTrace();
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
} catch (IllegalAccessException ex) {
- ex.printStackTrace();
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
} catch (IOException ex) {
- ex.printStackTrace();
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -198,6 +205,7 @@ public class CupboardController {
*/
@DeleteMapping("/{id}")
public ResponseEntity<Need> deleteNeed(@PathVariable int id) {
+ LOG.log(Level.INFO, "DELETE /cupboard/{0}", id);
try {
Need need = cupboardService.getNeed(id);
if (cupboardService.deleteNeed(id)) {
@@ -205,7 +213,8 @@ public class CupboardController {
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
- } catch (IOException e) {
+ } catch (IOException ex) {
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}