Ignore:
Timestamp:
09/23/22 02:03:14 (22 months ago)
Author:
Marko <Marko@…>
Branches:
master
Children:
895cd87
Parents:
436e0da
Message:

Implemented all use cases

File:
1 edited

Legend:

Unmodified
Added
Removed
  • phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/UserService.java

    r436e0da r48f3030  
    8585        String name = decodedJWT.getClaim("name").as(String.class);
    8686        Long id = decodedJWT.getClaim("id").as(Long.class);
    87 
     87//        String pickedSpecifications = decodedJWT.getClaim("pickedSpecifications").as(String.class);
    8888        return new User(id,name,role);
    8989    }
     
    175175        return ResponseEntity.ok().build();
    176176    }
     177
     178    public ResponseEntity<Object> editSpecificationsForUser(Long userId, String specifications) {
     179        boolean userExists = userRepository.existsById(userId);
     180        if (!userExists)
     181        {
     182            return ResponseEntity.badRequest().body("User with id "+userId+" doesn't exist");
     183        }
     184        User user = userRepository.findById(userId).get();
     185
     186        user.setSpecifications(specifications);
     187        userRepository.save(user);
     188
     189        return ResponseEntity.ok().build();
     190    }
     191
     192    public String getSpecificationsForUser(Long userId) {
     193        boolean userExists = userRepository.existsById(userId);
     194        if (!userExists)
     195        {
     196            throw new UsernameNotFoundException("User with id "+userId+" doesn't exist");
     197        }
     198
     199        User user = userRepository.findById(userId).get();
     200
     201        return user.getSpecifications() != null ? user.getSpecifications() : "[]";
     202    }
    177203}
Note: See TracChangeset for help on using the changeset viewer.