Browse Source

Proyecto Tienda

master
Ivan 1 year ago
parent
commit
d4b6eab809
62 changed files with 13729 additions and 317 deletions
  1. +97
    -7
      pom.xml
  2. +0
    -3
      src/main/java/com/ims/rallyModels/RallyModelsApplication.java
  3. +25
    -0
      src/main/java/com/ims/rallyModels/controlador/FilesController.java
  4. +52
    -0
      src/main/java/com/ims/rallyModels/controlador/LoginControlador.java
  5. +222
    -22
      src/main/java/com/ims/rallyModels/controlador/MaquetaControlador.java
  6. +72
    -0
      src/main/java/com/ims/rallyModels/controlador/RegistroControlador.java
  7. +32
    -0
      src/main/java/com/ims/rallyModels/controlador/UploadController.java
  8. +0
    -20
      src/main/java/com/ims/rallyModels/controlador/UsuarioControlador.java
  9. +61
    -0
      src/main/java/com/ims/rallyModels/dtu/UsuarioRegistroDTU.java
  10. +5
    -0
      src/main/java/com/ims/rallyModels/modelo/CocheEntity.java
  11. +35
    -0
      src/main/java/com/ims/rallyModels/modelo/CompraEntity.java
  12. +84
    -12
      src/main/java/com/ims/rallyModels/modelo/MaquetaEntity.java
  13. +97
    -0
      src/main/java/com/ims/rallyModels/modelo/UserModel.java
  14. +36
    -6
      src/main/java/com/ims/rallyModels/modelo/UsuarioEntity.java
  15. +104
    -0
      src/main/java/com/ims/rallyModels/reportes/FacturaExporterExcel.java
  16. +87
    -0
      src/main/java/com/ims/rallyModels/reportes/FacturaExporterPDF.java
  17. +9
    -0
      src/main/java/com/ims/rallyModels/repositorio/ICocheRepositorio.java
  18. +9
    -0
      src/main/java/com/ims/rallyModels/repositorio/ICompeticionRepositorio.java
  19. +4
    -3
      src/main/java/com/ims/rallyModels/repositorio/ICompraRepositorio.java
  20. +9
    -1
      src/main/java/com/ims/rallyModels/repositorio/IMaquetasRepositorio.java
  21. +12
    -0
      src/main/java/com/ims/rallyModels/repositorio/IUserRepository.java
  22. +55
    -0
      src/main/java/com/ims/rallyModels/security/SecurityConfig.java
  23. +0
    -11
      src/main/java/com/ims/rallyModels/servicio/IUsuarioServicio.java
  24. +58
    -0
      src/main/java/com/ims/rallyModels/servicio/UserDetailsImpl.java
  25. +41
    -10
      src/main/java/com/ims/rallyModels/servicio/UsuarioServicioImpl.java
  26. +42
    -0
      src/main/java/com/ims/rallyModels/servicio/coche/CocheServicioImpl.java
  27. +20
    -0
      src/main/java/com/ims/rallyModels/servicio/coche/ICocheServicio.java
  28. +40
    -0
      src/main/java/com/ims/rallyModels/servicio/competicion/CompeticionServicioImpl.java
  29. +19
    -0
      src/main/java/com/ims/rallyModels/servicio/competicion/ICompeticionService.java
  30. +71
    -0
      src/main/java/com/ims/rallyModels/servicio/compra/CompraServicioImpl.java
  31. +30
    -0
      src/main/java/com/ims/rallyModels/servicio/compra/ICompraServicio.java
  32. +168
    -0
      src/main/java/com/ims/rallyModels/servicio/img/FileSystemStorageService.java
  33. +20
    -0
      src/main/java/com/ims/rallyModels/servicio/img/StorageProperties.java
  34. +27
    -0
      src/main/java/com/ims/rallyModels/servicio/img/StorageService.java
  35. +6
    -3
      src/main/java/com/ims/rallyModels/servicio/maqueta/IMaquetasServicio.java
  36. +13
    -1
      src/main/java/com/ims/rallyModels/servicio/maqueta/MaquetasServicioImpl.java
  37. +11
    -0
      src/main/java/com/ims/rallyModels/servicio/userMng/IUsuarioServicio.java
  38. +24
    -0
      src/main/java/com/ims/rallyModels/servicio/userMng/UserServImpl.java
  39. +6
    -2
      src/main/resources/application.properties
  40. +43
    -0
      src/main/resources/static/css/shoppingCart.css
  41. +11233
    -74
      src/main/resources/static/css/styles.css
  42. BIN
      src/main/resources/static/raw/HyundaiI20.jpg
  43. BIN
      src/main/resources/static/raw/ToyotaYarisWRC.jpg
  44. BIN
      src/main/resources/static/raw/circLogo.png
  45. BIN
      src/main/resources/static/raw/fordPuma.jpg
  46. BIN
      src/main/resources/static/raw/logo.png
  47. +0
    -56
      src/main/resources/templates/crear_maqueta.html
  48. +31
    -7
      src/main/resources/templates/index.html
  49. +95
    -0
      src/main/resources/templates/login.html
  50. +0
    -76
      src/main/resources/templates/maqueta.html
  51. +57
    -0
      src/main/resources/templates/public/carrito.html
  52. +89
    -0
      src/main/resources/templates/public/crear_maqueta.html
  53. +3
    -3
      src/main/resources/templates/public/editar_maqueta.html
  54. +79
    -0
      src/main/resources/templates/public/factura.html
  55. +7
    -0
      src/main/resources/templates/public/js/scripts.js
  56. +125
    -0
      src/main/resources/templates/public/maqueta.html
  57. +47
    -0
      src/main/resources/templates/public/maqueta_detalle.html
  58. +25
    -0
      src/main/resources/templates/public/register.html
  59. +72
    -0
      src/main/resources/templates/public/usuarios.html
  60. BIN
      src/main/resources/templates/raw/images.jfif
  61. +111
    -0
      src/main/resources/templates/register.html
  62. +9
    -0
      src/main/resources/templates/utils/nav.html

