-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
91 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...api/springdoc/SpringDocConfiguration.java → ...entapi/config/SpringDocConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/com/api/notemanagementapi/exception/SQLException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.api.notemanagementapi.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
import java.sql.SQLIntegrityConstraintViolationException; | ||
|
||
@RestControllerAdvice | ||
public class SQLException { | ||
//Validaciones al registrarse (username duplicado en la base de datos) | ||
@ExceptionHandler(SQLIntegrityConstraintViolationException.class) | ||
public ResponseEntity captureSQLIntegrityConstraintViolationException | ||
(SQLIntegrityConstraintViolationException e){ | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Message: " | ||
.concat("Uno o más de los datos enviados ya existen, pruebe con otros.")); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/api/notemanagementapi/exception/ValidationDtoException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.api.notemanagementapi.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.http.converter.HttpMessageNotReadableException; | ||
import org.springframework.validation.FieldError; | ||
import org.springframework.web.bind.MethodArgumentNotValidException; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@RestControllerAdvice | ||
public class ValidationDtoException{ | ||
//Validaciones al registrarse-> entrada de datos vacios o nulos | ||
@ExceptionHandler(MethodArgumentNotValidException.class) | ||
public ResponseEntity captureMethodArgumentNotValidException | ||
(MethodArgumentNotValidException e){ | ||
List<String> errors = e | ||
.getBindingResult() | ||
.getFieldErrors() | ||
.stream().map( FieldError ::getDefaultMessage) | ||
.collect(Collectors.toList()); | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Message: ".concat(errors.toString())); | ||
} | ||
|
||
//Formato JSON recibido | ||
@ExceptionHandler( HttpMessageNotReadableException.class) | ||
public ResponseEntity captureHttpMessageNotReadableException | ||
(HttpMessageNotReadableException e){ | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST) | ||
.body("Message: ".concat(e.getMessage())); | ||
} | ||
//Parametro de json no permitido | ||
@ExceptionHandler( IllegalArgumentException.class) | ||
public ResponseEntity captureHttpMessageNotReadableException | ||
(IllegalArgumentException e){ | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST) | ||
.body("Message: ".concat("Uno de los parámetros enviados no es permitido")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#Database configuration | ||
profile.active=prod | ||
spring.jpa.hibernate.ddl-auto=${SPRING_JPA_HIBERNATE_DDL_AUTO} | ||
spring.datasource.url= ${SPRING_DATASOURCE_URL} | ||
spring.datasource.username= ${SPRING_DATASOURCE_USERNAME} | ||
spring.datasource.password= ${SPRING_DATASOURCE_PASSWORD} | ||
#JWT | ||
jwt.time.expiration = ${JWT_TIME_EXPIRATION} | ||
jwt.secret.key = ${JWT_SECRET_KEY} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
#Database configuration | ||
spring.jpa.hibernate.ddl-auto=${SPRING_JPA_HIBERNATE_DDL_AUTO} | ||
spring.datasource.url= ${SPRING_DATASOURCE_URL} | ||
spring.datasource.username= ${SPRING_DATASOURCE_USERNAME} | ||
spring.datasource.password= ${SPRING_DATASOURCE_PASSWORD} | ||
spring.jpa.hibernate.ddl-auto=create-drop | ||
spring.datasource.url= jdbc:mysql://localhost:3306/school | ||
spring.datasource.username= root | ||
spring.datasource.password= | ||
#JWT | ||
jwt.secret.key = ${JWT_SECRET_KEY} | ||
jwt.time.expiration = ${JWT_TIME_EXPIRATION} | ||
jwt.time.expiration = 86400000 | ||
jwt.secret.key = 76397924423F4528482B4D6251655468576D5A7134743777217A25432A46294A |