From 88fb8b99c2ab0319d201429a5553d8b53a79bc0d Mon Sep 17 00:00:00 2001 From: vicsash Date: Thu, 11 Apr 2024 20:57:57 +0200 Subject: [PATCH] Haciendo ajestes al buscador, empezando con operaciones de busqueda y detalles internas de la busqueda --- .../configuration/database/DatabaseTest.java | 8 +++ .../controllers/BuscadorController.java | 24 ++++++- .../proyectofinal/models/empresas/Alumno.java | 4 +- .../models/empresas/Empresa.java | 6 +- .../empresas/EmpressaRepository.java | 10 +++ .../resources/templates/buscador_admin.html | 67 +++++++++++++++++++ .../{buscador.html => buscador_alumno.html} | 33 +++++---- .../resources/templates/list_alumnos.html | 51 ++++++++++++++ .../resources/templates/list_empresas.html | 48 +++++++++++++ 9 files changed, 233 insertions(+), 18 deletions(-) create mode 100644 src/main/resources/templates/buscador_admin.html rename src/main/resources/templates/{buscador.html => buscador_alumno.html} (55%) create mode 100644 src/main/resources/templates/list_alumnos.html create mode 100644 src/main/resources/templates/list_empresas.html diff --git a/src/main/java/com/example/proyectofinal/configuration/database/DatabaseTest.java b/src/main/java/com/example/proyectofinal/configuration/database/DatabaseTest.java index 98930ea..a0dcb2b 100644 --- a/src/main/java/com/example/proyectofinal/configuration/database/DatabaseTest.java +++ b/src/main/java/com/example/proyectofinal/configuration/database/DatabaseTest.java @@ -5,15 +5,20 @@ import com.example.proyectofinal.repositories.empresas.ContactoRepository; import com.example.proyectofinal.repositories.empresas.OfertaRepository; import com.example.proyectofinal.repositories.empresas.SucursalRepository; import com.github.javafaker.Faker; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.core.JdbcTemplate; +import javax.sql.DataSource; import java.util.HashSet; import java.util.Set; @Configuration public class DatabaseTest { + @Autowired + private DataSource dataSource; @Bean CommandLineRunner initDatabase(AlumnoRepository alumnoRepository, ContactoRepository contactoRepository, SucursalRepository sucursalRepository, OfertaRepository ofertaRepository) { @@ -80,6 +85,9 @@ public class DatabaseTest { ); ofertaRepository.save(oferta); } + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); + jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON empresas(keywords,nombre)"); }; + } } diff --git a/src/main/java/com/example/proyectofinal/controllers/BuscadorController.java b/src/main/java/com/example/proyectofinal/controllers/BuscadorController.java index 4f5a1ee..123f124 100644 --- a/src/main/java/com/example/proyectofinal/controllers/BuscadorController.java +++ b/src/main/java/com/example/proyectofinal/controllers/BuscadorController.java @@ -1,14 +1,36 @@ package com.example.proyectofinal.controllers; + +import org.springframework.ui.Model; +import com.example.proyectofinal.models.empresas.Empresa; +import com.example.proyectofinal.repositories.empresas.EmpressaRepository; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; @Controller @RequestMapping("/buscador") public class BuscadorController { + @Autowired + private EmpressaRepository empressaRepository; @GetMapping public String buscador(){ - return "buscador"; + return "buscador_admin"; } + + @GetMapping("/search") + public String search(@RequestParam String query, @RequestParam(required = false) String optempresa, String optskill, String optalumno, String optoferta, Model model) { + if(optempresa != null){ + ArrayList empresas = empressaRepository.getEmpressaByKeywordsOrName("*"+query+"*"); + model.addAttribute("empresas", empresas); + } + return "list_empresas"; + } + } \ No newline at end of file diff --git a/src/main/java/com/example/proyectofinal/models/empresas/Alumno.java b/src/main/java/com/example/proyectofinal/models/empresas/Alumno.java index 67250de..163ce5c 100644 --- a/src/main/java/com/example/proyectofinal/models/empresas/Alumno.java +++ b/src/main/java/com/example/proyectofinal/models/empresas/Alumno.java @@ -13,7 +13,7 @@ import java.util.Set; //@Getter //@Setter @Data -@Table(name = "Alumno") +@Table(name = "alumnos") public class Alumno { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -45,6 +45,8 @@ public class Alumno { @NonNull @Column(length = 45) private String keyword; + //TODO AƱadir campos adicinales en alumno dni,correo 1 y 2, + // nacionalidad, domicillo y otros adicionales si hay necesidad @ManyToMany(cascade = {CascadeType.PERSIST,CascadeType.REFRESH},fetch = FetchType.EAGER) @JoinTable( diff --git a/src/main/java/com/example/proyectofinal/models/empresas/Empresa.java b/src/main/java/com/example/proyectofinal/models/empresas/Empresa.java index 6a38d6b..f2c01e6 100644 --- a/src/main/java/com/example/proyectofinal/models/empresas/Empresa.java +++ b/src/main/java/com/example/proyectofinal/models/empresas/Empresa.java @@ -10,7 +10,7 @@ import lombok.NonNull; @AllArgsConstructor @NoArgsConstructor @Data -@Table(name = "Empresa") +@Table(name = "empresas") public class Empresa { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -30,7 +30,7 @@ public class Empresa { @NonNull @Column(length = 45) - private String telefono1; + private String telefono; @NonNull @@ -45,7 +45,7 @@ public class Empresa { this.nombre = nombre; this.cif = cif; this.correo = correo; - this.telefono1 = telefono1; + this.telefono = telefono1; this.keywords = keywords; this.sector = sector; } diff --git a/src/main/java/com/example/proyectofinal/repositories/empresas/EmpressaRepository.java b/src/main/java/com/example/proyectofinal/repositories/empresas/EmpressaRepository.java index 6742c05..569ccfb 100644 --- a/src/main/java/com/example/proyectofinal/repositories/empresas/EmpressaRepository.java +++ b/src/main/java/com/example/proyectofinal/repositories/empresas/EmpressaRepository.java @@ -2,6 +2,16 @@ package com.example.proyectofinal.repositories.empresas; import com.example.proyectofinal.models.empresas.Empresa; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.ArrayList; public interface EmpressaRepository extends JpaRepository { + //There is no value= here so Empresa is the table name + @Query("Select u from Empresa u where u.nombre LIKE ?1") + public Empresa getEmpressa(String empressa); + //there is value = and nativeQuery = true so the query is written in SQL refering to the table in the database + @Query(value = "Select * FROM empresas u where MATCH(u.nombre, u.keywords) AGAINST( ?1 in boolean mode)",nativeQuery = true) + public ArrayList getEmpressaByKeywordsOrName(String keyword1); + } diff --git a/src/main/resources/templates/buscador_admin.html b/src/main/resources/templates/buscador_admin.html new file mode 100644 index 0000000..bc1252d --- /dev/null +++ b/src/main/resources/templates/buscador_admin.html @@ -0,0 +1,67 @@ + + + + Buscador + + + +
+
+ + +
+
+ +
+ +
+ +
+ +
+ +
+
+
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/buscador.html b/src/main/resources/templates/buscador_alumno.html similarity index 55% rename from src/main/resources/templates/buscador.html rename to src/main/resources/templates/buscador_alumno.html index 5dadc92..999309e 100644 --- a/src/main/resources/templates/buscador.html +++ b/src/main/resources/templates/buscador_alumno.html @@ -8,15 +8,21 @@ justify-content: center; align-items: center; height: 100vh; - margin: 0; + margin: 10px; background-color: #f0f0f0; font-family: Arial, sans-serif; } form { display: flex; - justify-content: space-between; + flex-direction: column; + align-items: center; width: 50%; } + .search-container { + display: flex; + width: 100%; + justify-content: space-between; + } input[type="text"] { flex-grow: 1; padding: 15px; @@ -25,8 +31,9 @@ } .checkboxes { display: flex; - flex-direction: column; + flex-direction: row; justify-content: space-between; + align-items: center; width: 50%; margin-top: 20px; } @@ -34,16 +41,16 @@
- - +
+ + +
+
+ +
+ +
+
-
- -
- -
- -
-
\ No newline at end of file diff --git a/src/main/resources/templates/list_alumnos.html b/src/main/resources/templates/list_alumnos.html new file mode 100644 index 0000000..18c4a0d --- /dev/null +++ b/src/main/resources/templates/list_alumnos.html @@ -0,0 +1,51 @@ + + + + + + Title + + + + + + +
+

Listado de Empresas

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
IdNombreApellido 1Apellido 2Fecha NacimientoNIAKeywordsSkillsCiclo
[[${alumno.id}]][[${alumno.nombre}]][[${alumno.apellido}]][[${alumno.apellido2}]][[${alumno.fechaNacimiento}]][[${alumno.genero}]][[${alumno.nia}]][[${keyword}]][[${alumno.ciclo}]]
+
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/list_empresas.html b/src/main/resources/templates/list_empresas.html new file mode 100644 index 0000000..aedb2a5 --- /dev/null +++ b/src/main/resources/templates/list_empresas.html @@ -0,0 +1,48 @@ + + + + + + Title + + + + + +
+

Listado de Empresas

+ + + + + + + + + + + + + + + + + + + + + + + +
IdNombreCifCorreoTelefonoKeywordsSector
[[${empresa.id}]][[${empresa.nombre}]][[${empresa.cif}]][[${empresa.correo}]][[${empresa.telefono}]] +
[[${keyword}]]
+
[[${empresa.sector.nombre}]]
+
+ + + \ No newline at end of file