+ 97
- 7
pom.xml View File

@ -17,7 +17,16 @@
<java.version>17</java.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>3.0.0</version>
</dependency>
<!--https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client-->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
@ -31,22 +40,37 @@
<version>6.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
<!-- Temporary explicit version to fix Thymeleaf bug -->
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!---->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
@ -60,11 +84,77 @@
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.librepdf/openpdf -->
<dependency>
<groupId>com.github.librepdf</groupId>
<artifactId>openpdf</artifactId>
<version>1.3.26</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
<!--<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity5
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>-->
<!--
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>6.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>-->
<!---->
<!--<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>-->
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependency>-->
</dependencies>
<build>


+ 0
- 3
src/main/java/com/ims/rallyModels/RallyModelsApplication.java View File

@ -14,9 +14,6 @@ public class RallyModelsApplication implements CommandLineRunner {
SpringApplication.run(RallyModelsApplication.class, args);
}
@Autowired
private IMaquetasRepositorio repositorio;
@Override
public void run(String... args) throws Exception {
/*


+ 25
- 0
src/main/java/com/ims/rallyModels/controlador/FilesController.java View File

@ -0,0 +1,25 @@
package com.ims.rallyModels.controlador;
import com.ims.rallyModels.servicio.img.StorageService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class FilesController {
@Autowired
StorageService storageService;
@GetMapping("/files/{filename:.+}")
@ResponseBody
public ResponseEntity<Resource> serveFile(@PathVariable String filename) {
Resource file = (Resource) storageService.loadAsResource(filename);
return ResponseEntity.ok().body(file);
}
}

+ 52
- 0
src/main/java/com/ims/rallyModels/controlador/LoginControlador.java View File

@ -0,0 +1,52 @@
package com.ims.rallyModels.controlador;
import com.ims.rallyModels.modelo.UsuarioEntity;
import com.ims.rallyModels.repositorio.IUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class LoginControlador {
@Autowired
private IUserRepository iUserRepository;
@GetMapping({"/login"})
public String goToLogin(Model model){
return "login";
}
/*
@Autowired
private IUsuarioRepositorio iUserRepository;
@GetMapping({"/login"})
public String goToLogin(Model model){
return "login";
}
*/
/*
@Autowired
private IUsuarioRepositorio iUsuarioRepositorio;
@GetMapping({"/login"})
public String goToLogin(Model model) {
return "login";
}
@GetMapping({"/"})
public String verPaginaInicio(Model model) {
return "index";
}
@GetMapping("/login/valid")
public String loginValidation(String username) {
UsuarioEntity user = iUsuarioRepositorio.findByName(username);
return "login";
}
*/
}

+ 222
- 22
src/main/java/com/ims/rallyModels/controlador/MaquetaControlador.java View File

