File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
src/main/java/com/jap/rest101/controller Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments