Skip to content

Commit 58f9d93

Browse files
committed
init update data
1 parent 4e74625 commit 58f9d93

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/main/java/com/jap/rest101/controller/UserController.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,21 @@ public ResponseEntity<?> getUser(@PathVariable("id") Long id) {
3535
return ResponseEntity.notFound().build();
3636
return ResponseEntity.ok(user);
3737
}
38+
39+
@PatchMapping("/{id}")
40+
public ResponseEntity<?> updateUser(@PathVariable("id") Long id, @RequestBody User user) {
41+
Optional<User> currentUser = repository.findById(id);
42+
if (currentUser.isEmpty())
43+
return ResponseEntity.notFound().build();
44+
45+
User u = currentUser.get();
46+
u.setFirstName(user.getFirstName());
47+
u.setLastName(user.getLastName());
48+
u.setEmail(user.getEmail());
49+
u.setPhone(user.getPhone());
50+
repository.save(u);
51+
52+
return ResponseEntity.ok(currentUser);
53+
}
3854
}
3955

0 commit comments

Comments
 (0)