-
Notifications
You must be signed in to change notification settings - Fork 0
DEMO-1 implement REST API endpoint for updating users #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
096e6bf
9767945
e6b440c
6e30671
71a9a43
0486c8c
ce4e552
ec493bf
402cd8a
b61e32e
79a2b84
1edf82e
305f3b8
4d1a6bf
54ddb58
61a1890
fa282a4
e1fb5e8
9b76d3f
fa4280d
d948d4b
3fa8cf5
75fbd3b
d8cffba
d4a8045
fbb8cda
f68ed6b
b8ad762
2b0c282
336740f
af17bb0
c2b99ad
3310313
25445ec
452a32d
bed8af0
c5df45c
d9295ed
4f4625a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,10 +33,22 @@ | |
| public ResponseEntity<User> getCarById(@PathVariable(value = "id") Long id) | ||
| throws ResourceNotFoundException { | ||
| User user = userService.getUserDetails(id) | ||
| .orElseThrow(() -> new ResourceNotFoundException("User not found for id: " + id)); | ||
|
Check failure on line 36 in src/main/java/com/sergiofreire/xray/tutorials/springboot/boundary/UserRestController.java
|
||
| return ResponseEntity.ok().body(user); | ||
| } | ||
|
|
||
| @PutMapping("/users/{id}") | ||
| public ResponseEntity<User> updateUser(@PathVariable(value = "id") Long id, @RequestBody User userDetails) | ||
| throws ResourceNotFoundException { | ||
| User user = userService.getUserDetails(id) | ||
| .orElseThrow(() -> new ResourceNotFoundException("User not found for id: " + id)); | ||
| user.setName(userDetails.getName()); | ||
| user.setUsername(userDetails.getUsername()); | ||
| user.setPassword(userDetails.getPassword()); | ||
|
||
| final User updatedUser = userService.save(user); | ||
| return ResponseEntity.ok(updatedUser); | ||
| } | ||
|
Comment on lines
+40
to
+50
|
||
|
|
||
| @GetMapping(path="/users" ) | ||
| public List<User> getAllUsers() { | ||
| return userService.getAllUsers(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -46,6 +46,7 @@ void setUp() { | |||
|
|
||||
| Mockito.when(userRepository.findById(john.getId())).thenReturn(Optional.of(john)); | ||||
| Mockito.when(userRepository.findByUsername(john.getUsername())).thenReturn(john); | ||||
| Mockito.when(userRepository.findByUsername(john.getUsername())).thenReturn(john); | ||||
|
||||
| Mockito.when(userRepository.findByUsername(john.getUsername())).thenReturn(john); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing input validation. The
updateUsermethod acceptsuserDetailswithout validating it (e.g., using@Validannotation). This could allow invalid data (e.g., empty username, short password) to be saved, bypassing the validation constraints defined in the User entity. Consider adding@Validbefore@RequestBody User userDetailsto ensure validation is enforced.