aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java2
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java2
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java2
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java1
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java5
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java2
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java4
-rw-r--r--ufund-ui/src/app/components/funding-basket/funding-basket.component.ts45
-rw-r--r--ufund-ui/src/app/services/users.service.ts9
9 files changed, 39 insertions, 33 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java
index b9ab4b4..36ae341 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java
@@ -144,7 +144,7 @@ public class CupboardController {
*/
@PutMapping("/{id}")
public ResponseEntity<Need> updateNeed(@RequestBody Need need, @PathVariable int id) {
- LOG.log(Level.INFO, "RAHHHHH " + need);
+ LOG.log(Level.INFO, "Updating need: " + need);
try {
Need updatedNeed = cupboardService.updateNeed(need, id);
if (updatedNeed != null) {
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 024bfc9..a16fdec 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
@@ -102,7 +102,7 @@ public class UserController {
*/
@PutMapping("/{username}")
public ResponseEntity<User> updateUser(@RequestBody User user, @PathVariable String username, @RequestHeader("jelly-api-key") String key) {
- System.out.println("controller: " + user + " " + username + " " + key.toString());
+ LOG.log(Level.INFO,"PUT: " + user + " " + username + " " + key.toString());
try {
//authService.authenticate(username, key);
user = userService.updateUser(user, username);
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 13000cc..6de1a8a 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
@@ -51,7 +51,7 @@ public class User {
basket.add(need.getId());
}
- public Integer[] getBasketNeeds() {
+ public Integer[] getNeeds() {
return basket.toArray(Integer[]::new);
}
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 a51d307..521acae 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
@@ -100,7 +100,6 @@ public class CupboardFileDAO implements CupboardDAO {
@Override
public Need updateNeed(Need need) throws IOException {
- System.out.println("UPDATING NEED FOR " + need);
synchronized (needs) {
if (needs.containsKey(need.getId())) {
needs.put(need.getId(), need);
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 def21c6..ee7dbcf 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
@@ -80,16 +80,19 @@ public class UserFileDAO implements UserDAO {
@Override
public User updateUser(User user) throws IOException {
+ System.out.println("HOW TO FORK AND KILL CHILD " + user);
synchronized (users) {
if (users.containsKey(user.getUsername())) {
// var old = users.put(user.getUsername(), user);
// user.copyPassword(old);
- if (user.getBasketNeeds() == null || user.getType() == null) {
+ if (user.getNeeds() == null || user.getType() == null) {
+ System.out.println("CRUTCH DATA");
User oldData = users.get(user.getUsername());
User crutch = new User(oldData.getUsername(), 0, new ArrayList<Integer>(), oldData.getType());
crutch.copyPassword(oldData);
users.put(user.getUsername(), crutch);
} else {
+ System.out.println("GOOD DATA");
var old = users.put(user.getUsername(), user);
user.copyPassword(old);
}
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 3b59953..caf9f4c 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
@@ -44,7 +44,7 @@ public class UserService {
*/
public User getUser(String username) throws IOException {
User user = userDAO.getUser(username);
- for (int needId : user.getBasketNeeds()) {
+ for (int needId : user.getNeeds()) {
if (cupboardService.getNeed(needId) == null) {
user.removeBasketNeed(needId);
}
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java
index 745e382..55b7f07 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java
@@ -59,7 +59,7 @@ public class UserTest {
user.addToBasket(need);
- Need getNeed = cupboardService.getNeed(user.getBasketNeeds()[0]);
+ Need getNeed = cupboardService.getNeed(user.getNeeds()[0]);
assertEquals(needs[0], getNeed);
@@ -80,7 +80,7 @@ public class UserTest {
user.removeBasketNeed(need.getId());
user.addToBasket(need2);
- Need getNeed = cupboardService.getNeed(user.getBasketNeeds()[0]);
+ Need getNeed = cupboardService.getNeed(user.getNeeds()[0]);
assertEquals(need2, getNeed);
diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
index 7f086ec..66b9fd1 100644
--- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
+++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
@@ -42,7 +42,7 @@ export class FundingBasketComponent implements OnInit {
let contribution = c as HTMLInputElement;
console.log(contribution.value, contribution.id);
contribution.setAttribute("style","");
- if ( contribution.value == '' || contribution.valueAsNumber < 0) {
+ if ( contribution.value == '' || contribution.valueAsNumber <= 0) {
this.isValid = false;
contribution.setAttribute("style","color: #ff0000");
}
@@ -53,30 +53,27 @@ export class FundingBasketComponent implements OnInit {
let need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id));
need.current +=+ contribution.value;
console.log(need);
- this.usersService.removeNeed(need.id);
+ this.usersService.removeNeed(+need.id);
this.cupboardService.updateNeed(need.id, need)
- .pipe(catchError((ex, r) => {
- console.log(ex.status);
- if (ex.status == 500) {
- this.statusText.next("Fields cannot be blank");
- } else if (ex.status == 400) {
- this.statusText.next("Goal must be greater than 0");
- } else {
- this.statusText.next("Error on creating need");
- }
- return new Observable<string>();
- }))
- .subscribe(
- (result) => {
- if (result) {
- console.log("need updated successfully");
- //this.needList?.refresh()
- } else {
- console.log("need update failed");
- }
- }
-
- );
+ .pipe(catchError((ex, r) => {
+ console.log(ex.status);
+ if (ex.status == 500) {
+ this.statusText.next('Fields cannot be blank');
+ } else if (ex.status == 400) {
+ this.statusText.next('Goal must be greater than 0');
+ } else {
+ this.statusText.next('Error on creating need');
+ }
+ return new Observable<string>();
+ }))
+ .subscribe((result) => {
+ if (result) {
+ console.log('need updated successfully');
+ //this.needList?.refresh()
+ } else {
+ console.log('need update failed');
+ }
+ });
}
}
}
diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts
index 62aea79..ddbd322 100644
--- a/ufund-ui/src/app/services/users.service.ts
+++ b/ufund-ui/src/app/services/users.service.ts
@@ -45,6 +45,7 @@ export class UsersService {
}
updateUser(user: User): Observable<User> {
+ console.log("REMOVING USER IN ANGULAR: ", user)
console.log(user, user.basket)
console.log(this.apiKey)
@@ -89,7 +90,13 @@ export class UsersService {
let newArr = this.basket.getValue().filter(v => v.id != id);
this.basket.next(newArr);
this.getCurrentUser()!.basket = newArr.map(need => need.id);
- this.updateUser(this.getCurrentUser()!);
+ console.log(this.getCurrentUser()!.basket)
+ this.updateUser(this.getCurrentUser()!).subscribe(() => {
+ this.refreshBasket();
+ error: (err: any) => {
+ console.error(err);
+ }
+ });
}
getBasket() {