Commit d6b0b79d by Joel Florentin

se unificaron los path de todos los controllers

parent a355ef3d
......@@ -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()
......
......@@ -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);
......
......@@ -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("/cerrar/{id}")
public String cerrarConvocatoria( @PathVariable(required = false) Long id) {
@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);
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";
}
}
......@@ -10,7 +10,7 @@
<h5>Cargo</h5>
</div>
<form:form
action="/cargo/${cargo.id == null ? '' : cargo.id}"
action="/cargos/${cargo.id == null ? 'agregar' : 'modificar/'.concat(cargo.id)}"
method="post"
modelAttribute="cargo"
class="d-flex flex-column"
......
......@@ -50,10 +50,10 @@ contentType="text/html;charset=UTF-8" language="java" %>
>Ver Convocatorias</a
>
</td>
<td><a href="/cargo/${cargo.id}">Editar cargo</a></td>
<td><a href="/cargos/modificar/${cargo.id}">Editar cargo</a></td>
<td>
<c:if test="${!cargo.isExisteConvocatoria()}">
<a class="btn btn-secondary" href="/convocatoria/crear/${cargo.id}">Abrir Convocatoria</a>
<a class="btn btn-secondary" href="/convocatorias/crear/${cargo.id}">Abrir Convocatoria</a>
</c:if>
</td>
</tr>
......
......@@ -92,7 +92,7 @@
<td><a href="/postulantes?convId=${convocatoria.id}">Ver postulantes</a></td>
<td>
<c:if test="${convocatoria.getEstado() != 'cerrado'}">
<a class="btn btn-secondary" href="/convocatoria/${convocatoria.id}">Cerrar convocatoria</a>
<a class="btn btn-secondary" href="/convocatorias/cerrar/${convocatoria.id}">Cerrar convocatoria</a>
</c:if>
</td>
</tr>
......
......@@ -38,7 +38,7 @@
Cargos
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="/cargo">Agregar Cargo</a></li>
<li><a class="dropdown-item" href="/cargos/agregar">Agregar Cargo</a></li>
<li><a class="dropdown-item" href="/cargos">Listar cargos</a></li>
<li><a class="dropdown-item" href="/convocatorias">Listar convocatorias</a></li>
</ul>
......
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