diff --git a/curriculumsearch/src/main/java/com/roshka/configuration/WebSecurityConfig.java b/curriculumsearch/src/main/java/com/roshka/configuration/WebSecurityConfig.java index 163a8ea..590496e 100644 --- a/curriculumsearch/src/main/java/com/roshka/configuration/WebSecurityConfig.java +++ b/curriculumsearch/src/main/java/com/roshka/configuration/WebSecurityConfig.java @@ -48,9 +48,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { .authorizeRequests() .mvcMatchers("/").authenticated() .mvcMatchers("/home").authenticated() - .mvcMatchers("/cargo*").authenticated() - .mvcMatchers("/convocatoria*").authenticated() - .mvcMatchers("/convocatoria/crear/*").authenticated() + .mvcMatchers("/cargos","/cargos/**").authenticated() + .mvcMatchers("/convocatorias","/convocatorias/**").authenticated() .mvcMatchers("/tecnologias","/tecnologias/**").authenticated() .mvcMatchers("/postulantes","/postulantes/**").authenticated() .mvcMatchers("/edit-user-data").authenticated() diff --git a/curriculumsearch/src/main/java/com/roshka/controller/CargoController.java b/curriculumsearch/src/main/java/com/roshka/controller/CargoController.java index 5626e38..55a5867 100644 --- a/curriculumsearch/src/main/java/com/roshka/controller/CargoController.java +++ b/curriculumsearch/src/main/java/com/roshka/controller/CargoController.java @@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.*; import javax.validation.Valid; @Controller +@RequestMapping("/cargos") public class CargoController { CargoRepository cargoRepo; @@ -25,7 +26,7 @@ public class CargoController { this.cargoRepo = cargoRepo; } - @RequestMapping("/cargos") + @RequestMapping() public String menuCargos(Model model,@RequestParam(required = false) String nombre,@RequestParam(defaultValue = "0")Integer nroPagina) { final Integer CANTIDAD_POR_PAGINA = 10; Pageable page = PageRequest.of(nroPagina,CANTIDAD_POR_PAGINA,Sort.by("id")); @@ -42,7 +43,7 @@ public class CargoController { return "cargos"; } - @RequestMapping(path = {"/cargo","/cargo/{id}"}, method = RequestMethod.GET) + @RequestMapping(path = {"/agregar","/modificar/{id}"}, method = RequestMethod.GET) public String formCargo(Model model,@PathVariable(required = false) Long id) { if(id == null) model.addAttribute("cargo", new Cargo()); @@ -50,7 +51,7 @@ public class CargoController { return "cargo-form"; } - @PostMapping(path = {"/cargo","/cargo/{id}"}) + @PostMapping(path = {"/agregar","/modificar/{id}"}) public String guardarCargo(@Valid @ModelAttribute Cargo cargo, BindingResult result, @PathVariable(required = false) Long id, Model model) { if(result.hasErrors() || (id==null && cargoRepo.existsByNombreIgnoreCase(cargo.getNombre()) )){ model.addAttribute("mismoNombre", true); diff --git a/curriculumsearch/src/main/java/com/roshka/controller/ConvocatoriaController.java b/curriculumsearch/src/main/java/com/roshka/controller/ConvocatoriaController.java index 486438e..c3cb606 100644 --- a/curriculumsearch/src/main/java/com/roshka/controller/ConvocatoriaController.java +++ b/curriculumsearch/src/main/java/com/roshka/controller/ConvocatoriaController.java @@ -11,12 +11,12 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import java.util.Date; +@RequestMapping("/convocatorias") @Controller public class ConvocatoriaController { @@ -29,7 +29,7 @@ public class ConvocatoriaController { this.convoRepo = convoRepo; } - @RequestMapping("/convocatorias") + @RequestMapping() public String menuConvocatorias(Model model,RedirectAttributes redirectAttrs, @RequestParam(required = false) Long cargoId, @RequestParam(required = false) EstadoConvocatoria estado,//1: true, 0: false @@ -48,7 +48,7 @@ public class ConvocatoriaController { return "convocatorias"; } - @RequestMapping("/convocatoria/crear/{id}") + @RequestMapping("/crear/{id}") public String guardarConvocatoriaa(@PathVariable(required = false) Long id,RedirectAttributes redirectAttributes) { for (ConvocatoriaCargo conv:convoRepo.findByCargoId(id)) { if(conv.getEstado()==EstadoConvocatoria.abierto){ @@ -68,36 +68,16 @@ public class ConvocatoriaController { return "redirect:/convocatorias"; } - /* @RequestMapping("/convocatoria/{id}") - public String formConvocatoria(Model model,@PathVariable(required = false) Long id) { - model.addAttribute("cargos", cargoRepo.findAll()); - if(id == null){ - model.addAttribute("convocatoria", new ConvocatoriaCargo()); - model.addAttribute("listaConvocatoria", convoRepo.findAll()); - } - else { - ConvocatoriaCargo cc = convoRepo.getById(id); - cc.setFechaFinS(new SimpleDateFormat("yyyy-MM-dd").format((cc.getFechaFin()))); - cc.setFechaInicioS(new SimpleDateFormat("yyyy-MM-dd").format((cc.getFechaInicio()))); - - model.addAttribute("convocatoria", cc); - model.addAttribute("listaConvocatoria", convoRepo.findAll()); - } - - return "convocatoria-form"; - }*/ - @RequestMapping("/convocatoria/{id}") - public String guardarConvocatoria(@ModelAttribute ConvocatoriaCargo convocatoria, BindingResult result, @PathVariable(required = false) Long id,Model model) { - if(id != null) convocatoria.setId(id); - convocatoria=convoRepo.findByIdConvocatoriaCargo(id); + @RequestMapping("/cerrar/{id}") + public String cerrarConvocatoria( @PathVariable(required = false) Long id) { + + ConvocatoriaCargo convocatoria=convoRepo.getById(id); + if(convocatoria == null || convocatoria.getEstado() == EstadoConvocatoria.cerrado) return "error"; convocatoria.setEstado(EstadoConvocatoria.cerrado); convocatoria.setFechaFin(new Date()); convocatoria.getCargo().setExisteConvocatoria(false); convoRepo.save(convocatoria); - - - return "redirect:/convocatorias"; } } diff --git a/curriculumsearch/src/main/webapp/jsp/cargo-form.jsp b/curriculumsearch/src/main/webapp/jsp/cargo-form.jsp index d129aa6..85ca80f 100644 --- a/curriculumsearch/src/main/webapp/jsp/cargo-form.jsp +++ b/curriculumsearch/src/main/webapp/jsp/cargo-form.jsp @@ -10,7 +10,7 @@