@ -1,34 +1,220 @@
package com.ims.rallyModels.controlador;
import com.ims.rallyModels.modelo.CompraEntity;
import com.ims.rallyModels.modelo.MaquetaEntity;
import com.ims.rallyModels.servicio.IMaquetasServicio;
import com.ims.rallyModels.modelo.UserModel;
import com.ims.rallyModels.reportes.FacturaExporterExcel;
import com.ims.rallyModels.reportes.FacturaExporterPDF;
import com.ims.rallyModels.servicio.coche.ICocheServicio;
import com.ims.rallyModels.servicio.competicion.ICompeticionService;
import com.ims.rallyModels.servicio.compra.ICompraServicio;
import com.ims.rallyModels.servicio.img.StorageService;
import com.ims.rallyModels.servicio.maqueta.IMaquetasServicio;
import com.ims.rallyModels.servicio.userMng.IUsuarioServicio;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Controller
@RequestMapping("/public")
public class MaquetaControlador {
/*
@GetMapping({"/","maquetas"})
public String index(){
return "public/maqueta";
}
/*
HTTP GET /users returns all the users in the system.
HTTP GET /users/{id} returns a user by specified id.
HTTP POST /users creates a new user in the system.
@ para path
$ para objetos
? para mensajes
~ para href/frg
*/
@Autowired
private IMaquetasServicio maquetasServicio;
@Autowired
private ICocheServicio cocheServicio;
@Autowired
private ICompeticionService competicionService;
@Autowired
private IUsuarioServicio usuarioServicio;
@Autowired
private ICompraServicio compraServicio;
@Autowired
private IMaquetasServicio servicio;
private StorageService storageService;
@Autowired
private HttpSession session;
private UserModel usuario;
private List<MaquetaEntity> maquetas;
/*
@GetMapping({"/index","/","/maquetas",""})//url path
public String listarMaquetas(Model model) {
return "index";//html path
}*/
@ModelAttribute("carrito")
public List<MaquetaEntity> productosCarrito() {
List<Integer> contenido = (List<Integer>) session.getAttribute("carrito");
return (contenido == null) ? null : maquetasServicio.variosPorId(contenido);
}
@ModelAttribute("total_carrito")
public Double totalCarrito() {
List<MaquetaEntity> productosCarrito = productosCarrito();
if (productosCarrito != null) {
return productosCarrito.stream()
.mapToDouble(p -> p.getPrecio())
.sum();
}
return 0.0;
}
@GetMapping("/carrito")
public String verCarrito(Model model) {
return "public/carrito";
}
@GetMapping("/carrito/add/{id}")
public String addCarrito(Model model, @PathVariable Integer id) {
List<Integer> contenido = (List<Integer>) session.getAttribute("carrito");
if (contenido == null)
contenido = new ArrayList<>();
if (!contenido.contains(id))
contenido.add(id);
session.setAttribute("carrito",contenido);
return "redirect:/public/carrito";
}
@GetMapping({"/maquetas",""})//url path
@GetMapping("/carrito/eliminar/{id}")
public String borrarDelCarrito(Model model, @PathVariable Integer id) {
List<Integer> contenido = (List<Integer>) session.getAttribute("carrito");
if (contenido == null)
return "redirect:/maquetas";
contenido.remove(id);
if (contenido.isEmpty())
session.removeAttribute("carrito");
else
session.setAttribute("carrito",contenido);
return "redirect:/public/carrito";
}
@GetMapping("/carrito/finalizar")
public String finalizarCompra() {
List<Integer> contenido = (List<Integer>) session.getAttribute("carrito");
if (contenido == null)
return "redirect:/maquetas";
List<MaquetaEntity> productos = productosCarrito();
CompraEntity c = compraServicio.insertar(new CompraEntity(),usuario);
productos.forEach(p -> compraServicio.addMaquetaCompra(p,c));
session.removeAttribute("carrito");
return "redirect:/public/compra/factura/"+c.getIdCompra();
}
@GetMapping("/miscompras")
public String verMisCompras(Model model) {
return "/compra/listado";
}
@GetMapping("/compra/factura/{id}")
public String factura(Model model, @PathVariable Integer id, HttpServletResponse response) throws IOException {
/*response.setContentType("application/pdf");
DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
String fechaActual = dateFormatter.format(new Date());
String cabecera = "Content-Disposition";
String valor = "attachment; filename=Compra_"+fechaActual+".pdf";
response.setHeader(cabecera,valor);*/
CompraEntity c = compraServicio.obtenerCompraPorId(id);
List<MaquetaEntity> productos = maquetasServicio.productosDeUnaCompra(c);
maquetas = productos;
//FacturaExporterPDF exporter = new FacturaExporterPDF(productos);
//exporter.exportar(response);
model.addAttribute("productos",productos);
model.addAttribute("compra",c);
model.addAttribute("total_compra", productos.stream()
.mapToDouble(p -> p.getPrecio())
.sum());
return "public/factura";
}
@GetMapping("/exportarPDF/{id}")
public void exportarCompraPDF(HttpServletResponse response, @PathVariable Integer id) throws IOException {
response.setContentType("application/pdf");
DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
String fechaActual = dateFormatter.format(new Date());
String cabecera = "Content-Disposition";
String valor = "attachment; filename=Compra_"+fechaActual+".pdf";
response.setHeader(cabecera,valor);
CompraEntity compra = compraServicio.obtenerCompraPorId(id);
FacturaExporterPDF exporter = new FacturaExporterPDF(maquetas);
exporter.exportar(response);
}
@GetMapping("/exportarExcel/{id}")
public void exportarCompraExcel(HttpServletResponse response, @PathVariable Integer id) throws IOException {
response.setContentType("application/octet-stream");
DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
String fechaActual = dateFormatter.format(new Date());
String cabecera = "Content-Disposition";
String valor = "attachment; filename=Compra_"+fechaActual+".xlsx";
response.setHeader(cabecera,valor);
CompraEntity compra = compraServicio.obtenerCompraPorId(id);
FacturaExporterExcel exporter = new FacturaExporterExcel(maquetas);
exporter.exportar(response);
}
/* @GetMapping("/maquetas/{id}")
public String mostrarMaqueta(Model model, @PathVariable Integer id) {
MaquetaEntity producto = maquetasServicio.obtenerMaquetaPorId(id);
if (producto != null) {
model.addAttribute("producto",producto);
return "/public/maqueta_detalle";//redirect si falla. Pd: se tendrá que cambiar
}
return "redirect:/public/maquetas";
}*/
@GetMapping({"/models","/","/maquetas",""})//url path
public String listarMaquetas(Model model) {
model.addAttribute("maquetas",servicio.listAll());
return "maqueta";//html path
model.addAttribute("maquetas", maquetasServicio.listAll());
return "public/maqueta";//html path
}
@GetMapping({"/maquetas/nuevo"})
@ -36,39 +222,53 @@ public class MaquetaControlador {
//maqueta que le pasaremos al formulario
MaquetaEntity maqueta = new MaquetaEntity();
model.addAttribute("maqueta",maqueta);
return "crear_maqueta";
return "public/crear_maqueta";
}
@PostMapping("/maquetas")
public String guardarMaqueta(@ModelAttribute("maqueta")MaquetaEntity maqueta) {
public String guardarMaqueta(@ModelAttribute("maqueta")MaquetaEntity maqueta/*, @RequestParam("file")MultipartFile file*/) {
/*if (!file.isEmpty()) {
String imagen = storageService.store(file);
maqueta.setImage(MvcUriComponentsBuilder
.fromMethodName(FilesController.class,"serveFile",imagen).build().toUriString());
}*/
//recibimos el objeto que creamos para el formulario
//agregamos métodos útiles a la Interfaz de servicio
servicio.guardarMaqueta(maqueta);
return "redirect:/maquetas";//volvemos a la página inicial
maquetasServicio.guardarMaqueta(maqueta);
return "redirect:/public/maquetas";//volvemos a la página inicial
}
@GetMapping("/maquetas/mostrar/{id}")
public String mostrarMaqueta(@PathVariable Integer id, Model modelo) {
modelo.addAttribute("maqueta", maquetasServicio.obtenerMaquetaPorId(id));
return "/public/maqueta_detalle";
}
@GetMapping("/maquetas/editar/{id}")
public String mostrarFormularioEditar(@PathVariable Integer id, Model modelo) {
modelo.addAttribute("maqueta",servicio.obtenerMaquetaPorId(id));
return "editar_maqueta";
modelo.addAttribute("maqueta", maquetasServicio.obtenerMaquetaPorId(id));
return "public/editar_maqueta";
}
@PostMapping("/maquetas/{id}")
public String actualizarMaqueta(@PathVariable Integer id,
@ModelAttribute("maqueta") MaquetaEntity maqueta,
Model modelo) {
MaquetaEntity maquetaExistente = servicio.obtenerMaquetaPorId(id);
MaquetaEntity maquetaExistente = maquetasServicio.obtenerMaquetaPorId(id);
maquetaExistente.setIdMaqueta(maqueta.getIdMaqueta());
//System.out.println(maquetaExistente.getIdMaqueta()); == 4
maquetaExistente.setDescripcion(maqueta.getDescripcion());
servicio.actualizarMaqueta(maquetaExistente);
maquetasServicio.actualizarMaqueta(maquetaExistente);
return "redirect:/maquetas";
return "redirect:/public/maquetas";
}
@GetMapping("/maquetas/{id}")
@GetMapping("/maquetas/eliminar/{id}")
public String eliminarMaqueta(@PathVariable Integer id) {
servicio.eliminarMaquetas(id);
return "redirect:/maquetas";
maquetasServicio.eliminarMaquetas(id);
return "redirect:/public/maquetas";
}
}

+ 72
- 0
src/main/java/com/ims/rallyModels/controlador/RegistroControlador.java View File

@ -0,0 +1,72 @@
package com.ims.rallyModels.controlador;
import com.ims.rallyModels.modelo.UserModel;
import com.ims.rallyModels.repositorio.IUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@Controller
public class RegistroControlador {
@Autowired
private IUserRepository iUserRepository;
@GetMapping({"/register"})
public String goToregister(Model model){
model.addAttribute("user", new UserModel());
return "register";
}
@PostMapping("/process_register")
public String processRegister(UserModel user) {
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String encodedPassword = passwordEncoder.encode(user.getPassword());
user.setPassword(encodedPassword);
iUserRepository.save(user);
return "login";
}
/*@Autowired
private IUsuarioRepositorio iUsuarioRepositorio;
//@GetMapping
//public String mostrarFormularioRegistro() {
//return "login";
//}
/*
@PostMapping
public String registrarCuentaDeUsuario(@ModelAttribute("usuario") UsuarioRegistroDTU usuario) {
usuarioServicio.guardar(usuario);
//si logramos registrar correctamente se mandará el
//mensaje de éxito al html del registro (l.35)
return "redirect:/register?exito";
}
@GetMapping("security/user")
public String getUser( Model model) {
CustomUserDetails currentUser = (CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UsuarioEntity user = iUsuarioRepositorio.findByNombre(currentUser.getUsername());
model.addAttribute("user", user);
return "security/user";
}
@GetMapping({"/register"})
public String goToregister(Model model){
model.addAttribute("user", new UsuarioEntity());
return "register";
}
@PostMapping("/process_register")
public String processRegister(UsuarioEntity user) {
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String encodedPassword = passwordEncoder.encode(user.getContrasena());
user.setContrasena(encodedPassword);
iUsuarioRepositorio.save(user);
return "index";
}*/
}

+ 32
- 0
src/main/java/com/ims/rallyModels/controlador/UploadController.java View File

@ -0,0 +1,32 @@
package com.ims.rallyModels.controlador;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@Controller
public class UploadController {
public static String UPLOAD_DIRECTORY = System.getProperty("user.dir") + "/uploads";
@GetMapping("/uploadimage") public String displayUploadForm() {
return "redirect:/public/maquetas";
}
@PostMapping("/upload") public String uploadImage(Model model, @RequestParam("image") MultipartFile file) throws IOException {
StringBuilder fileNames = new StringBuilder();
Path fileNameAndPath = Paths.get(UPLOAD_DIRECTORY, file.getOriginalFilename());
fileNames.append(file.getName());
Files.write(fileNameAndPath, file.getBytes());
model.addAttribute("msg", "Uploaded images: " + fileNames.toString());
return "redirect:/public/maquetas";
}
}

+ 0
- 20
src/main/java/com/ims/rallyModels/controlador/UsuarioControlador.java View File

@ -1,20 +0,0 @@
package com.ims.rallyModels.controlador;
import com.ims.rallyModels.servicio.IMaquetasServicio;
import com.ims.rallyModels.servicio.IUsuarioServicio;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
public class UsuarioControlador {
@Autowired
private IUsuarioServicio servicio;
@GetMapping({"/usuarios",""})
public String listarMaquetas(Model model) {
model.addAttribute("usuarios",servicio.listAll());
return "usuarios";
}
}

+ 61
- 0
src/main/java/com/ims/rallyModels/dtu/UsuarioRegistroDTU.java View File

@ -0,0 +1,61 @@
package com.ims.rallyModels.dtu;
public class UsuarioRegistroDTU {
private int idUsuario;
private String nombre;
private String password;
private String sudo;
public UsuarioRegistroDTU(int idUsuario, String nombre, String password, String sudo) {
this.idUsuario = idUsuario;
this.nombre = nombre;
this.password = password;
this.sudo = sudo;
}
public UsuarioRegistroDTU(String nombre, String password, String sudo) {
this.nombre = nombre;
this.password = password;
this.sudo = sudo;
}
public UsuarioRegistroDTU(String nombre) {
this.nombre = nombre;
}
public UsuarioRegistroDTU() {
}
public int getIdUsuario() {
return idUsuario;
}
public void setIdUsuario(int idUsuario) {
this.idUsuario = idUsuario;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getContrasena() {
return password;
}
public void setContrasena(String contrasena) {
this.password = contrasena;
}
public String getSudo() {
return sudo;
}
public void setSudo(String sudo) {
this.sudo = sudo;
}
}

+ 5
- 0
src/main/java/com/ims/rallyModels/modelo/CocheEntity.java View File

@ -19,6 +19,8 @@ public class CocheEntity {
@Column(name = "piloto", nullable = true, length = 45)
private String piloto;
private String image;
public int getIdCoche() {
return idCoche;
}
@ -51,6 +53,9 @@ public class CocheEntity {
this.piloto = piloto;
}
public String getImage() {
return image;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;


+ 35
- 0
src/main/java/com/ims/rallyModels/modelo/CompraEntity.java View File

@ -1,10 +1,16 @@
package com.ims.rallyModels.modelo;
import com.ims.rallyModels.servicio.UserDetailsImpl;
import jakarta.persistence.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
@Entity
@EntityListeners(AuditingEntityListener.class)//para la auto fecha
@Table(name = "compra", schema = "proyecto", catalog = "")
public class CompraEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -24,10 +30,39 @@ public class CompraEntity {
@Column(name = "fk_idMetodos_Pago", nullable = false)
private int fkIdMetodosPago;
@OneToMany
private List<MaquetaEntity> productos;
@ManyToOne
private UserModel usuario;
@ManyToOne
private MetodosPagoEntity metodoPago;
public List<MaquetaEntity> getProductos() {
return productos;
}
public MetodosPagoEntity getMetodoPago() {
return metodoPago;
}
public CompraEntity() {
productos = new ArrayList<>();
usuario = new UserDetailsImpl(usuario).getUser();
}
public UserModel getUsuario() {
return usuario;
}
public int getIdCompra() {
return idCompra;
}
public void setUsuario(UserModel usuario) {
this.usuario = usuario;
}
public void setIdCompra(int idCompra) {
this.idCompra = idCompra;
}


+ 84
- 12
src/main/java/com/ims/rallyModels/modelo/MaquetaEntity.java View File

@ -12,20 +12,74 @@ public class MaquetaEntity {
@Basic
@Column(name = "descripcion", nullable = true, length = 45)
private String descripcion;
@Basic
@Column(name = "precio", nullable = true, precision = 0)
private Double precio;
private String marca;
private String modelo;
private String piloto;
private String image;
@ManyToOne
private CompraEntity compra;
@Basic
@Column(name = "fk_idCompeticion", nullable = false)
private int fkIdCompeticion;
@Basic
@Column(name = "fk_idCoche", nullable = false)
private int fkIdCoche;
@Basic
@Column(name = "precio", nullable = true, precision = 0)
private Double precio;
@ManyToOne
private CompeticionEntity competicion;
public MaquetaEntity() {
}
public MaquetaEntity(String descripcion, Double precio) {
this.descripcion = descripcion;
this.precio = precio;
}
public MaquetaEntity(String descripcion, CompraEntity compra, Double precio) {
this.descripcion = descripcion;
this.compra = compra;
this.precio = precio;
}
public String getMarca() {
return marca;
}
public void setMarca(String marca) {
this.marca = marca;
}
public String getModelo() {
return modelo;
}
public void setModelo(String modelo) {
this.modelo = modelo;
}
public String getPiloto() {
return piloto;
}
public void setPiloto(String piloto) {
this.piloto = piloto;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public void setCompeticion(CompeticionEntity competicion) {
this.competicion = competicion;
}
public int getIdMaqueta() {
return idMaqueta;
}
@ -58,12 +112,32 @@ public class MaquetaEntity {
this.fkIdCompeticion = fkIdCompeticion;
}
public int getFkIdCoche() {
return fkIdCoche;
public CompeticionEntity getCompeticion() {
return competicion;
}
public void setFkIdCoche(int fkIdCoche) {
this.fkIdCoche = fkIdCoche;
public CompraEntity getCompra() {
return compra;
}
public void setCompra(CompraEntity compra) {
this.compra = compra;
}
@Override
public String toString() {
return "MaquetaEntity{" +
"idMaqueta=" + idMaqueta +
", descripcion='" + descripcion + '\'' +
", marca='" + marca + '\'' +
", modelo='" + modelo + '\'' +
", piloto='" + piloto + '\'' +
", image='" + image + '\'' +
", compra=" + compra +
", fkIdCompeticion=" + fkIdCompeticion +
", precio=" + precio +
", competicion=" + competicion +
'}';
}
@Override
@ -75,7 +149,6 @@ public class MaquetaEntity {
if (idMaqueta != that.idMaqueta) return false;
if (fkIdCompeticion != that.fkIdCompeticion) return false;
if (fkIdCoche != that.fkIdCoche) return false;
if (descripcion != null ? !descripcion.equals(that.descripcion) : that.descripcion != null) return false;
if (precio != null ? !precio.equals(that.precio) : that.precio != null) return false;
@ -88,7 +161,6 @@ public class MaquetaEntity {
result = 31 * result + (descripcion != null ? descripcion.hashCode() : 0);
result = 31 * result + (precio != null ? precio.hashCode() : 0);
result = 31 * result + fkIdCompeticion;
result = 31 * result + fkIdCoche;
return result;
}
}

+ 97
- 0
src/main/java/com/ims/rallyModels/modelo/UserModel.java View File

@ -0,0 +1,97 @@
package com.ims.rallyModels.modelo;
import jakarta.persistence.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.util.Date;
import java.util.Objects;
@Entity
@EntityListeners(AuditingEntityListener.class)
public class UserModel {
@Id
@GeneratedValue
private long id;
private String email;
private String password;
private String name;
private String surname;
@CreatedDate
@Temporal(TemporalType.TIMESTAMP)
private Date createdDate;
public UserModel() { }
public UserModel(String name, String surname, String email, String password) {
this.name = name;
this.surname = surname;
this.email = email;
this.password = password;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public String getSurname() {
return surname;
}
public Date getCreatedDate() {
return createdDate;
}
public String getEmail() {
return email;
}
public String getPassword() {
return password;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UserModel user = (UserModel) o;
return id == user.id && email.equals(user.email);
}
@Override
public int hashCode() {
return Objects.hash(id, email);
}
public void setPassword(String password) {
this.password = password;
}
public void setId(long id) {
this.id = id;
}
public void setEmail(String email) {
this.email = email;
}
public void setName(String name) {
this.name = name;
}
public void setSurname(String surname) {
this.surname = surname;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
}

+ 36
- 6
src/main/java/com/ims/rallyModels/modelo/UsuarioEntity.java View File

@ -1,8 +1,10 @@
package com.ims.rallyModels.modelo;
import jakarta.persistence.*;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "usuario", schema = "proyecto", catalog = "")
public class UsuarioEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -13,8 +15,30 @@ public class UsuarioEntity {
@Column(name = "nombre", nullable = true, length = 45)
private String nombre;
@Basic
@Column(name = "contrasena", nullable = true, length = 45)
private String contrasena;
@Column(name = "password", nullable = true, length = 150)
private String password;
@Basic
@Column(name = "sudo", nullable = true, length = 45)
private String sudo;
public UsuarioEntity(int idUsuario, String nombre, String password) {
this.idUsuario = idUsuario;
this.nombre = nombre;
this.password = password;
this.sudo = "USER";
}
public UsuarioEntity(String nombre, String password) {
this.nombre = nombre;
this.password = password;
this.sudo = "USER";
}
public UsuarioEntity() {
super();//anyways
}
public int getIdUsuario() {
return idUsuario;
@ -33,11 +57,17 @@ public class UsuarioEntity {
}
public String getContrasena() {
return contrasena;
return password;
}
public void setContrasena(String contrasena) {
this.contrasena = contrasena;
this.password = contrasena;
}
public String getSudo() {
return sudo;
}
public void setSudo(String sudo) {
this.sudo = sudo;
}
@Override
@ -49,7 +79,7 @@ public class UsuarioEntity {
if (idUsuario != that.idUsuario) return false;
if (nombre != null ? !nombre.equals(that.nombre) : that.nombre != null) return false;
if (contrasena != null ? !contrasena.equals(that.contrasena) : that.contrasena != null) return false;
if (password != null ? !password.equals(that.password) : that.password != null) return false;
return true;
}
@ -58,7 +88,7 @@ public class UsuarioEntity {
public int hashCode() {
int result = idUsuario;
result = 31 * result + (nombre != null ? nombre.hashCode() : 0);
result = 31 * result + (contrasena != null ? contrasena.hashCode() : 0);
result = 31 * result + (password != null ? password.hashCode() : 0);
return result;
}
}

+ 104
- 0
src/main/java/com/ims/rallyModels/reportes/FacturaExporterExcel.java View File

@ -0,0 +1,104 @@
package com.ims.rallyModels.reportes;
import com.ims.rallyModels.modelo.MaquetaEntity;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public class FacturaExporterExcel {
private XSSFWorkbook libro;
private XSSFSheet hoja;
private List<MaquetaEntity> maquetas;
public FacturaExporterExcel(List<MaquetaEntity> maquetas) {
this.maquetas = maquetas;
libro = new XSSFWorkbook();
hoja = libro.createSheet("Maquetas");
}
private void escribirCabeceraTabla() {
Row fila = hoja.createRow(0);
CellStyle estilo = libro.createCellStyle();
XSSFFont fuente = libro.createFont();
fuente.setBold(true);
fuente.setFontHeight(16);
estilo.setFont(fuente);
Cell celda = fila.createCell(0);
celda.setCellValue("Id");
celda.setCellStyle(estilo);
celda = fila.createCell(1);
celda.setCellValue("Coche");
celda.setCellStyle(estilo);
celda = fila.createCell(2);
celda.setCellValue("Piloto");
celda.setCellStyle(estilo);
celda = fila.createCell(3);
celda.setCellValue("Precio");
celda.setCellStyle(estilo);
}
public void escribirDatosDeTabla() {
int numeroFilas = 1;
CellStyle estilo = libro.createCellStyle();
XSSFFont fuente = libro.createFont();
fuente.setFontHeight(14);
estilo.setFont(fuente);
for (MaquetaEntity m : maquetas) {
Row fila = hoja.createRow(numeroFilas++);
Cell celda = fila.createCell(0);
celda.setCellValue(m.getIdMaqueta());
hoja.autoSizeColumn(0);
celda.setCellStyle(estilo);
celda = fila.createCell(1);
celda.setCellValue(m.getMarca()+" "+m.getModelo());
hoja.autoSizeColumn(1);
celda.setCellStyle(estilo);
celda = fila.createCell(2);
celda.setCellValue(m.getPiloto());
hoja.autoSizeColumn(2);
celda.setCellStyle(estilo);
celda = fila.createCell(3);
celda.setCellValue(m.getPrecio());
hoja.autoSizeColumn(3);
celda.setCellStyle(estilo);
}
}
public void exportar(HttpServletResponse response) throws IOException {
escribirCabeceraTabla();
escribirDatosDeTabla();
ServletOutputStream outputStream = response.getOutputStream();
libro.write(outputStream);
libro.close();
outputStream.close();
}
}

+ 87
- 0
src/main/java/com/ims/rallyModels/reportes/FacturaExporterPDF.java View File

@ -0,0 +1,87 @@
package com.ims.rallyModels.reportes;
import com.ims.rallyModels.modelo.CompraEntity;
import com.ims.rallyModels.modelo.MaquetaEntity;
import com.lowagie.text.*;
import com.lowagie.text.Font;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import jakarta.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.IOException;
import java.util.List;
public class FacturaExporterPDF {
private List<MaquetaEntity> compra;
public FacturaExporterPDF(List<MaquetaEntity> compra) {
super();
this.compra = compra;
}
private void escribirCabeceraDeLaTabla(PdfPTable tabla) {
PdfPCell cell = new PdfPCell();
cell.setBackgroundColor(Color.LIGHT_GRAY);
cell.setPadding(5);
Font fuente = FontFactory.getFont(FontFactory.HELVETICA);
fuente.setColor(Color.WHITE);
cell.setPhrase(new Phrase("Id",fuente));
tabla.addCell(cell);
cell.setPhrase(new Phrase("Coche",fuente));
tabla.addCell(cell);
cell.setPhrase(new Phrase("Piloto",fuente));
tabla.addCell(cell);
cell.setPhrase(new Phrase("Precio",fuente));
tabla.addCell(cell);
}
private void escribirDatosDeLaTable(PdfPTable table) {
for (MaquetaEntity m : compra) {
table.addCell(String.valueOf(m.getIdMaqueta()));
table.addCell(m.getMarca()+" "+m.getModelo());
table.addCell(m.getPiloto());
table.addCell(m.getPrecio().toString());
}
}
public void exportar(HttpServletResponse response) throws IOException {
Document documento = new Document(PageSize.A4);
PdfWriter.getInstance(documento,response.getOutputStream());
documento.open();
Font fuente = FontFactory.getFont(FontFactory.HELVETICA);
fuente.setColor(Color.RED);
fuente.setSize(18);
Paragraph titulo = new Paragraph("Factura de maquetas", fuente);
titulo.setAlignment(Paragraph.ALIGN_CENTER);
documento.add(titulo);
PdfPTable tabla = new PdfPTable(4);
tabla.setWidthPercentage(100);
tabla.setSpacingBefore(15);
tabla.setWidths(new float[] {1f,2.3f,2.3f,2.3f});
tabla.setWidthPercentage(110);
escribirCabeceraDeLaTabla(tabla);
escribirDatosDeLaTable(tabla);
documento.add(tabla);
documento.close();
}
}

+ 9
- 0
src/main/java/com/ims/rallyModels/repositorio/ICocheRepositorio.java View File

@ -0,0 +1,9 @@
package com.ims.rallyModels.repositorio;
import com.ims.rallyModels.modelo.CocheEntity;
import jdk.jfr.Registered;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ICocheRepositorio extends JpaRepository<CocheEntity,Integer> {}

+ 9
- 0
src/main/java/com/ims/rallyModels/repositorio/ICompeticionRepositorio.java View File

@ -0,0 +1,9 @@
package com.ims.rallyModels.repositorio;
import com.ims.rallyModels.modelo.CompeticionEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ICompeticionRepositorio extends JpaRepository<CompeticionEntity, Integer> {
}

src/main/java/com/ims/rallyModels/repositorio/IUsuarioRepositorio.java → src/main/java/com/ims/rallyModels/repositorio/ICompraRepositorio.java View File

@ -1,10 +1,11 @@
package com.ims.rallyModels.repositorio;
import com.ims.rallyModels.modelo.CompraEntity;
import com.ims.rallyModels.modelo.MaquetaEntity;
import com.ims.rallyModels.modelo.UsuarioEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface IUsuarioRepositorio extends JpaRepository<UsuarioEntity, Integer> {
import java.util.List;
public interface ICompraRepositorio extends JpaRepository<CompraEntity,Integer> {
}

+ 9
- 1
src/main/java/com/ims/rallyModels/repositorio/IMaquetasRepositorio.java View File

@ -1,8 +1,16 @@
package com.ims.rallyModels.repositorio;
import com.ims.rallyModels.modelo.CompraEntity;
import com.ims.rallyModels.modelo.MaquetaEntity;
import com.ims.rallyModels.modelo.UserModel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface IMaquetasRepositorio extends JpaRepository<MaquetaEntity, Integer> { }
public interface IMaquetasRepositorio extends JpaRepository<MaquetaEntity, Integer> {
List<MaquetaEntity> findByCompra(CompraEntity c);
}

+ 12
- 0
src/main/java/com/ims/rallyModels/repositorio/IUserRepository.java View File

@ -0,0 +1,12 @@
package com.ims.rallyModels.repositorio;
import com.ims.rallyModels.modelo.MaquetaEntity;
import com.ims.rallyModels.modelo.UserModel;
import com.ims.rallyModels.modelo.UsuarioEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
public interface IUserRepository extends JpaRepository<UserModel, Integer> {
UserModel findByEmail(String email);
}

+ 55
- 0
src/main/java/com/ims/rallyModels/security/SecurityConfig.java View File

@ -0,0 +1,55 @@
package com.ims.rallyModels.security;
import com.ims.rallyModels.servicio.UsuarioServicioImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public UsuarioServicioImpl userDetailsService(){
return new UsuarioServicioImpl();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
public DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService());
authProvider.setPasswordEncoder(passwordEncoder());
return authProvider;
}
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests()
.requestMatchers("/user").authenticated()
.anyRequest().permitAll()
.and()
.formLogin()
.usernameParameter("email")
.loginPage("/login")
.defaultSuccessUrl("/public/maquetas")
.permitAll()
.and()
.logout().logoutSuccessUrl("/login").permitAll();
return http.build();
}
}

+ 0
- 11
src/main/java/com/ims/rallyModels/servicio/IUsuarioServicio.java View File

@ -1,11 +0,0 @@
package com.ims.rallyModels.servicio;
import com.ims.rallyModels.modelo.UsuarioEntity;
import java.util.List;
public interface IUsuarioServicio {
public List<UsuarioEntity> listAll();
}

+ 58
- 0
src/main/java/com/ims/rallyModels/servicio/UserDetailsImpl.java View File

@ -0,0 +1,58 @@
package com.ims.rallyModels.servicio;
import com.ims.rallyModels.modelo.CompraEntity;
import com.ims.rallyModels.modelo.UserModel;
import com.ims.rallyModels.modelo.UsuarioEntity;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.util.Collection;
import java.util.List;
public class UserDetailsImpl implements UserDetails {
private UserModel user;
public UserDetailsImpl(UserModel user) {
this.user = user;
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return null;
}
@Override
public String getPassword() {
return user.getPassword();
}
public UserModel getUser() {
return user;
}
@Override
public String getUsername() {
return user.getEmail();
}
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return true;
}
}

+ 41
- 10
src/main/java/com/ims/rallyModels/servicio/UsuarioServicioImpl.java View File

@ -1,20 +1,51 @@
package com.ims.rallyModels.servicio;
import com.ims.rallyModels.modelo.UsuarioEntity;
import com.ims.rallyModels.repositorio.IMaquetasRepositorio;
import com.ims.rallyModels.repositorio.IUsuarioRepositorio;
import com.ims.rallyModels.modelo.UserModel;
import com.ims.rallyModels.repositorio.IUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import java.util.List;
public class UsuarioServicioImpl implements IUsuarioServicio{
import java.util.Collection;
import java.util.stream.Collectors;
@Service
public class UsuarioServicioImpl implements UserDetailsService {
//may cons
@Autowired
private IUsuarioRepositorio repositorio;
private IUserRepository userRepo;
@Override
public List<UsuarioEntity> listAll() {
return repositorio.findAll();
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
UserModel user = userRepo.findByEmail(username);
if (user == null) {
throw new UsernameNotFoundException("User not found");
}
return new UserDetailsImpl(user);
}
/*@Override
public UsuarioEntity buscarPorNombre(String nombre) {
return repositorio.findByName(nombre);
}*/
/*
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
UsuarioEntity usuario = repositorio.findByNombre(username);
if (usuario == null) {
throw new UsernameNotFoundException("Usuario o password inválidos");;
}
return new UsuarioEntity(usuario.getNombre(), usuario.getContrasena(), mapearAutoridadesRoles(usuario.getSudo()));
}*/
/*@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
UsuarioEntity user = repositorio.findByNombre(username);
if (user == null) {
throw new UsernameNotFoundException("User not found");
}
return new UserDetailsImpl(user);
}*/
}

+ 42
- 0
src/main/java/com/ims/rallyModels/servicio/coche/CocheServicioImpl.java View File

@ -0,0 +1,42 @@
package com.ims.rallyModels.servicio.coche;
import com.ims.rallyModels.modelo.CocheEntity;
import com.ims.rallyModels.repositorio.ICocheRepositorio;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class CocheServicioImpl implements ICocheServicio {
@Autowired
private ICocheRepositorio repositorio;
@Override
public List<CocheEntity> listAll() {
return repositorio.findAll();
}
@Override
public CocheEntity guardarCoche(CocheEntity maqueta) {
return repositorio.save(maqueta);
}
@Override
public CocheEntity obtenerCochePorId(Integer id) {
return repositorio.findById(id).get();
}
@Override
public CocheEntity actualizarCoche(CocheEntity maqueta) {
//primero se busca y luego se edita y guarda
return repositorio.save(maqueta);
}
@Override