From f3fc555e6463c420eed5337662a839723a842b1b Mon Sep 17 00:00:00 2001
From: Juan Pablo Dealbera <80698781+juanpid2112@users.noreply.github.com>
Date: Wed, 23 Oct 2024 10:36:51 -0300
Subject: [PATCH 1/2] Avances sobre Prioridad Proyecto
Creacion del modelo
Creacion del repository
Creacion del service
Creacion del DTO
Creacion del Mapper
Creacion del GlobalExceptionHandler
Creacion de las distintas exceptions
---
pom.xml | 10 ++
.../management/DTO/PrioridadProyectoDTO.java | 15 +++
.../management/exception/ApiResponse.java | 16 +++
.../exception/BadRequestException.java | 16 +++
.../exception/ConflictException.java | 11 ++
.../exception/ForbiddenException.java | 11 ++
.../exception/GlobalExceptionHandler.java | 93 ++++++++++++++
.../exception/GlobalExceptionHandler.java~ | 94 ++++++++++++++
.../exception/NotFoundException.java | 11 ++
.../management/exception/ResponseService.java | 31 +++++
.../exception/UnauthorizedException.java | 12 ++
.../mapper/PrioridadProyectoMapper.java | 21 ++++
.../management/model/PrioridadProyecto.java | 34 ++++++
.../PrioridadProyectoRepository.java | 33 +++++
.../service/IPrioridadProyectoService.java | 35 ++++++
.../service/PrioridadProyectoService.java | 115 ++++++++++++++++++
16 files changed, 558 insertions(+)
create mode 100644 src/main/java/com/example/project/management/DTO/PrioridadProyectoDTO.java
create mode 100644 src/main/java/com/example/project/management/exception/ApiResponse.java
create mode 100644 src/main/java/com/example/project/management/exception/BadRequestException.java
create mode 100644 src/main/java/com/example/project/management/exception/ConflictException.java
create mode 100644 src/main/java/com/example/project/management/exception/ForbiddenException.java
create mode 100644 src/main/java/com/example/project/management/exception/GlobalExceptionHandler.java
create mode 100644 src/main/java/com/example/project/management/exception/GlobalExceptionHandler.java~
create mode 100644 src/main/java/com/example/project/management/exception/NotFoundException.java
create mode 100644 src/main/java/com/example/project/management/exception/ResponseService.java
create mode 100644 src/main/java/com/example/project/management/exception/UnauthorizedException.java
create mode 100644 src/main/java/com/example/project/management/mapper/PrioridadProyectoMapper.java
create mode 100644 src/main/java/com/example/project/management/model/PrioridadProyecto.java
create mode 100644 src/main/java/com/example/project/management/repository/PrioridadProyectoRepository.java
create mode 100644 src/main/java/com/example/project/management/service/IPrioridadProyectoService.java
create mode 100644 src/main/java/com/example/project/management/service/PrioridadProyectoService.java
diff --git a/pom.xml b/pom.xml
index ad485bc..cc64a73 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,6 +54,16 @@
spring-boot-starter-test
test
+
+ jakarta.persistence
+ jakarta.persistence-api
+
+
+ jakarta.validation
+ jakarta.validation-api
+ 3.0.0
+
+
diff --git a/src/main/java/com/example/project/management/DTO/PrioridadProyectoDTO.java b/src/main/java/com/example/project/management/DTO/PrioridadProyectoDTO.java
new file mode 100644
index 0000000..52a3bd8
--- /dev/null
+++ b/src/main/java/com/example/project/management/DTO/PrioridadProyectoDTO.java
@@ -0,0 +1,15 @@
+package com.example.project.management.DTO;
+
+import com.example.project.management.model.PrioridadProyecto;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+@Data
+public class PrioridadProyectoDTO {
+
+ private Long id;
+ private String prioridad;
+ private LocalDateTime fechaEliminacion;
+
+}
diff --git a/src/main/java/com/example/project/management/exception/ApiResponse.java b/src/main/java/com/example/project/management/exception/ApiResponse.java
new file mode 100644
index 0000000..ab1ccc8
--- /dev/null
+++ b/src/main/java/com/example/project/management/exception/ApiResponse.java
@@ -0,0 +1,16 @@
+package com.example.project.management.exception;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class ApiResponse {
+ private int status; // Código de estado HTTP
+ private String message; // Mensaje de estado (éxito o error)
+ private T data; // Datos relevantes que se devuelven
+ private String errors; // En caso de error, detalles del mismo
+}
+
diff --git a/src/main/java/com/example/project/management/exception/BadRequestException.java b/src/main/java/com/example/project/management/exception/BadRequestException.java
new file mode 100644
index 0000000..919c080
--- /dev/null
+++ b/src/main/java/com/example/project/management/exception/BadRequestException.java
@@ -0,0 +1,16 @@
+package com.example.project.management.exception;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+@ResponseStatus(value = HttpStatus.BAD_REQUEST)
+public class BadRequestException extends RuntimeException {
+ public BadRequestException(String message) {
+ super(message);
+ }
+}
+/*
+* El BadRequestException es una excepcion personalizada que se utiliza para manejar
+* errores de validaciones de datos.
+* Por ejemplo: Cuando un argumento tiene que tener un tipo de dato correcto.
+* */
\ No newline at end of file
diff --git a/src/main/java/com/example/project/management/exception/ConflictException.java b/src/main/java/com/example/project/management/exception/ConflictException.java
new file mode 100644
index 0000000..921c8b0
--- /dev/null
+++ b/src/main/java/com/example/project/management/exception/ConflictException.java
@@ -0,0 +1,11 @@
+package com.example.project.management.exception;
+
+public class ConflictException extends RuntimeException {
+ public ConflictException(String message) {
+ super(message);
+ }
+}
+/*
+* ConflictException se usa para manejar errores de conflictos
+* Por ejemplo: Cuando un recurso ya existe.
+* */
\ No newline at end of file
diff --git a/src/main/java/com/example/project/management/exception/ForbiddenException.java b/src/main/java/com/example/project/management/exception/ForbiddenException.java
new file mode 100644
index 0000000..445030e
--- /dev/null
+++ b/src/main/java/com/example/project/management/exception/ForbiddenException.java
@@ -0,0 +1,11 @@
+package com.example.project.management.exception;
+
+public class ForbiddenException extends RuntimeException {
+ public ForbiddenException(String message) {
+ super(message);
+ }
+}
+/*
+* ForbiddenException sirve para manejar los errores de acceso denegado
+* Por ejemplo: Cuando un usuario no tiene permiso para acceder a un recurso.
+* */
\ No newline at end of file
diff --git a/src/main/java/com/example/project/management/exception/GlobalExceptionHandler.java b/src/main/java/com/example/project/management/exception/GlobalExceptionHandler.java
new file mode 100644
index 0000000..6591f62
--- /dev/null
+++ b/src/main/java/com/example/project/management/exception/GlobalExceptionHandler.java
@@ -0,0 +1,93 @@
+package com.example.project.management.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 org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
+
+@RestControllerAdvice
+public class GlobalExceptionHandler {
+
+ // Manejo de BadRequestException (400)
+ @ExceptionHandler(BadRequestException.class)
+ public ResponseEntity