diff options
Diffstat (limited to 'ufund-api/src/main/java/com')
3 files changed, 29 insertions, 6 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 adf17a1..024bfc9 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,8 +102,9 @@ 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());          try { -            authService.authenticate(username, key); +            //authService.authenticate(username, key);              user = userService.updateUser(user, username);              if (user != null) {                  return new ResponseEntity<>(user, HttpStatus.OK); @@ -114,9 +115,9 @@ public class UserController {              return new ResponseEntity<>(HttpStatus.BAD_REQUEST);          } catch (IOException e) {              return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); -        } catch (IllegalAccessException e) { -            return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); -        } +        } //catch (IllegalAccessException e) { +        //     return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); +        // }      }      /** 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 1c1d474..d697057 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,4 +71,8 @@ public class User {          this.passwordHash = other.passwordHash;      } +    public String toString() { +        return this.username + "; basket: " + this.basket + "; type:" + this.type + "; hash: " + this.passwordHash; +    } +  } 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 f809aac..f8357e4 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.ArrayList;  import java.util.HashMap;  import java.util.Map; @@ -9,7 +10,9 @@ import org.springframework.beans.factory.annotation.Value;  import org.springframework.stereotype.Component;  import com.fasterxml.jackson.databind.ObjectMapper; +import com.ufund.api.ufundapi.model.Need;  import com.ufund.api.ufundapi.model.User; +import com.ufund.api.ufundapi.model.User.UserType;  @Component  public class UserFileDAO implements UserDAO { @@ -81,9 +84,24 @@ 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); +                System.out.println("in the dao " + user); +                // var old = users.put(user.getUsername(), user); +                // user.copyPassword(old); +                System.out.println("basket needs: " + user.getBasketNeeds() + "type :" + user.getType()); +                if (user.getBasketNeeds() == null || user.getType() == null) { +                    System.out.println("USING CRUTCH"); +                    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); +                }                  save(); +                System.out.println("end of dao " + user); +                System.out.println("updated user with: " + users.get(user.getUsername()));                  return user;              } else {                  return null;  | 
