aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java
diff options
context:
space:
mode:
authorTyler Ferrari <69283684+Sowgro@users.noreply.github.com>2025-03-27 18:50:33 -0400
committerGitHub <noreply@github.com>2025-03-27 18:50:33 -0400
commitddbd1cc688aa98fb275ad72a750fbaaf53e6c0ae (patch)
tree0a0f9669fb0f7cf2f2816b798269e50a8b26f125 /ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java
parent35d7c971ed47718d4dc5738edb09d62cd780dac4 (diff)
parent4f5e9e9ecda282a98af5d70bd6cf0540973c7314 (diff)
downloadJellySolutions-ddbd1cc688aa98fb275ad72a750fbaaf53e6c0ae.tar.gz
JellySolutions-ddbd1cc688aa98fb275ad72a750fbaaf53e6c0ae.tar.bz2
JellySolutions-ddbd1cc688aa98fb275ad72a750fbaaf53e6c0ae.zip
Merge pull request #17 from RIT-SWEN-261-02/api-cleanup
Merge api-cleanup into main
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java')
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java31
1 files changed, 11 insertions, 20 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java
index 521acae..7efda83 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java
@@ -1,15 +1,16 @@
package com.ufund.api.ufundapi.persistence;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.ufund.api.ufundapi.model.Need;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ufund.api.ufundapi.model.Need;
+
@Component
public class CupboardFileDAO implements CupboardDAO {
@@ -52,31 +53,20 @@ public class CupboardFileDAO implements CupboardDAO {
}
/**
- * Return an array of the needs
- *
- * @return An array of all the needs
- */
- private Need[] getNeedsArray() {
- return needs.values().toArray(Need[]::new);
- }
-
- /**
* Saves the needs to json
*
- * @return True if the save was successful, false otherwise
* @throws IOException If there was an IO issue saving the file
*/
- private boolean save() throws IOException {
- Need[] needArray = getNeedsArray();
+ private void save() throws IOException {
+ Need[] needArray = needs.values().toArray(Need[]::new);
objectMapper.writeValue(new File(filename), needArray);
- return true;
}
@Override
public Need[] getNeeds() {
synchronized (needs) {
- return getNeedsArray();
+ return needs.values().toArray(Need[]::new);
}
}
@@ -117,7 +107,8 @@ public class CupboardFileDAO implements CupboardDAO {
synchronized (needs) {
if (needs.containsKey(id)) {
needs.remove(id);
- return save();
+ save();
+ return true;
} else {
return false;
}