Commit 52078ec2 by Joel Florentin

listar tecnologias existentes

parent 2c98ce83
......@@ -57,6 +57,12 @@
<artifactId>hibernate-validator</artifactId>
<version>6.0.13.Final</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
......
......@@ -6,11 +6,13 @@ import javax.validation.ConstraintViolationException;
import com.roshka.modelo.Postulante;
import com.roshka.repositorio.PostulanteRepository;
import com.roshka.repositorio.TecnologiaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.*;
......@@ -20,19 +22,28 @@ public class PostulanteController {
@Autowired
PostulanteRepository post;
@Autowired
TecnologiaRepository tecRepo;
@RequestMapping("/")
public String index() {
return "index";
}
@RequestMapping("/postulante")
public String getFormPostulante(){
public String getFormPostulante(Model model){
model.addAttribute("tecnologias", tecRepo.findAll());
return "postulante-form";
}
@PostMapping(value = "/postulante",consumes = "application/json")
public String guardarPostulante(@RequestBody Postulante postulante){
//se obtiene referencia de todas las tecnologias existentes
postulante.getTecnologias().stream().filter(
tec -> tec.getTecnologia().getId() != 0
).forEach(
tec -> tec.setTecnologia(tecRepo.getById(tec.getTecnologia().getId()))
);
post.save(postulante);
return "redirect:/";
}
......
......@@ -9,13 +9,15 @@ import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import com.fasterxml.jackson.annotation.JsonBackReference;
@Entity
@Table(name="postulante_tecnologia")
@Table(name="postulante_tecnologia",
uniqueConstraints=@UniqueConstraint(columnNames={"postulante_id", "tecnologia_id"}))
public class PostulanteTecnologia {
@Id
......@@ -27,7 +29,7 @@ public class PostulanteTecnologia {
@Min(value = 1)
@Max(value = 5)
private Long nivel;
@ManyToOne(cascade = CascadeType.PERSIST)
@ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE},optional = false)
@JoinColumn
private Tecnologia tecnologia;
......
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
spring.sql.init.mode=always
spring.sql.init.platform=postgres
......
......@@ -56,10 +56,11 @@ function agregarFieldTecnologia(){
pairs[name] = value
}
tecnologias[cont_tecnologia]={}
tecnologias[cont_tecnologia]["tecnologia"]={nombre: pairs.nombre}
tecnologias[cont_tecnologia]["tecnologia"]=pairs["tecnologia-id"]=="-1"?{nombre: pairs["tecnologia-nombre"]}:{id: pairs["tecnologia-id"],nombre:document.querySelector('option[value="'+pairs["tecnologia-id"]+'"]').innerHTML}
tecnologias[cont_tecnologia]["nivel"]=pairs.nivel
//tecnologias[cont_tecnologia] = pairs;
formtecn.reset();
document.querySelector("#tecnologia-nombre").classList.add('d-none')
//imprimir lista actualizada
const div = document.querySelector("#tecnologias")
const div1 = document.createElement('div');
......@@ -149,4 +150,6 @@ form.addEventListener("submit",(evt)=>{
}
});
evt.preventDefault();
} );
\ No newline at end of file
} );
document.querySelector("#btn-new-tech").addEventListener('click',()=>{document.querySelector("#tecnologia-nombre").classList.remove('d-none')})
\ No newline at end of file
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="en">
<head>
......@@ -158,8 +161,19 @@
</div>
<div class="modal-body">
<form name="tecnologia-form">
<label for="nombre" class="form-label">Nombre</label>
<input type="text" class="form-control" name="nombre" id="nombre" >
<label for="tecnologia-nombre" class="form-label">Tecnologia</label>
<div class="input-group mb-3">
<select class="form-select" name="tecnologia-id" aria-label="Default select example">
<option value="-1" selected>Open this select menu</option>
<c:forEach items="${tecnologias}" var="tecnologia">
<option value="${tecnologia.id}">${tecnologia.nombre}</option>
</c:forEach>
</select>
<button class="btn btn-outline-secondary" type="button" id="btn-new-tech">Agregar nuevo</button>
</div>
<input type="text" class="form-control d-none" name="tecnologia-nombre" id="tecnologia-nombre" >
<label for="nivel" class="form-label">Nivel</label>
<input type="number" class="form-control" name="nivel" id="nivel" >
</form>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment