From cb6463630446503d441b37f3d62ec2d064b00269 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Thu, 3 Apr 2025 07:56:54 -0400 Subject: Added dashboard statistics --- .../src/main/java/com/ufund/api/ufundapi/controller/UserController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ufund-api') diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java index c6e622c..6953276 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java @@ -108,7 +108,7 @@ public class UserController { try { authService.keyHasAccessToCupboard(key); - int count = userService.getUserCount(); + String count = String.valueOf(userService.getUserCount()); return new ResponseEntity<>(count, HttpStatus.OK); } catch (IllegalAccessException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); -- cgit v1.2.3 From 26b4a37cb91dfe5551f3e227512cd5ceff897d54 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Thu, 3 Apr 2025 14:49:04 -0400 Subject: Changes to cupboard on front end and back end to try and fix bugs --- .../api/ufundapi/controller/CupboardController.java | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'ufund-api') 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..2cf8647 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 checkoutNeeds(@RequestBody Map 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 checkoutNeeds(@RequestBody List> 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 map : data) { + int needID = map.get("needID"); + if (cupboardService.getNeed(needID) != null) { + return new ResponseEntity<>("One or more need is invalid, please refresh.", HttpStatus.BAD_REQUEST); + } + } + for (Map map : data) { + int needID = map.get("needID"); + int checkoutAmount = map.get("amount"); + cupboardService.checkoutNeed(needID, checkoutAmount, key); + } return new ResponseEntity<>(HttpStatus.OK); } catch (IllegalArgumentException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); -- cgit v1.2.3 From 75f5ad5fb154811d7acd236687bb7f30bb7c10aa Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Thu, 3 Apr 2025 15:35:12 -0400 Subject: Fixed incognito race condition and checkout bugs --- .../java/com/ufund/api/ufundapi/controller/CupboardController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ufund-api') 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 2cf8647..075878a 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 @@ -197,13 +197,13 @@ public class CupboardController { for (Map map : data) { int needID = map.get("needID"); - if (cupboardService.getNeed(needID) != null) { + if (cupboardService.getNeed(needID) == null) { return new ResponseEntity<>("One or more need is invalid, please refresh.", HttpStatus.BAD_REQUEST); } } for (Map map : data) { int needID = map.get("needID"); - int checkoutAmount = map.get("amount"); + int checkoutAmount = map.get("quantity"); cupboardService.checkoutNeed(needID, checkoutAmount, key); } return new ResponseEntity<>(HttpStatus.OK); -- cgit v1.2.3 From 8c38792e8e257cf264d5739e80e085c824ccecd8 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Thu, 3 Apr 2025 15:54:36 -0400 Subject: Fixed broken tests --- .../controller/CupboardControllerTest.java | 48 +++++++++++++++------- 1 file changed, 33 insertions(+), 15 deletions(-) (limited to 'ufund-api') diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java index 8572ec6..7ea4455 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java @@ -1,6 +1,7 @@ package com.ufund.api.ufundapi.controller; import java.io.IOException; +import java.util.List; import java.util.Map; import static java.util.Map.entry; @@ -418,12 +419,14 @@ public class CupboardControllerTest { @Test public void checkoutNeeds() throws IOException, IllegalAccessException { + when(mockCupboardService.getNeed(0)).thenReturn(new Need("name", "image", "location", 0, 10, GoalType.MONETARY, true, "a")); doNothing().when(mockCupboardService).checkoutNeed(0, 20, key); - - Map needMap = Map.ofEntries( - entry("needID", 0), - entry("amount", 20) + var needMap = List.of( + Map.ofEntries( + entry("needID", 0), + entry("quantity", 20) + ) ); var res = cupboardController.checkoutNeeds(needMap, key); @@ -435,9 +438,15 @@ public class CupboardControllerTest { public void checkoutNeedsBadRequest() throws IOException, IllegalAccessException { doThrow(new IllegalArgumentException()).when(mockCupboardService).checkoutNeed(0, 20, key); - Map needMap = Map.ofEntries( - entry("needID", 0), - entry("amount", 20) + var needMap = List.of( + Map.ofEntries( + entry("needID", 0), + entry("quantity", 20) + ), + Map.ofEntries( + entry("needID", 2), + entry("quantity", 30) + ) ); var res = cupboardController.checkoutNeeds(needMap, key); @@ -447,11 +456,17 @@ public class CupboardControllerTest { @Test public void checkoutNeedsUnauthorized() throws IOException, IllegalAccessException { - doThrow(new IllegalAccessException()).when(mockCupboardService).checkoutNeed(0, 20, key); - - Map needMap = Map.ofEntries( - entry("needID", 0), - entry("amount", 20) + doThrow(new IllegalAccessException()).when(mockAuthService).keyIsValid(key); + + var needMap = List.of( + Map.ofEntries( + entry("needID", 0), + entry("quantity", 20) + ), + Map.ofEntries( + entry("needID", 2), + entry("quantity", 30) + ) ); var res = cupboardController.checkoutNeeds(needMap, key); @@ -461,11 +476,14 @@ public class CupboardControllerTest { @Test public void checkoutNeedsInternalError() throws IOException, IllegalAccessException { + when(mockCupboardService.getNeed(0)).thenReturn(new Need("name", "image", "location", 0, 10, GoalType.MONETARY, true, "a")); doThrow(new IOException()).when(mockCupboardService).checkoutNeed(0, 20, key); - Map needMap = Map.ofEntries( - entry("needID", 0), - entry("amount", 20) + var needMap = List.of( + Map.ofEntries( + entry("needID", 0), + entry("quantity", 20) + ) ); var res = cupboardController.checkoutNeeds(needMap, key); -- cgit v1.2.3 From 03431245f71385c5d641f66a7f63c1a22ab65210 Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 4 Apr 2025 20:56:36 -0400 Subject: [backend] Add toString to need for debugging --- .../main/java/com/ufund/api/ufundapi/model/Need.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'ufund-api') diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java index 9b6170b..d3b3065 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java @@ -2,6 +2,8 @@ package com.ufund.api.ufundapi.model; import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Arrays; + public class Need { public enum GoalType { @@ -129,4 +131,20 @@ public class Need { public void setID(int id){ this.id = id; } + + @Override + public String toString() { + return "Need{" + + "name='" + name + '\'' + + ", image='" + image + '\'' + + ", location='" + location + '\'' + + ", id=" + id + + ", filterAttributes=" + Arrays.toString(filterAttributes) + + ", type=" + type + + ", maxGoal=" + maxGoal + + ", urgent=" + urgent + + ", current=" + current + + ", description='" + description + '\'' + + '}'; + } } \ No newline at end of file -- cgit v1.2.3 From 04db6f32b249ffb17c571cd6b16c8c54397f0be4 Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 4 Apr 2025 23:55:19 -0400 Subject: Fix typos --- .../main/java/com/ufund/api/ufundapi/controller/CupboardController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ufund-api') 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 075878a..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 @@ -198,7 +198,7 @@ public class CupboardController { for (Map map : data) { int needID = map.get("needID"); if (cupboardService.getNeed(needID) == null) { - return new ResponseEntity<>("One or more need is invalid, please refresh.", HttpStatus.BAD_REQUEST); + return new ResponseEntity<>("One or more needs are invalid, please refresh.", HttpStatus.BAD_REQUEST); } } for (Map map : data) { -- cgit v1.2.3