diff options
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.java | 33 |
1 files changed, 24 insertions, 9 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 c42d211..ebfa9f2 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 @@ -62,7 +62,6 @@ public class UserFileDAO implements UserDAO { return users.values().toArray(User[]::new); } - @Override public User[] getUsers() throws IOException { synchronized (users) { @@ -86,11 +85,11 @@ public class UserFileDAO implements UserDAO { } /** - * Return the user with the String name name or null otherwise + * Create a User user * - * @param name Name of desired user + * @param user User to create * - * @return Desired user, null otherwise + * @return Desired created user * @throws IOException If there was an IO issue saving the file */ @Override @@ -103,19 +102,36 @@ public class UserFileDAO implements UserDAO { } } + /** + * Update a user that matches the supplied name + * + * @param name The name of the user + * @param newUser New user data + * + * @return Desired user, null otherwise + * @throws IOException If there was an IO issue saving the file + */ @Override - public User updateUser(User user) throws IOException { + public User updateUser(User newUser, String name) throws IOException { synchronized (users) { - if (users.containsKey(user.getName())) { - users.put(user.getName(), user); + if (users.containsKey(name)) { + users.put(name, newUser); save(); - return user; + return newUser; } else { return null; } } } + /** + * Delete a user matching the name + * + * @param name The name of the user + * + * @return True if deleted, false otherwise + * @throws IOException If there was an IO issue saving the file + */ @Override public boolean deleteUser(String name) throws IOException { synchronized (users) { @@ -128,5 +144,4 @@ public class UserFileDAO implements UserDAO { } } - }
\ No newline at end of file |