Changeset 48f3030 for phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/UserService.java
- Timestamp:
- 09/23/22 02:03:14 (2 years ago)
- Branches:
- master
- Children:
- 895cd87
- Parents:
- 436e0da
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/UserService.java
r436e0da r48f3030 85 85 String name = decodedJWT.getClaim("name").as(String.class); 86 86 Long id = decodedJWT.getClaim("id").as(Long.class); 87 87 // String pickedSpecifications = decodedJWT.getClaim("pickedSpecifications").as(String.class); 88 88 return new User(id,name,role); 89 89 } … … 175 175 return ResponseEntity.ok().build(); 176 176 } 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 } 177 203 }
Note:
See TracChangeset
for help on using the changeset viewer.