File tree Expand file tree Collapse file tree 6 files changed +25
-12
lines changed
src/main/java/lk/ijse/dep/note Expand file tree Collapse file tree 6 files changed +25
-12
lines changed Original file line number Diff line number Diff line change 8888 <orderEntry type =" library" scope =" TEST" name =" Maven: org.springframework:spring-test:5.3.21" level =" project" />
8989 <orderEntry type =" library" name =" Maven: org.modelmapper.extensions:modelmapper-spring:3.1.0" level =" project" />
9090 <orderEntry type =" library" name =" Maven: org.modelmapper:modelmapper:3.1.0" level =" project" />
91- <orderEntry type =" library" name =" Maven: org.hibernate.validator:hibernate-validator:6.2.3 .Final" level =" project" />
92- <orderEntry type =" library" name =" Maven: jakarta .validation:jakarta. validation-api:2.0.2 " level =" project" />
91+ <orderEntry type =" library" name =" Maven: org.hibernate.validator:hibernate-validator:6.0.0 .Final" level =" project" />
92+ <orderEntry type =" library" name =" Maven: javax .validation:validation-api:2.0.0.Final " level =" project" />
9393 </component >
9494</module >
Original file line number Diff line number Diff line change 104104 <dependency >
105105 <groupId >org.hibernate.validator</groupId >
106106 <artifactId >hibernate-validator</artifactId >
107- <version >6.2.3 .Final</version >
107+ <version >6.0.0 .Final</version >
108108 </dependency >
109109
110110
Original file line number Diff line number Diff line change 1111@ RestControllerAdvice
1212public class GlobalExceptionHandler {
1313
14+ @ ResponseStatus (HttpStatus .CONFLICT )
1415 @ ExceptionHandler (DuplicateEmailException .class )
15- public void handleDuplicateEmailexception (DuplicateEmailException e ){
16+ public String handleDuplicateEmailexception (DuplicateEmailException e ){
1617 e .initCause ( new ResponseStatusException (HttpStatus .CONFLICT ,e .getMessage ()));
18+ return e .getMessage ();
1719 }
20+ @ ResponseStatus (HttpStatus .NOT_FOUND )
1821 @ ExceptionHandler (NotFoundException .class )
19- public void handleNotfoundExcpetion (NotFoundException e ){
22+ public String handleNotfoundExcpetion (NotFoundException e ){
2023 e .initCause (new ResponseStatusException (HttpStatus .NOT_FOUND ,e .getMessage ()));
24+ return e .getMessage ();
2125 }
2226}
Original file line number Diff line number Diff line change 11package lk .ijse .dep .note .api ;
22
3- import jakarta .validation .Valid ;
3+ import javax .validation .Valid ;
44import lk .ijse .dep .note .dto .UserDTO ;
55import lk .ijse .dep .note .service .UserService ;
66import lk .ijse .dep .note .service .exception .DuplicateEmailException ;
77import lk .ijse .dep .note .service .exception .NotFoundException ;
88import org .springframework .beans .factory .annotation .Autowired ;
99import org .springframework .http .HttpStatus ;
10+ import org .springframework .validation .annotation .Validated ;
1011import org .springframework .web .bind .annotation .*;
1112import org .springframework .web .server .ResponseStatusException ;
1213
1314@ RestController
1415@ RequestMapping ("api/v1/users" )
16+ @ Validated
1517public class UserController {
1618
1719 @ Autowired
Original file line number Diff line number Diff line change 1111import org .springframework .core .env .PropertiesPropertySource ;
1212import org .springframework .core .io .ClassPathResource ;
1313import org .springframework .stereotype .Component ;
14+ import org .springframework .validation .beanvalidation .LocalValidatorFactoryBean ;
1415import org .springframework .web .servlet .config .annotation .EnableWebMvc ;
1516
1617import java .util .Properties ;
2223public class WebAppConfig {
2324
2425
26+ @ Bean
27+ public LocalValidatorFactoryBean localValidatorFactoryBean () {
28+ return new LocalValidatorFactoryBean ();
29+ }
2530
2631 @ Bean
27- public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer (){
28- return new PropertySourcesPlaceholderConfigurer ();
32+ public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer () {
33+ return new PropertySourcesPlaceholderConfigurer ();
2934
3035 }
36+
3137 @ Bean
32- public ObjectMapper objectMapper (){
33- return new ObjectMapper ();
38+ public ObjectMapper objectMapper () {
39+ return new ObjectMapper ();
3440 }
3541}
Original file line number Diff line number Diff line change 11package lk .ijse .dep .note .dto ;
22
3- import jakarta .validation .constraints .*;
3+ import javax .validation .constraints .*;
44import lk .ijse .dep .note .entity .SuperEntity ;
55import lombok .AllArgsConstructor ;
66import lombok .Data ;
77import lombok .NoArgsConstructor ;
8+ import org .hibernate .validator .constraints .Length ;
89
910import javax .persistence .Column ;
1011import javax .persistence .Entity ;
@@ -22,7 +23,7 @@ public class UserDTO implements Serializable {
2223 private String email ;
2324
2425 @ NotNull (message = "Password cannot be empty" )
25- @ Max ( value = 6 ,message = "Password must have minimum of 6 characters" )
26+ @ Length ( max = 6 ,message = "Password must have minimum of 6 characters" )
2627 @ NotNull (message = "Password cannot be null" )
2728 private String password ;
2829
You can’t perform that action at this time.
0 commit comments