Validacion en back tmb

parent 2f4802c5
...@@ -46,7 +46,8 @@ import org.springframework.ui.Model; ...@@ -46,7 +46,8 @@ import org.springframework.ui.Model;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.servlet.view.RedirectView;
@Controller @Controller
...@@ -144,8 +145,9 @@ public class PostulanteController { ...@@ -144,8 +145,9 @@ public class PostulanteController {
} }
@PostMapping(value = "/postulante",consumes = "application/json") @PostMapping(value = "/postulante",consumes = "application/json")
public String guardarPostulante(@RequestBody Postulante postulante){ public RedirectView guardarPostulante(@RequestBody Postulante postulante, RedirectAttributes redirectAttributes){
//Codigo encargado de modificar postulacion si se envia mismo CI //Codigo encargado de modificar postulacion si se envia mismo CI
RedirectView redirectView = new RedirectView("/postulacion-correcta",true);
Postulante postulantex = post.findByNroDocument(postulante.getnroDocument()); Postulante postulantex = post.findByNroDocument(postulante.getnroDocument());
if(postulantex != null){ if(postulantex != null){
estudioRepository.findByPostulante(postulantex).forEach(x -> estudioRepository.delete(x)); estudioRepository.findByPostulante(postulantex).forEach(x -> estudioRepository.delete(x));
...@@ -153,11 +155,8 @@ public class PostulanteController { ...@@ -153,11 +155,8 @@ public class PostulanteController {
postulanteTecnologiaRepository.findByPostulante(postulantex).forEach(x -> postulanteTecnologiaRepository.delete(x)); postulanteTecnologiaRepository.findByPostulante(postulantex).forEach(x -> postulanteTecnologiaRepository.delete(x));
postulante.setId(postulantex.getId()); postulante.setId(postulantex.getId());
} }
postulante.getTecnologias().stream().filter( postulante.getTecnologias().stream().filter(tec -> tec.getTecnologia().getId() != 0)
tec -> tec.getTecnologia().getId() != 0 .forEach(tec -> tec.setTecnologia(tecRepo.getById(tec.getTecnologia().getId())));
).forEach(
tec -> tec.setTecnologia(tecRepo.getById(tec.getTecnologia().getId()))
);
/* for (int i = 0; i < postulante.getPostulaciones().size(); i++) { /* for (int i = 0; i < postulante.getPostulaciones().size(); i++) {
postulante.getPostulaciones().set(i, cargoRepo.getById(postulante.getPostulaciones().get(i).getId())); postulante.getPostulaciones().set(i, cargoRepo.getById(postulante.getPostulaciones().get(i).getId()));
} }
...@@ -173,8 +172,13 @@ public class PostulanteController { ...@@ -173,8 +172,13 @@ public class PostulanteController {
estudio.setInstitucion(institucion); estudio.setInstitucion(institucion);
} }
} }
if(postulante.getPostulaciones().isEmpty() || postulante.getTecnologias().isEmpty()){
redirectView.setUrl("/postulante");
redirectAttributes.addFlashAttribute("error", "Datos invalidos");
return redirectView;
}
post.save(postulante); post.save(postulante);
return "redirect:/postulacion-correcta"; return redirectView;
} }
@GetMapping("/postulacion-correcta") @GetMapping("/postulacion-correcta")
......
...@@ -245,7 +245,6 @@ async function postData(url = '', data = {}) { ...@@ -245,7 +245,6 @@ async function postData(url = '', data = {}) {
} }
senddata["headers"][headerxs] = token; senddata["headers"][headerxs] = token;
let response = null let response = null
console.log(noValidateFlag)
if(!noValidateFlag){ if(!noValidateFlag){
response = await fetch(url, senddata); response = await fetch(url, senddata);
} }
......
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