Skip to content

Commit 21de891

Browse files
committed
delete user
1 parent 58f9d93 commit 21de891

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,16 @@ public ResponseEntity<?> updateUser(@PathVariable("id") Long id, @RequestBody Us
5151

5252
return ResponseEntity.ok(currentUser);
5353
}
54+
55+
@DeleteMapping("/{id}")
56+
public ResponseEntity<?> deleteUser(@PathVariable("id") Long id) {
57+
Optional<User> currentUser = repository.findById(id);
58+
if (currentUser.isEmpty())
59+
return ResponseEntity.notFound().build();
60+
61+
repository.deleteById(id);
62+
63+
return ResponseEntity.noContent().build();
64+
}
5465
}
5566

0 commit comments

Comments
 (0)