aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-03-06 21:41:39 -0500
committersowgro <tpoke.ferrari@gmail.com>2025-03-06 21:41:39 -0500
commitbb9ce55cb5b55a6aaed2399e39a01d68f2491ce3 (patch)
tree7df43079fa8d3e5c7b34c5ab13389018c1216078 /ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java
parenteb4edcc7e7e4f9a6a59bed6d3952486f179fc445 (diff)
downloadJellySolutions-bb9ce55cb5b55a6aaed2399e39a01d68f2491ce3.tar.gz
JellySolutions-bb9ce55cb5b55a6aaed2399e39a01d68f2491ce3.tar.bz2
JellySolutions-bb9ce55cb5b55a6aaed2399e39a01d68f2491ce3.zip
Push current changes (working on documentation and tests)
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java')
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java23
1 files changed, 6 insertions, 17 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java
index dca812b..1ef3032 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java
@@ -2,6 +2,7 @@ package com.ufund.api.ufundapi.persistence;
import java.io.File;
import java.io.IOException;
+import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
@@ -21,7 +22,7 @@ public class UserFileDAO implements UserDAO {
public UserFileDAO(@Value("${users.file}") String filename, ObjectMapper objectMapper) throws IOException {
this.filename = filename;
this.objectMapper = objectMapper;
- users = new TreeMap<>();
+ users = new HashMap<>();
load(); // load the users from the file
}
@@ -47,25 +48,14 @@ public class UserFileDAO implements UserDAO {
* @throws IOException If there was an IO issue saving the file
*/
private boolean save() throws IOException {
- User[] userArray = getUserArray();
-
- objectMapper.writeValue(new File(filename), userArray);
+ objectMapper.writeValue(new File(filename), users.values());
return true;
}
- /**
- * Return an array of the needs
- *
- * @return An array of all the needs
- */
- private User[] getUserArray() {
- return users.values().toArray(User[]::new);
- }
-
@Override
- public User[] getUsers() throws IOException {
+ public User[] getUsers() {
synchronized (users) {
- return getUserArray();
+ return users.values().toArray(User[]::new);
}
}
@@ -75,10 +65,9 @@ public class UserFileDAO implements UserDAO {
* @param username Name of desired user
*
* @return Desired user, null otherwise
- * @throws IOException If there was an IO issue saving the file
*/
@Override
- public User getUser(String username) throws IOException {
+ public User getUser(String username) {
synchronized (users) {
return users.getOrDefault(username, null);
}