aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-api/src/main')
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java3
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java4
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java7
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java11
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java1
5 files changed, 10 insertions, 16 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java
index d2f3f28..c2d9e06 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java
@@ -1,7 +1,6 @@
package com.ufund.api.ufundapi.controller;
import java.io.IOException;
-import java.security.InvalidParameterException;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -117,7 +116,7 @@ public class UserController {
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
- } catch (InvalidParameterException ex) {
+ } catch (IllegalArgumentException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
} catch (IllegalAccessException ex) {
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java
index d04d8b7..58b62df 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java
@@ -71,8 +71,8 @@ public class User {
return basket.toArray(Integer[]::new);
}
- public boolean removeBasketNeed(Integer needID) {
- return basket.remove(needID);
+ public void removeBasketNeed(Integer needID) {
+ basket.remove(needID);
}
/**
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 3115204..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
@@ -55,14 +55,12 @@ public class CupboardFileDAO implements CupboardDAO {
/**
* 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 {
+ private void save() throws IOException {
Need[] needArray = needs.values().toArray(Need[]::new);
objectMapper.writeValue(new File(filename), needArray);
- return true;
}
@Override
@@ -109,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;
}
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 63d864a..0d9b9e4 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
@@ -45,12 +45,10 @@ public class UserFileDAO implements UserDAO {
/**
* 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 {
+ private void save() throws IOException {
objectMapper.writeValue(new File(filename), users.values());
- return true;
}
@Override
@@ -83,9 +81,7 @@ public class UserFileDAO implements UserDAO {
public User updateUser(User user) throws IOException {
synchronized (users) {
if (users.containsKey(user.getUsername())) {
- // var old = users.put(user.getUsername(), user);
- // user.copyPassword(old);
- if (user.getBasket() == null || user.getType() == null) {
+ if (user.getBasket() == null || user.getType() == null) { // TODO clean this up
User oldData = users.get(user.getUsername());
User crutch = new User(oldData.getUsername(), 0, new ArrayList<>(), oldData.getType());
crutch.copyPassword(oldData);
@@ -107,7 +103,8 @@ public class UserFileDAO implements UserDAO {
synchronized (users) {
if (users.containsKey(username)) {
users.remove(username);
- return save();
+ save();
+ return true;
} else {
return false;
}
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java
index 51283fc..6e27f50 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java
@@ -2,7 +2,6 @@ package com.ufund.api.ufundapi.service;
import java.io.IOException;
-import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import com.ufund.api.ufundapi.DuplicateKeyException;