primer commit
This commit is contained in:
commit
a70c16f69d
41
.classpath
Normal file
41
.classpath
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</classpath>
|
||||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/target/
|
||||||
|
*.class
|
||||||
23
.project
Normal file
23
.project
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>proyectos_lapaloma_sb</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
7
.settings/org.eclipse.core.resources.prefs
Normal file
7
.settings/org.eclipse.core.resources.prefs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding//src/main/java=UTF-8
|
||||||
|
encoding//src/main/resources=UTF-8
|
||||||
|
encoding//src/test/java=UTF-8
|
||||||
|
encoding//src/test/resources=UTF-8
|
||||||
|
encoding/<project>=UTF-8
|
||||||
|
encoding/src=UTF-8
|
||||||
9
.settings/org.eclipse.jdt.core.prefs
Normal file
9
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=17
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=17
|
||||||
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
||||||
94
pom.xml
Normal file
94
pom.xml
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>ies.lapaloma.proyectos.sb</groupId>
|
||||||
|
<artifactId>ies_lapaloma_proyectos_sb</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
<description>Demo project for Spring Boot</description>
|
||||||
|
<url/>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>3.4.0</version>
|
||||||
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>local-repo</id>
|
||||||
|
<url>file://${user.home}/.m2/repository</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Dependencia para el acceso a datos (Hibernate, etc.) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>ies.lapaloma.proyectos</groupId>
|
||||||
|
<artifactId>ies_lapaloma_proyectos</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webmvc-ui -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springdoc</groupId>
|
||||||
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
<version>2.8.4</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<exclude>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>23</java.version> <!-- Cambia esto a la versión adecuada -->
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package org.lapaloma.aadd.api.proyectos;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class AppPrincipalSpringBoot {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(AppPrincipalSpringBoot.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.lapaloma.aadd.api.proyectos.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Organización: Virgen de la Paloma
|
||||||
|
Programador: Isidoro Nevares Martín
|
||||||
|
Fecha: 18 feb 2025
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class WebConfig implements WebMvcConfigurer {
|
||||||
|
@Override
|
||||||
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
|
// Permitir acceso desde cualquier dominio
|
||||||
|
registry.addMapping("/**") // Aplica a todos los endpoints
|
||||||
|
.allowedOrigins("*") // Permite solicitudes desde cualquier origen
|
||||||
|
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // Métodos HTTP permitidos
|
||||||
|
.allowedHeaders("*") // Permite cualquier encabezado
|
||||||
|
.allowCredentials(false); // Permite enviar credenciales como cookies, etc.
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,147 @@
|
|||||||
|
package org.lapaloma.aadd.api.proyectos.controlador;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.dao.IOperacionesCRUDMasConsultasEntidad;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.dao.impl.ConceptoDaoJPA;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.exceptions.ProyectosIESException;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.vo.Concepto;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.vo.CursoAcademico;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.vo.Proyecto;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api") // La ruta base de tu API
|
||||||
|
public class ConceptoControlador {
|
||||||
|
|
||||||
|
// Se podría haber preparado para que la implementación fuera inyectada por SpringBoot
|
||||||
|
private final IOperacionesCRUDMasConsultasEntidad<Concepto, Integer> implDaoConcepto = new ConceptoDaoJPA();
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping(value = "/conceptos")
|
||||||
|
public ResponseEntity<List<Concepto>> obtenerListaConceptos() {
|
||||||
|
List<Concepto> listaConceptos = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaConceptos = implDaoConcepto.obtenerListaEntidades();
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaConceptos); // Devuelve 200 OK con la lista de coches
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/concepto/{id}")
|
||||||
|
public ResponseEntity<Concepto> obtenerConcepto( @PathVariable("id") Integer identificador) {
|
||||||
|
Concepto coche= null;
|
||||||
|
try {
|
||||||
|
coche = implDaoConcepto.obtenerEntidadPorID(identificador);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(coche); // Devuelve 200 OK con la lista de coches
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/conceptos/curso/{codCursoAcademico}")
|
||||||
|
public ResponseEntity<List<Concepto>> obtenerConceptosPorCurso(@PathVariable("codCursoAcademico") String codCursoAcademico) {
|
||||||
|
List<Concepto> listaConceptos = null;
|
||||||
|
|
||||||
|
CursoAcademico curso = new CursoAcademico();
|
||||||
|
curso.setCodigo(codCursoAcademico);
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaConceptos = implDaoConcepto.obtenerListaEntidadesPorCursoAcademico(curso);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaConceptos); // Devuelve 200 OK con la lista de Concepto
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/conceptos/proyecto/{idProyecto}")
|
||||||
|
public ResponseEntity<List<Concepto>> obtenerConceptosPorProyecto(@PathVariable("idProyecto") Integer idProyecto) {
|
||||||
|
List<Concepto> listaConceptos = null;
|
||||||
|
|
||||||
|
Proyecto proyecto = new Proyecto();
|
||||||
|
proyecto.setIdentificador(idProyecto);
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaConceptos = implDaoConcepto.obtenerListaEntidadesPorProyecto(proyecto);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaConceptos); // Devuelve 200 OK con la lista de Concepto
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/conceptos/proyecto/{idProyecto}/curso/{codCursoAcademico}")
|
||||||
|
public ResponseEntity<List<Concepto>> obtenerConceptosPorProyectoYCurso(
|
||||||
|
@PathVariable("codCursoAcademico") String codCursoAcademico,
|
||||||
|
@PathVariable("idProyecto") Integer idProyecto) {
|
||||||
|
List<Concepto> listaConceptos = null;
|
||||||
|
|
||||||
|
CursoAcademico curso = new CursoAcademico();
|
||||||
|
curso.setCodigo(codCursoAcademico);
|
||||||
|
|
||||||
|
Proyecto proyecto = new Proyecto();
|
||||||
|
proyecto.setIdentificador(idProyecto);
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaConceptos = implDaoConcepto.obtenerListaEntidadesPorProyectoCurso(proyecto, curso);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaConceptos); // Devuelve 200 OK con la lista de Concepto
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/concepto/{id}")
|
||||||
|
public ResponseEntity<String> eliminarConcepto(@PathVariable("id") int id) {
|
||||||
|
Concepto concepto=new Concepto();
|
||||||
|
concepto.setIdentificador(id);
|
||||||
|
|
||||||
|
try {
|
||||||
|
implDaoConcepto.eliminarEntidad(concepto);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body("Error interno en el servidor"); // Devuelve 500 Internal Server Error si hay un fallo inesperado
|
||||||
|
}
|
||||||
|
return ResponseEntity.status(200).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/concepto")
|
||||||
|
public ResponseEntity<Concepto> crearConcepto(@RequestBody Concepto concepto) {
|
||||||
|
try {
|
||||||
|
implDaoConcepto.insertarEntidad(concepto);
|
||||||
|
return ResponseEntity.status(201).body(concepto); // Devuelve un 201 Created con el Concepto creado
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body(null); // Devuelve 500 si ocurre un error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/concepto/{id}")
|
||||||
|
public ResponseEntity<Concepto> actualizarProyecto(@PathVariable("id") int id, @RequestBody Concepto concepto) {
|
||||||
|
try {
|
||||||
|
concepto.setIdentificador(id); // Asegúrate de que el ID del coche se actualice en el DTO
|
||||||
|
implDaoConcepto.actualizarEntidad(concepto); // Llama al servicio para actualizar el Concepto
|
||||||
|
return ResponseEntity.status(200).body(concepto); // Devuelve el Concepto actualizado con un 200 OK
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body(null); // Devuelve 500 si ocurre un error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package org.lapaloma.aadd.api.proyectos.controlador;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.servlet.view.RedirectView;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Hidden;
|
||||||
|
|
||||||
|
@Hidden
|
||||||
|
@RestController
|
||||||
|
public class ControladorInicio {
|
||||||
|
|
||||||
|
@RequestMapping("/")
|
||||||
|
public RedirectView redirigirASwagger() {
|
||||||
|
// Redirige a Swagger UI
|
||||||
|
return new RedirectView("/swagger-ui/index.html");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,90 @@
|
|||||||
|
package org.lapaloma.aadd.api.proyectos.controlador;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.dao.IOperacionesCRUDEntidad;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.dao.impl.CursoAcademicoDaoJPA;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.exceptions.ProyectosIESException;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.vo.CursoAcademico;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api") // La ruta base de tu API
|
||||||
|
public class CursoAcademicoControlador {
|
||||||
|
|
||||||
|
// Se podría haber preparado para que la implementación fuera inyectada por SpringBoot
|
||||||
|
private final IOperacionesCRUDEntidad<CursoAcademico, String> implDaoCursosAcademicos = new CursoAcademicoDaoJPA();
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping(value = "/cursos")
|
||||||
|
public ResponseEntity<List<CursoAcademico>> obtenerListaCursosAcademicos() {
|
||||||
|
List<CursoAcademico> listaCursoAcademicos = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaCursoAcademicos = implDaoCursosAcademicos.obtenerListaEntidades();
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaCursoAcademicos); // Devuelve 200 OK con la lista de CursoAcademico
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/curso/{codigo}")
|
||||||
|
public ResponseEntity<CursoAcademico> obtenerCursoAcademico( @PathVariable("codigo") String codigo) {
|
||||||
|
CursoAcademico cursoAcademico= null;
|
||||||
|
try {
|
||||||
|
cursoAcademico = implDaoCursosAcademicos.obtenerEntidadPorID(codigo);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(cursoAcademico); // Devuelve 200 OK con la lista de CursoAcademico
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/curso/{codigo}")
|
||||||
|
public ResponseEntity<String> eliminarCursoAcademico(@PathVariable("codigo") String codigoCurso) {
|
||||||
|
CursoAcademico cursoAcademico=new CursoAcademico();
|
||||||
|
cursoAcademico.setCodigo(codigoCurso);
|
||||||
|
|
||||||
|
try {
|
||||||
|
implDaoCursosAcademicos.eliminarEntidad(cursoAcademico);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body("Error interno en el servidor"); // Devuelve 500 Internal Server Error si hay un fallo inesperado
|
||||||
|
}
|
||||||
|
return ResponseEntity.status(200).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/curso")
|
||||||
|
public ResponseEntity<CursoAcademico> crearCursoAcademico(@RequestBody CursoAcademico cursoAcademico) {
|
||||||
|
try {
|
||||||
|
implDaoCursosAcademicos.insertarEntidad(cursoAcademico);
|
||||||
|
return ResponseEntity.status(201).body(cursoAcademico); // Devuelve un 201 Created con el CursoAcademico creado
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body(null); // Devuelve 500 si ocurre un error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/curso/{id}")
|
||||||
|
public ResponseEntity<CursoAcademico> actualizarCursoAcademico(@PathVariable("codigo") String codigoCurso, @RequestBody CursoAcademico cursoAcademico) {
|
||||||
|
try {
|
||||||
|
cursoAcademico.setCodigo(codigoCurso); // Asegúrate de que el codigoCurso
|
||||||
|
implDaoCursosAcademicos.actualizarEntidad(cursoAcademico); // Llama al servicio para actualizar el cursoAcademico
|
||||||
|
return ResponseEntity.status(200).body(cursoAcademico); // Devuelve el cursoAcademico actualizado con un 200 OK
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body(null); // Devuelve 500 si ocurre un error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,146 @@
|
|||||||
|
package org.lapaloma.aadd.api.proyectos.controlador;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.dao.IOperacionesCRUDMasConsultasEntidad;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.dao.impl.GastoDaoJPA;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.exceptions.ProyectosIESException;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.vo.CursoAcademico;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.vo.Gasto;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.vo.Proyecto;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api") // La ruta base de tu API
|
||||||
|
public class GastoControlador {
|
||||||
|
|
||||||
|
// Se podría haber preparado para que la implementación fuera inyectada por SpringBoot
|
||||||
|
private final IOperacionesCRUDMasConsultasEntidad<Gasto, Integer> implDaoGasto = new GastoDaoJPA();
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping(value = "/gastos")
|
||||||
|
public ResponseEntity<List<Gasto>> obtenerListaGastos() {
|
||||||
|
List<Gasto> listaGastos = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaGastos = implDaoGasto.obtenerListaEntidades();
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaGastos); // Devuelve 200 OK con la lista de coches
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/gasto/{id}")
|
||||||
|
public ResponseEntity<Gasto> obtenerGasto( @PathVariable("id") Integer identificador) {
|
||||||
|
Gasto gasto= null;
|
||||||
|
try {
|
||||||
|
gasto = implDaoGasto.obtenerEntidadPorID(identificador);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(gasto); // Devuelve 200 OK con la lista de coches
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/gastos/curso/{codCursoAcademico}")
|
||||||
|
public ResponseEntity<List<Gasto>> obtenerGastosPorCurso(@PathVariable("codCursoAcademico") String codCursoAcademico) {
|
||||||
|
List<Gasto> listaGastos = null;
|
||||||
|
|
||||||
|
CursoAcademico curso = new CursoAcademico();
|
||||||
|
curso.setCodigo(codCursoAcademico);
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaGastos = implDaoGasto.obtenerListaEntidadesPorCursoAcademico(curso);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaGastos); // Devuelve 200 OK con la lista de coches
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/gastos/proyecto/{idProyecto}")
|
||||||
|
public ResponseEntity<List<Gasto>> obtenerGastosPorProyecto(@PathVariable("idProyecto") Integer idProyecto) {
|
||||||
|
List<Gasto> listaGastos = null;
|
||||||
|
|
||||||
|
Proyecto proyecto = new Proyecto();
|
||||||
|
proyecto.setIdentificador(idProyecto);
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaGastos = implDaoGasto.obtenerListaEntidadesPorProyecto(proyecto);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaGastos); // Devuelve 200 OK con la lista de gasto
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/gastos/proyecto/{idProyecto}/curso/{codCursoAcademico}")
|
||||||
|
public ResponseEntity<List<Gasto>> obtenerGastosPorProyectoYCurso(
|
||||||
|
@PathVariable("codCursoAcademico") String codCursoAcademico,
|
||||||
|
@PathVariable("idProyecto") Integer idProyecto) {
|
||||||
|
List<Gasto> listaGastos = null;
|
||||||
|
|
||||||
|
CursoAcademico curso = new CursoAcademico();
|
||||||
|
curso.setCodigo(codCursoAcademico);
|
||||||
|
|
||||||
|
Proyecto proyecto = new Proyecto();
|
||||||
|
proyecto.setIdentificador(idProyecto);
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaGastos = implDaoGasto.obtenerListaEntidadesPorProyectoCurso(proyecto, curso);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaGastos); // Devuelve 200 OK con la lista de gasto
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/gasto/{id}")
|
||||||
|
public ResponseEntity<String> eliminarGasto(@PathVariable("id") Integer idGasto) {
|
||||||
|
Gasto gasto=new Gasto();
|
||||||
|
gasto.setIdentificador(idGasto);
|
||||||
|
|
||||||
|
try {
|
||||||
|
implDaoGasto.eliminarEntidad(gasto);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body("Error interno en el servidor"); // Devuelve 500 Internal Server Error si hay un fallo inesperado
|
||||||
|
}
|
||||||
|
return ResponseEntity.status(200).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/gasto")
|
||||||
|
public ResponseEntity<Gasto> crearGasto(@RequestBody Gasto gasto) {
|
||||||
|
try {
|
||||||
|
implDaoGasto.insertarEntidad(gasto);
|
||||||
|
return ResponseEntity.status(201).body(gasto); // Devuelve un 201 Created con el gasto creado
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body(null); // Devuelve 500 si ocurre un error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/gasto/{id}")
|
||||||
|
public ResponseEntity<Gasto> actualizarGasto(@PathVariable("id") Integer idGasto, @RequestBody Gasto gasto) {
|
||||||
|
try {
|
||||||
|
gasto.setIdentificador(idGasto); // Asegúrate de que el codigoCurso
|
||||||
|
implDaoGasto.actualizarEntidad(gasto); // Llama al servicio para actualizar el gasto
|
||||||
|
return ResponseEntity.status(200).body(gasto); // Devuelve el gasto actualizado con un 200 OK
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body(null); // Devuelve 500 si ocurre un error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,147 @@
|
|||||||
|
package org.lapaloma.aadd.api.proyectos.controlador;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.dao.IOperacionesCRUDMasConsultasEntidad;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.dao.impl.IngresoDaoJPA;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.exceptions.ProyectosIESException;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.vo.CursoAcademico;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.vo.Ingreso;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.vo.Proyecto;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api") // La ruta base de tu API
|
||||||
|
public class IngresoControlador {
|
||||||
|
|
||||||
|
// Se podría haber preparado para que la implementación fuera inyectada por SpringBoot
|
||||||
|
private final IOperacionesCRUDMasConsultasEntidad<Ingreso, Integer> implDaoIngreso = new IngresoDaoJPA();
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping(value = "/ingresos")
|
||||||
|
public ResponseEntity<List<Ingreso>> obtenerListaIngresos() {
|
||||||
|
List<Ingreso> listaIngresos = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaIngresos = implDaoIngreso.obtenerListaEntidades();
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaIngresos); // Devuelve 200 OK con la lista de Ingreso
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/ingreso/{id}")
|
||||||
|
public ResponseEntity<Ingreso> obtenerIngreso( @PathVariable("id") Integer identificador) {
|
||||||
|
Ingreso ingreso= null;
|
||||||
|
try {
|
||||||
|
ingreso = implDaoIngreso.obtenerEntidadPorID(identificador);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(ingreso); // Devuelve 200 OK con la lista de Ingreso
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/ingresos/curso/{codCursoAcademico}")
|
||||||
|
public ResponseEntity<List<Ingreso>> obtenerIngresosPorCurso(@PathVariable("codCursoAcademico") String codCursoAcademico) {
|
||||||
|
List<Ingreso> listaIngresos = null;
|
||||||
|
|
||||||
|
CursoAcademico curso = new CursoAcademico();
|
||||||
|
curso.setCodigo(codCursoAcademico);
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaIngresos = implDaoIngreso.obtenerListaEntidadesPorCursoAcademico(curso);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaIngresos); // Devuelve 200 OK con la lista de Ingreso
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/ingresos/proyecto/{idProyecto}")
|
||||||
|
public ResponseEntity<List<Ingreso>> obtenerIngresosPorProyecto(@PathVariable("idProyecto") Integer idProyecto) {
|
||||||
|
List<Ingreso> listaIngresos = null;
|
||||||
|
|
||||||
|
Proyecto proyecto = new Proyecto();
|
||||||
|
proyecto.setIdentificador(idProyecto);
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaIngresos = implDaoIngreso.obtenerListaEntidadesPorProyecto(proyecto);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaIngresos); // Devuelve 200 OK con la lista de Ingreso
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/ingresos/proyecto/{idProyecto}/curso/{codCursoAcademico}")
|
||||||
|
public ResponseEntity<List<Ingreso>> obtenerIngresosPorProyectoYCurso(
|
||||||
|
@PathVariable("codCursoAcademico") String codCursoAcademico,
|
||||||
|
@PathVariable("idProyecto") Integer idProyecto) {
|
||||||
|
List<Ingreso> listaIngresos = null;
|
||||||
|
|
||||||
|
CursoAcademico curso = new CursoAcademico();
|
||||||
|
curso.setCodigo(codCursoAcademico);
|
||||||
|
|
||||||
|
Proyecto proyecto = new Proyecto();
|
||||||
|
proyecto.setIdentificador(idProyecto);
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaIngresos = implDaoIngreso.obtenerListaEntidadesPorProyectoCurso(proyecto, curso);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaIngresos); // Devuelve 200 OK con la lista de Ingreso
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/ingreso/{id}")
|
||||||
|
public ResponseEntity<String> eliminarIngreso(@PathVariable("id") Integer idIngreso) {
|
||||||
|
Ingreso ingreso=new Ingreso();
|
||||||
|
ingreso.setIdentificador(idIngreso);
|
||||||
|
|
||||||
|
try {
|
||||||
|
implDaoIngreso.eliminarEntidad(ingreso);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body("Error interno en el servidor"); // Devuelve 500 Internal Server Error si hay un fallo inesperado
|
||||||
|
}
|
||||||
|
return ResponseEntity.status(200).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/ingreso")
|
||||||
|
public ResponseEntity<Ingreso> crearIngreso(@RequestBody Ingreso ingreso) {
|
||||||
|
try {
|
||||||
|
implDaoIngreso.insertarEntidad(ingreso);
|
||||||
|
return ResponseEntity.status(201).body(ingreso); // Devuelve un 201 Created con el gasto creado
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body(null); // Devuelve 500 si ocurre un error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/ingreso/{id}")
|
||||||
|
public ResponseEntity<Ingreso> actualizarIngreso(@PathVariable("id") Integer idIngreso, @RequestBody Ingreso ingreso) {
|
||||||
|
try {
|
||||||
|
ingreso.setIdentificador(idIngreso); // Asegúrate de que el codigoCurso
|
||||||
|
implDaoIngreso.actualizarEntidad(ingreso); // Llama al servicio para actualizar el Ingreso
|
||||||
|
return ResponseEntity.status(200).body(ingreso); // Devuelve el Ingreso actualizado con un 200 OK
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body(null); // Devuelve 500 si ocurre un error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,149 @@
|
|||||||
|
package org.lapaloma.aadd.api.proyectos.controlador;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.dao.IOperacionesCRUDMasConsultasEntidad;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.dao.impl.PatrocinadorDaoJPA;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.exceptions.ProyectosIESException;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.vo.CursoAcademico;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.vo.Patrocinador;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.vo.Proyecto;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api") // La ruta base de tu API
|
||||||
|
public class PatrocinadorControlador {
|
||||||
|
|
||||||
|
// Se podría haber preparado para que la implementación fuera inyectada por SpringBoot
|
||||||
|
private final IOperacionesCRUDMasConsultasEntidad<Patrocinador, Integer> implDaoPatrocinador = new PatrocinadorDaoJPA();
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/patrocinador/{id}")
|
||||||
|
public ResponseEntity<Patrocinador> obtenerPatrocinador(@PathVariable("id") Integer idPatrocinador) {
|
||||||
|
Patrocinador patrocinador = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
patrocinador = implDaoPatrocinador.obtenerEntidadPorID(idPatrocinador);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(patrocinador); // Devuelve 200 OK con la lista de patrocinadores
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping(value = "/patrocinadores")
|
||||||
|
public ResponseEntity<List<Patrocinador>> obtenerListaPatrocinadores() {
|
||||||
|
List<Patrocinador> listaPatrocinadores = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaPatrocinadores = implDaoPatrocinador.obtenerListaEntidades();
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaPatrocinadores); // Devuelve 200 OK con la lista de patrocinadores
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/patrocinadores/curso/{codCursoAcademico}")
|
||||||
|
public ResponseEntity<List<Patrocinador>> obtenerPatrocinadoresPorCurso(@PathVariable("codCursoAcademico") String codCursoAcademico) {
|
||||||
|
List<Patrocinador> listaPatrocinadores = null;
|
||||||
|
|
||||||
|
CursoAcademico curso = new CursoAcademico();
|
||||||
|
curso.setCodigo(codCursoAcademico);
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaPatrocinadores = implDaoPatrocinador.obtenerListaEntidadesPorCursoAcademico(curso);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaPatrocinadores); // Devuelve 200 OK con la lista de patrocinadores
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/patrocinadores/proyecto/{idProyecto}")
|
||||||
|
public ResponseEntity<List<Patrocinador>> obtenerPatrocinadoresPorProyecto(@PathVariable("idProyecto") Integer idProyecto) {
|
||||||
|
List<Patrocinador> listaPatrocinadores = null;
|
||||||
|
|
||||||
|
Proyecto proyecto = new Proyecto();
|
||||||
|
proyecto.setIdentificador(idProyecto);
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaPatrocinadores = implDaoPatrocinador.obtenerListaEntidadesPorProyecto(proyecto);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaPatrocinadores); // Devuelve 200 OK con la lista de patrocinadores
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/patrocinadores/proyecto/{idProyecto}/curso/{codCursoAcademico}")
|
||||||
|
public ResponseEntity<List<Patrocinador>> obtenerPatrocinadoresPorProyectoYCurso(
|
||||||
|
@PathVariable("codCursoAcademico") String codCursoAcademico,
|
||||||
|
@PathVariable("idProyecto") Integer idProyecto) {
|
||||||
|
List<Patrocinador> listaPatrocinadores = null;
|
||||||
|
|
||||||
|
CursoAcademico curso = new CursoAcademico();
|
||||||
|
curso.setCodigo(codCursoAcademico);
|
||||||
|
|
||||||
|
Proyecto proyecto = new Proyecto();
|
||||||
|
proyecto.setIdentificador(idProyecto);
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaPatrocinadores = implDaoPatrocinador.obtenerListaEntidadesPorProyectoCurso(proyecto, curso);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaPatrocinadores); // Devuelve 200 OK con la lista de patrocinadors
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@DeleteMapping("/patrocinador/{id}")
|
||||||
|
public ResponseEntity<String> eliminarPatrocinador(@PathVariable("id") int id) {
|
||||||
|
Patrocinador patrocinador=new Patrocinador();
|
||||||
|
patrocinador.setIdentificador(id);
|
||||||
|
|
||||||
|
try {
|
||||||
|
implDaoPatrocinador.eliminarEntidad(patrocinador);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body("Error interno en el servidor"); // Devuelve 500 Internal Server Error si hay un fallo inesperado
|
||||||
|
}
|
||||||
|
return ResponseEntity.status(200).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/patrocinador")
|
||||||
|
public ResponseEntity<Patrocinador> crearPatrocinador(@RequestBody Patrocinador patrocinador) {
|
||||||
|
try {
|
||||||
|
implDaoPatrocinador.insertarEntidad(patrocinador);
|
||||||
|
return ResponseEntity.status(201).body(patrocinador); // Devuelve un 201 Created con el patrocinador creado
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body(null); // Devuelve 500 si ocurre un error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/patrocinador/{id}")
|
||||||
|
public ResponseEntity<Patrocinador> actualizarPatrocinador(@PathVariable("id") int id, @RequestBody Patrocinador patrocinador) {
|
||||||
|
try {
|
||||||
|
patrocinador.setIdentificador(id); // Asegúrate de que el ID del coche se actualice en el DTO
|
||||||
|
implDaoPatrocinador.actualizarEntidad(patrocinador); // Llama al servicio para actualizar el patrocinador
|
||||||
|
return ResponseEntity.status(200).body(patrocinador); // Devuelve el patrocinador actualizado con un 200 OK
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body(null); // Devuelve 500 si ocurre un error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,107 @@
|
|||||||
|
package org.lapaloma.aadd.api.proyectos.controlador;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.dao.IOperacionesCRUDMasConsultasCursoAcademico;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.dao.impl.ProyectoDaoJPA;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.exceptions.ProyectosIESException;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.vo.CursoAcademico;
|
||||||
|
import org.palomafp.dam2.aadd.proyectos.vo.Proyecto;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api") // La ruta base de tu API
|
||||||
|
public class ProyectoControlador {
|
||||||
|
|
||||||
|
// Se podría haber preparado para que la implementación fuera inyectada por SpringBoot
|
||||||
|
private final IOperacionesCRUDMasConsultasCursoAcademico<Proyecto, Integer> implDaoProyecto = new ProyectoDaoJPA();
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping(value = "/proyectos")
|
||||||
|
public ResponseEntity<List<Proyecto>> obtenerListaProyectos() {
|
||||||
|
List<Proyecto> listaProyectos = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaProyectos = implDaoProyecto.obtenerListaEntidades();
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaProyectos); // Devuelve 200 OK con la lista de Proyecto
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/proyecto/{id}")
|
||||||
|
public ResponseEntity<Proyecto> obtenerProyecto( @PathVariable("id") Integer identificador) {
|
||||||
|
Proyecto proyecto= null;
|
||||||
|
try {
|
||||||
|
proyecto = implDaoProyecto.obtenerEntidadPorID(identificador);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(proyecto); // Devuelve 200 OK con la lista de Proyecto
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/proyectos/curso/{codCursoAcademico}")
|
||||||
|
public ResponseEntity<List<Proyecto>> obtenerProyectosPorCurso(@PathVariable("codCursoAcademico") String codCursoAcademico) {
|
||||||
|
List<Proyecto> listaProyectos = null;
|
||||||
|
|
||||||
|
CursoAcademico curso = new CursoAcademico();
|
||||||
|
curso.setCodigo(codCursoAcademico);
|
||||||
|
|
||||||
|
try {
|
||||||
|
listaProyectos = implDaoProyecto.obtenerListaEntidadesPorCursoAcademico(curso);
|
||||||
|
} catch (ProyectosIESException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).build(); // Devuelve 500 Internal Server Error en caso de excepción
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(listaProyectos); // Devuelve 200 OK con la lista de Proyecto
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/proyecto/{id}")
|
||||||
|
public ResponseEntity<String> eliminarProyecto(@PathVariable("id") int id) {
|
||||||
|
Proyecto proyecto=new Proyecto();
|
||||||
|
proyecto.setIdentificador(id);
|
||||||
|
|
||||||
|
try {
|
||||||
|
implDaoProyecto.eliminarEntidad(proyecto);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body("Error interno en el servidor"); // Devuelve 500 Internal Server Error si hay un fallo inesperado
|
||||||
|
}
|
||||||
|
return ResponseEntity.status(200).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/proyecto")
|
||||||
|
public ResponseEntity<Proyecto> crearProyecto(@RequestBody Proyecto proyecto) {
|
||||||
|
try {
|
||||||
|
implDaoProyecto.insertarEntidad(proyecto);
|
||||||
|
return ResponseEntity.status(201).body(proyecto); // Devuelve un 201 Created con el Proyecto creado
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body(null); // Devuelve 500 si ocurre un error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/proyecto/{id}")
|
||||||
|
public ResponseEntity<Proyecto> actualizarProyecto(@PathVariable("id") int id, @RequestBody Proyecto proyecto) {
|
||||||
|
try {
|
||||||
|
proyecto.setIdentificador(id); // Asegúrate de que el ID del coche se actualice en el DTO
|
||||||
|
implDaoProyecto.actualizarEntidad(proyecto); // Llama al servicio para actualizar el Proyecto
|
||||||
|
return ResponseEntity.status(200).body(proyecto); // Devuelve el Proyecto actualizado con un 200 OK
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500).body(null); // Devuelve 500 si ocurre un error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
10
src/main/resources/application.properties
Normal file
10
src/main/resources/application.properties
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Este es el nombre de la aplicación
|
||||||
|
spring.application.name=ies_lapaloma_proyectos
|
||||||
|
|
||||||
|
# Puerto sobre el que correrá Tomcat.
|
||||||
|
server.port=4455
|
||||||
|
|
||||||
|
# Configuración de logs
|
||||||
|
logging.file.name=/var/log/ies_lapaloma_proyectos.log
|
||||||
|
logging.level.org.springframework=INFO
|
||||||
|
logging.level.org.lapaloma=DEBUG
|
||||||
Loading…
Reference in New Issue
Block a user