- Timestamp:
- 09/23/22 02:03:14 (2 years ago)
- Branches:
- master
- Children:
- 895cd87
- Parents:
- 436e0da
- Location:
- phonelux-backend/src/main/java/finki/it/phoneluxbackend
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/UserController.java
r436e0da r48f3030 33 33 } 34 34 35 @PutMapping(path = "/{userId}/editspecifications") 36 public ResponseEntity<Object> editSpecificationsForUser(@PathVariable("userId") Long userId, 37 @RequestBody String specifications){ 38 return userService.editSpecificationsForUser(userId,specifications); 39 } 40 41 @GetMapping(path = "/{userId}/getspecifications") 42 public String getSpecificationsForUser(@PathVariable("userId") Long userId){ 43 return userService.getSpecificationsForUser(userId); 44 } 45 35 46 } -
phonelux-backend/src/main/java/finki/it/phoneluxbackend/entities/User.java
r436e0da r48f3030 69 69 } 70 70 71 71 72 public User(Long id, String firstName, String lastName, String email, UserRole userRole) { 72 73 this.id = id; -
phonelux-backend/src/main/java/finki/it/phoneluxbackend/security/CustomAuthenticationFilter.java
r436e0da r48f3030 52 52 .withClaim("name", user.getFirstName()) 53 53 .withClaim("id", user.getId()) 54 // .withClaim("pickedSpecifications",user.getSpecifications()!=null ? 55 // user.getSpecifications() : "[]") 54 56 .sign(algorithm); 55 57 -
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.