diff options
author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-03-24 21:17:33 -0400 |
---|---|---|
committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-03-24 21:17:33 -0400 |
commit | cb3b7710b9e32df408b3a38383aca049fa98214e (patch) | |
tree | 38bbfe093fe6b397dd5f378c77e56f581058753b /ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java | |
parent | 35d7c971ed47718d4dc5738edb09d62cd780dac4 (diff) | |
download | JellySolutions-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/service/CupboardService.java')
-rw-r--r-- | ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java index 2398745..8713882 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java @@ -3,6 +3,7 @@ package com.ufund.api.ufundapi.service; import java.io.IOException; import java.util.Arrays; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import com.ufund.api.ufundapi.DuplicateKeyException; @@ -13,8 +14,10 @@ import com.ufund.api.ufundapi.persistence.CupboardDAO; public class CupboardService { private final CupboardDAO cupboardDAO; + final AuthService authService; - public CupboardService(CupboardDAO cupboardDAO) { + public CupboardService(@Lazy AuthService authService, CupboardDAO cupboardDAO) { + this.authService = authService; this.cupboardDAO = cupboardDAO; } @@ -97,6 +100,23 @@ public class CupboardService { } /** + * Checks out a need with the desired amount + * + * @param id The ID of the need to update + * @param checkoutAmount The amount to update the need by + * @throws IOException + * @throws IllegalAccessException + */ + public void checkoutNeed(int id, double checkoutAmount, String key) throws IOException, IllegalAccessException { + if (checkoutAmount <= 0) { + throw new IllegalArgumentException("Amount must be greather than 0"); + } + authService.authenticate(key); + Need need = cupboardDAO.getNeed(id); + need.incrementCurrent(checkoutAmount); + } + + /** * Delete a need from the cupboard * * @param id the ID of the need |