diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2025-04-06 15:15:47 -0400 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2025-04-06 15:15:47 -0400 |
commit | 9f14b3787a8cfc49fd168b1242adcc6d5fa8bfd6 (patch) | |
tree | 8af111a538a8d6361e1cf07467b9c31568284921 /ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java | |
parent | 1ac878b4aaa19ab889c7a98b7dab6acd57c778b3 (diff) | |
parent | 04cb51b2e7891785c956c5faa73fb88cc04e82e0 (diff) | |
download | JellySolutions-9f14b3787a8cfc49fd168b1242adcc6d5fa8bfd6.tar.gz JellySolutions-9f14b3787a8cfc49fd168b1242adcc6d5fa8bfd6.tar.bz2 JellySolutions-9f14b3787a8cfc49fd168b1242adcc6d5fa8bfd6.zip |
Merge branch 'main' into light-mode
# Conflicts:
# ufund-ui/src/app/app.component.html
# ufund-ui/src/app/components/funding-basket/funding-basket.component.html
# ufund-ui/src/app/components/need-list/need-list.component.html
# ufund-ui/src/app/components/need-page/need-page.component.css
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 | 21 |
1 files changed, 16 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 12fb0a9..5452c81 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.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -189,12 +190,22 @@ public class CupboardController { * @return OK if successful, other statuses if failure */ @PutMapping("/checkout") - 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, "PUT /need/checkout body={0}", data); + public ResponseEntity<Object> checkoutNeeds(@RequestBody List<Map<String, Integer>> data, @RequestHeader("jelly-api-key") String key) { + LOG.log(Level.INFO, "PUT /cupboard/checkout body={0}", data); try { - cupboardService.checkoutNeed(needID, checkoutAmount, key); + authService.keyIsValid(key); + + for (Map<String, Integer> map : data) { + int needID = map.get("needID"); + if (cupboardService.getNeed(needID) == null) { + return new ResponseEntity<>("One or more needs are invalid, please refresh.", HttpStatus.BAD_REQUEST); + } + } + for (Map<String, Integer> map : data) { + int needID = map.get("needID"); + int checkoutAmount = map.get("quantity"); + cupboardService.checkoutNeed(needID, checkoutAmount, key); + } return new ResponseEntity<>(HttpStatus.OK); } catch (IllegalArgumentException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); |