Skip to content

Commit

Permalink
Cambios en el controlador que utilizan la BBDD
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbh committed Mar 12, 2021
1 parent 1b9d186 commit e55a9aa
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/main/java/org/tecnificados/boot/WebSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.tecnificados.boot.controller.StartController;


/**
Expand All @@ -27,11 +28,16 @@
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/login", "/resources/**").permitAll()
.antMatchers(StartController.DEFAULT,
StartController.ADD,
StartController.EMPTY,
"/login",
"/resources/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,81 @@
*/
package org.tecnificados.boot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.tecnificados.boot.model.Incidencia;
import org.tecnificados.boot.service.IncidenciaService;

/**
* @author Juan Carlos Ballesteros (tecnificados.com)
*
*/
@Controller
public class StartController {

@RequestMapping("/")
public String mensaje() {

return "index";
}

public static final String EMPTY = "/empty";
public static final String ADD = "/add";
public static final String DEFAULT = "/";


@Autowired
private IncidenciaService personaService;

@RequestMapping(DEFAULT)
public ModelAndView index() {

List<Incidencia> list = personaService.getAll();

ModelAndView model = new ModelAndView();
model.addObject("list", list);

model.setViewName("index");

return model;
}


@RequestMapping(ADD)
@ResponseBody
public String add() {


Long id=personaService.maxId()+1;

Incidencia incidencia = new Incidencia();
incidencia.setId(id);
incidencia.setAutor("Juan Carlos");
incidencia.setTitulo("Incidencia "+incidencia.getId());
incidencia.setDescripcion("La aplicación no arranca");
incidencia.setEstado(0);

personaService.save(incidencia);


return "added";
}


@RequestMapping(EMPTY)
@ResponseBody
public String empty() {


List<Incidencia> list = personaService.getAll();

for (Incidencia p:list)
{
personaService.delete(p.getId());
}




return "empty";
}
}

0 comments on commit e55a9aa

Please sign in to comment.