diff options
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api')
| -rw-r--r-- | ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserDAO.java | 5 | ||||
| -rw-r--r-- | ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java | 33 | 
2 files changed, 27 insertions, 11 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserDAO.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserDAO.java index 5926214..d456abc 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserDAO.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserDAO.java @@ -49,14 +49,15 @@ public interface UserDAO {      /**       * Updates and saves a {@linkplain User user}       *  -     * @param user {@link User user} object to be updated and saved +     * @param newUser {@link User user} object to be updated and saved +     * @param name {@link String name} name of object to be updated       *        * @return updated {@link User user} if successful, null if       *         {@link User user} could not be found       *        * @throws IOException if underlying storage cannot be accessed       */ -    User updateUser(User user) throws IOException; +    User updateUser(User newUser, String name) throws IOException;      /**       * Deletes a {@linkplain User user} with the given id 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  | 
