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-24 21:17:33 -0400
committerGunther6070 <haydenhartman10@yahoo.com>2025-03-24 21:17:33 -0400
commitcb3b7710b9e32df408b3a38383aca049fa98214e (patch)
tree38bbfe093fe6b397dd5f378c77e56f581058753b /ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java
parent35d7c971ed47718d4dc5738edb09d62cd780dac4 (diff)
downloadJellySolutions-cb3b7710b9e32df408b3a38383aca049fa98214e.tar.gz
JellySolutions-cb3b7710b9e32df408b3a38383aca049fa98214e.tar.bz2
JellySolutions-cb3b7710b9e32df408b3a38383aca049fa98214e.zip
Fixed various bugs and began fixing auth system. Also started implementing checkout method in cupboardService
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.java29
1 files changed, 29 insertions, 0 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 36ae341..664b53b 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
@@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@@ -162,6 +163,34 @@ public class CupboardController {
}
/**
+ * Checks out a need by checkoutAmount
+ *
+ * @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 {
+ int needID = data.get("needID");
+ int checkoutAmount = data.get("amount");
+ LOG.log(Level.INFO, "Checking out need with ID: " + needID + " by " + checkoutAmount);
+ try {
+ cupboardService.checkoutNeed(needID, checkoutAmount, key);
+ return new ResponseEntity<>(HttpStatus.OK);
+ } catch (IllegalArgumentException ex) {
+ ex.printStackTrace();
+ return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
+ } catch (IllegalAccessException ex) {
+ ex.printStackTrace();
+ return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ }
+
+ /**
* Deletes a single need from the cupboard using the Need's id
*
* @param id The need's ID