File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
src/main/java/lk/ijse/dep/note Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 11package lk .ijse .dep .note .api ;
22
3+ import jakarta .validation .Valid ;
34import lk .ijse .dep .note .dto .UserDTO ;
45import lk .ijse .dep .note .service .UserService ;
56import lk .ijse .dep .note .service .exception .DuplicateEmailException ;
@@ -18,9 +19,7 @@ public class UserController {
1819
1920 @ ResponseStatus (HttpStatus .CREATED )
2021 @ PostMapping (consumes = "application/json" , produces = "application/json" )
21- public UserDTO registerUser (@ RequestBody UserDTO user ) {
22- //validate
23-
22+ public UserDTO registerUser (@ RequestBody @ Valid UserDTO user ) {
2423
2524 userService .registerUser (user );
2625
@@ -45,9 +44,9 @@ public void deleteuser(@PathVariable String userId) {
4544
4645 @ ResponseStatus (HttpStatus .NO_CONTENT )
4746 @ PatchMapping (path = "{userId:[A-Fa-f0-\\ ~]{36}}" , consumes = "application/json" )
48- public void updateUser (@ PathVariable String userId , @ RequestBody UserDTO user ) {
47+ public void updateUser (@ PathVariable String userId , @ RequestBody @ Valid UserDTO user ) {
48+
4949
50- //todo:validate the user
5150
5251 user .setId (userId );
5352 userService .updateUser (user );
Original file line number Diff line number Diff line change 11package lk .ijse .dep .note .dto ;
22
3+ import jakarta .validation .constraints .*;
34import lk .ijse .dep .note .entity .SuperEntity ;
45import lombok .AllArgsConstructor ;
56import lombok .Data ;
1314@ NoArgsConstructor @ AllArgsConstructor @ Data
1415public class UserDTO implements Serializable {
1516
17+ @ Null (message = "Id cannot be set" )
1618 private String id ;
1719
20+ @ Email (message = "invalid email" )
21+ @ NotNull (message = "email cannot be empty" )
1822 private String email ;
1923
24+ @ NotNull (message = "Password cannot be empty" )
25+ @ Max (value = 6 ,message = "Password must have minimum of 6 characters" )
26+ @ NotNull (message = "Password cannot be null" )
2027 private String password ;
2128
29+
30+ @ Pattern (regexp = "[A-za-z ]+" ,message = "Invalid Name format" )
2231 private String fullName ;
2332}
You can’t perform that action at this time.
0 commit comments