Termunando con funcion de borar en empresas, usando el formato nuevo empezando a rehacer las tablas, sector acabado y contactos en progreso. Arreglando fallo de que al cambiar la cantidad de entradas en lista y despues cambiando a otra pagina que no ha gaurdado la cantidad de entradas en la lista.

master
vicsash 5 months ago
parent 03e9be9fc0
commit 19f3bc0f7f

@ -3,6 +3,8 @@ package com.example.proyectofinal.controllers;
import com.example.proyectofinal.models.empresas.*;
import com.example.proyectofinal.repositories.empresas.*;
import com.example.proyectofinal.servicios.ContactosService;
import com.example.proyectofinal.servicios.SectorService;
import com.example.proyectofinal.servicios.implemetations.IEmpresa;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@ -29,14 +31,14 @@ public class BuscadorController {
@Autowired
private OfertaRepository ofertaRepository;
@Autowired
private SectorRepository sectorRepository;
private SectorService sectorService;
@Autowired
private SucursalRepository sucursalRepository;
@Autowired
private SkillRepository skillRepository;
@Autowired
private ContactoRepository contactoRepository;
private ContactosService contactosService;
@Autowired
private FamiliaRepository familiaRepository;
@Autowired
@ -59,26 +61,68 @@ public class BuscadorController {
@RequestParam(defaultValue = "asc") String sortDir){
String[] word = query.split("\\b(y|o)\\b|[,/]");
List<Empresa> empresas;
List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
Page<Empresa> page = this.empresaService.finadAllpaginated(pageNum, size, "id", "asc");
empresas = page.getContent();
} else {
Page<Empresa> page = this.empresaService.finadAllpaginated(pageNum, size, sortField, sortDir);
empresas = page.getContent();
if (word.length == 1 && (word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas"))) {
sortField = "id";
sortDir = "asc";
}
Page<Empresa> page = this.empresaService.finadAllpaginated(pageNum, size, sortField, sortDir);
List<Empresa> empresas = page.getContent();
model.addAttribute("currentSize", size);
Map<String, Object> attributes = getPagAtrEmpresas(pageNum, query, size, sortField, sortDir, empresas, itemsPage);
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
model.addAttribute(entry.getKey(), entry.getValue());
}
return "/list/empresas";
}
@GetMapping("/sectores/page/{pageNum}")
public String searchSectoresList(@PathVariable int pageNum,
@RequestParam(defaultValue = "") String query,
Model model,
@RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "id") String sortField,
@RequestParam(defaultValue = "asc") String sortDir){
String[] word = query.split("\\b(y|o)\\b|[,/]");
List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
if (word.length == 1 && (word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas"))) {
sortField = "id";
sortDir = "asc";
}
Page<Sector> page = this.sectorService.finadAllpaginated(pageNum, size, sortField, sortDir);
List<Sector> sectors = page.getContent();
model.addAttribute("currentSize", size);
Map<String, Object> attributes = getPagAtrSetores(pageNum, query, size, sortField, sortDir, sectors, itemsPage);
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
model.addAttribute(entry.getKey(), entry.getValue());
}
return "/list/sectores";
}
@GetMapping("/contactos/page/{pageNum")
public String searchContactosList(@PathVariable int pageNum,
@RequestParam(defaultValue = "") String query,
Model model,
@RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "id") String sortField,
@RequestParam(defaultValue = "asc") String sortDir) {
String[] word = query.split("\\b(y|o)\\b|[,/]");
List<Integer> itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
if (word.length == 1 && (word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas"))) {
sortField = "id";
sortDir = "asc";
}
Page<Contacto> page = this.contactosService.finadAllpaginated(pageNum, size, sortField, sortDir);
List<Contacto> contactos = page.getContent();
model.addAttribute("currentSize", size);
Map<String, Object> attributes = getPagAtrContactos(pageNum, query, size, sortField, sortDir, contactos, itemsPage);
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
model.addAttribute(entry.getKey(), entry.getValue());
}
return "/list/contactos";
}
public String searchAlumnosList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
@ -103,20 +147,7 @@ public class BuscadorController {
return "/list/ofertas";
}
@GetMapping("/sectores")
public String searchSectoresList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size){
Pageable pageable = PageRequest.of(page, size);
String[] word = query.split("\\b(y|o)\\b|[,/]");
if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
List<Sector> sectores = new ArrayList<>(sectorRepository.findAll());
model.addAttribute("sectores", sectores);
return "/list/sectores";
} else {
Sector sector = sectorRepository.findByNombre(word[0]);
model.addAttribute("sectores", sector);
return "/list/sectores";
}
}
@GetMapping("/sucursales")
public String searchSucursalesList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size){
@ -131,17 +162,7 @@ public class BuscadorController {
}
@GetMapping("/contactos")
public String searchContactosList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
String[] word = query.split("\\b(y|o)\\b|[,/]");
if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
List<Contacto> contactos = new ArrayList<>(contactoRepository.findAll());
model.addAttribute("contactos", contactos);
return "/list/contactos";
}
return "/list/contactos";
}
@GetMapping("/familias")
public String searchFamiliasList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
@ -197,9 +218,51 @@ public class BuscadorController {
return attributes;
}
public Map<String, Object> getPagAtrSetores(int pageNum, String query, int size, String sortField, String sortDir, List<Sector> sectors, List<Integer> itemsPage) {
Map<String, Object> attributes = new HashMap<>();
Page<Sector> page = this.sectorService.finadAllpaginated(pageNum, size, "id", "asc");
attributes.put("currentPage", pageNum);
attributes.put("totalPages", page.getTotalPages());
attributes.put("totalItems", page.getTotalElements());
attributes.put("sortField", sortField);
attributes.put("sortDir", sortDir);
attributes.put("reverseSortDir", sortDir.equals("asc") ? "desc" : "asc");
attributes.put("sectores", sectors);
attributes.put("query", query);
attributes.put("itemsPage", itemsPage);
return attributes;
}
public Map<String, Object> getPagAtrContactos(int pageNum, String query, int size, String sortField, String sortDir, List<Contacto> contactos, List<Integer> itemsPage) {
Map<String, Object> attributes = new HashMap<>();
Page<Contacto> page = this.contactosService.finadAllpaginated(pageNum, size, "id", "asc");
attributes.put("currentPage", pageNum);
attributes.put("totalPages", page.getTotalPages());
attributes.put("totalItems", page.getTotalElements());
attributes.put("sortField", sortField);
attributes.put("sortDir", sortDir);
attributes.put("reverseSortDir", sortDir.equals("asc") ? "desc" : "asc");
attributes.put("contactos", contactos);
attributes.put("query", query);
attributes.put("itemsPage", itemsPage);
return attributes;
}
@GetMapping("/empresas/search")
public ResponseEntity<List<Empresa>> searchEmpresas(@RequestParam String query) {
List<Empresa> empresas = empresaService.search(query);
return ResponseEntity.ok(empresas);
}
@GetMapping("/sectores/search")
public ResponseEntity<List<Sector>> searchSectores(@RequestParam String query) {
List<Sector> sectors = sectorService.search(query);
return ResponseEntity.ok(sectors);
}
@GetMapping("/sectores/search")
public ResponseEntity<List<Contacto>> searchContactos(@RequestParam String query) {
List<Contacto> contactos = null;
return ResponseEntity.ok(contactos);
}
}

@ -0,0 +1,96 @@
package com.example.proyectofinal.controllers.modelControllers;
import com.example.proyectofinal.models.empresas.Contacto;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.servicios.ContactosService;
import com.example.proyectofinal.servicios.EmpresaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@Controller
public class ContactoController {
@Autowired
private ContactosService contactosService;
@Autowired
private EmpresaService empresaService;
@GetMapping("/admin/contacto/create")
public String showCreateForm(Model model) {
Contacto contacto = new Contacto();
List<Empresa> empresas = empresaService.findAll();
Empresa empresa = new Empresa();
model.addAttribute("contacto", contacto);
model.addAttribute("empresas", empresas);
model.addAttribute("empresa", empresa);
return "admin/contacto/create";
}
@PostMapping("/contacto/save")
public ResponseEntity<String> saveContacto(Contacto contacto, @RequestParam("sector.id") Long empresaId){
try{
Empresa existingEmpresa = empresaService.findById(empresaId);
if(existingEmpresa != null) {
contacto.setEmpresa(existingEmpresa);
} else {
return new ResponseEntity<>("Empresa no encontrada", HttpStatus.BAD_REQUEST);
}
if(contactosService.exists(contacto)){
return new ResponseEntity<>("Este contacto ya existe en la base de datos", HttpStatus.BAD_REQUEST);
}else {
contactosService.save(contacto);
return new ResponseEntity<>("El contacto fue guardado con exito", HttpStatus.OK);
}
}catch (Exception e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/admin/contacto/update/{id}")
public String showUpdateForm(Model model, @PathVariable Long id) {
Contacto contacto = contactosService.findById(id);
Empresa empresa = new Empresa();
List<Empresa> empresas = empresaService.findAll();
model.addAttribute("contacto", contacto);
model.addAttribute("empresas", empresas);
model.addAttribute("empresa", empresa);
return "admin/contacto/update";
}
@PostMapping("/contacto/update")
public ResponseEntity<String> updateContacto(Contacto contacto, @RequestParam("sector.id") Long empresaId){
try{
Empresa existingEmpresa = empresaService.findById(empresaId);
if(existingEmpresa != null) {
contacto.setEmpresa(existingEmpresa);
} else {
return new ResponseEntity<>("Empresa no encontrado", HttpStatus.BAD_REQUEST);
}
contactosService.save(contacto);
return new ResponseEntity<>("Los datos del contacto fue renovados con exito", HttpStatus.OK);
}catch (Exception e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/contacto/delete/{id}")
public ResponseEntity<String> deleteContacto(@PathVariable Long id){
try{
empresaService.deleteById(id);
return new ResponseEntity<>("El contacto ha sido eliminado", HttpStatus.OK);
}catch (Exception e){
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

@ -102,10 +102,9 @@ public class EmpressaController {
@GetMapping("/empresa/delete/{id}")
public ResponseEntity<String> deleteEmpresa(@PathVariable Long id){
try{
System.out.println("Deleting empresa with id: " + id);
empresaService.deleteById(id);
return new ResponseEntity<>("La empresa ha sido eliminado", HttpStatus.OK);
return new ResponseEntity<>("El sector ha sido eliminado", HttpStatus.OK);
}catch (Exception e){
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}

@ -1,27 +1,80 @@
package com.example.proyectofinal.controllers.modelControllers;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.models.empresas.Sector;
import com.example.proyectofinal.repositories.empresas.EmpressaRepository;
import com.example.proyectofinal.servicios.SectorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import java.util.HashSet;
import java.util.Set;
@Controller
@RequestMapping("/sector")
@RequestMapping()
public class SectorController {
@Autowired
private EmpressaRepository empressaRepository;
@GetMapping("/{id}")
@Autowired
private SectorService sectorService;
@GetMapping("sector/{id}")
public String getEmpressaBySector(@PathVariable Long id, Model model) {
Set<Empresa> empresaSet = new HashSet<>(empressaRepository.findBySector(id));
model.addAttribute("empresas", empresaSet);
return "empresas";
}
@GetMapping("/admin/sector/create")
public String showCreateForm(Model model) {
Sector sectores = new Sector();
model.addAttribute("sector", sectores);
return "admin/sector/create";
}
@PostMapping("/sector/save")
public ResponseEntity<String> saveSector(Sector sector){
try{
if(sectorService.findByName(sector.getNombre()) != null){
System.out.println("Este sector ya existe en la base de datos");
return new ResponseEntity<>("Este sector ya existe en la base de datos", HttpStatus.BAD_REQUEST);
}else {
sectorService.save(sector);
return new ResponseEntity<>("El sector fue guardado con exito", HttpStatus.OK);
}
}catch (Exception e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/admin/sector/update/{id}")
public String showUpdateForm(Model model, @PathVariable Long id) {
Sector sector = sectorService.findById(id);
model.addAttribute("sector", sector);
return "admin/sector/update";
}
@PostMapping("/sector/update")
public ResponseEntity<String> updateSector(Sector sector){
try{
sectorService.save(sector);
return new ResponseEntity<>("El sector ha sido actualizado", HttpStatus.OK);
}catch (Exception e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/sector/delete/{id}")
public ResponseEntity<String> deleteSector(@PathVariable Long id){
try{
sectorService.deleteById(id);
return new ResponseEntity<>("El sector ha sido eliminado", HttpStatus.OK);
}catch (Exception e){
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

@ -7,12 +7,12 @@ INSERT INTO familias (nombre) VALUES ('Tourismo');
-- Insert into Ciclo table
INSERT INTO ciclos (nombre, codigo, Familia_id) VALUES ('Dessarrollo de aplicaciones multiplataforma','DAM2', 1);
INSERT INTO ciclos (nombre, codigo, Familia_id) VALUES ('Dessarrollo de aplicaciones web','DAW2', 1);
INSERT INTO ciclos (nombre, codigo, Familia_id) VALUES ('Gestion de servidores ANCII','ANCI2', 1);
INSERT INTO Ciclos (nombre, codigo, Familia_id) VALUES ('Tourismo','TOUR', 5);
INSERT INTO ciclos (nombre, codigo, Familia_id) VALUES ('Deporte','DEP', 4);
INSERT INTO ciclos (nombre, codigo, Familia_id) VALUES ('Contabilidad','Cont', 3);
INSERT INTO ciclos (nombre, codigo, fk_familia) VALUES ('Dessarrollo de aplicaciones multiplataforma','DAM2', 1);
INSERT INTO ciclos (nombre, codigo, fk_familia) VALUES ('Dessarrollo de aplicaciones web','DAW2', 1);
INSERT INTO ciclos (nombre, codigo, fk_familia) VALUES ('Gestion de servidores ANCII','ANCI2', 1);
INSERT INTO Ciclos (nombre, codigo, fk_familia) VALUES ('Tourismo','TOUR', 5);
INSERT INTO ciclos (nombre, codigo, fk_familia) VALUES ('Deporte','DEP', 4);
INSERT INTO ciclos (nombre, codigo, fk_familia) VALUES ('Contabilidad','Cont', 3);
-- Insert into Skill table
INSERT INTO skills (nombre) VALUES ('Java');
@ -44,94 +44,94 @@ INSERT INTO sectores (nombre) VALUES ('Marketing');
INSERT INTO sectores (nombre) VALUES ('Economia');
-- Insert into Alumno table
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, ciclo_id) VALUES ('Jorge', 'Doe', NULL , '2000-01-01', 'Masculino', '123456781', '12345678A', 'john.doe@example.com', 'john.smith@example.com', 'American', 'Java, Python', 1);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, ciclo_id) VALUES ('Jane', 'Doe', 'Johnson', '2000-02-02', 'Femenino', '123456782', '12345678B', 'jane.doe@example.com', 'jane.johnson@example.com', 'American', 'Guitara', 2);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, ciclo_id) VALUES ('Robert', 'Smith', NULL , '2000-03-03', 'Masculino', '123456783', '12345678C', 'robert.smith@example.com', NULL , 'British', 'Eletricista', 3);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, ciclo_id) VALUES ('Emily', 'Johnson', 'Smith', '2000-04-04', 'Femenino', '123456784', '12345678D', 'emily.johnson@example.com', 'emily.smith@example.com', 'British', 'Moviles', 4);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, ciclo_id) VALUES ('James', 'Brown', 'Johnson', '2000-05-05', 'Masculino', '123456785', '12345678E', 'james.brown@example.com', NULL, 'Australian', 'Deportista', 5);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, ciclo_id) VALUES ('Michael', 'Jackson', 'Smith', '2000-06-06', 'Masculino', '123456786', '12345678F', 'michael.jackson@example.com', 'michael.smith@example.com', 'American', 'Music, Dance', 1);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, ciclo_id) VALUES ('Emma', 'Watson', 'Johnson', '2000-07-07', 'Femenino', '123456787', '12345678G', 'emma.watson@example.com', 'emma.johnson@example.com', 'British', 'Acting, French', 2);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, ciclo_id) VALUES ('Tom', 'Cruise',NULL , '2000-08-08', 'Masculino', '123456788', '12345678H', 'tom.cruise@example.com',NULL, 'American', 'Acting, Stunts', 3);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, ciclo_id) VALUES ('Jennifer', 'Lawrence', 'Smith', '2000-09-09', 'Femenino', '123456789', '12345678I', 'jennifer.lawrence@example.com', 'jennifer.smith@example.com', 'American', 'Acting, Archery', 4);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, ciclo_id) VALUES ('Chris', 'Hemsworth', 'Johnson', '2000-10-10', 'Masculino', '123456780', '12345678J', 'chris.hemsworth@example.com',NULL , 'Australian', 'Acting, Fitness', 5);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, ciclo_id) VALUES ('Brad', 'Pitt', 'Johnson', '2000-11-11', 'Masculino', '123456781', '12345678K', 'brad.pitt@example.com', 'brad.johnson@example.com', 'American', 'Acting, Production', 1);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, ciclo_id) VALUES ('Angelina', 'Jolie', 'Smith', '2000-12-12', 'Femenino', '123456782', '12345678L', 'angelina.jolie@example.com', 'angelina.smith@example.com', 'American', 'Acting, Humanitarian', 2);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, ciclo_id) VALUES ('Leonardo', 'DiCaprio', NULL , '2001-01-01', 'Masculino', '123456783', '12345678M', 'leonardo.dicaprio@example.com',NULL , 'American', 'Acting, Environmental activism', 3);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, ciclo_id) VALUES ('Scarlett', 'Johansson', 'Johnson', '2001-02-02', 'Femenino', '123456784', '12345678N', 'scarlett.johansson@example.com', 'scarlett.johnson@example.com', 'American', 'Acting, Singing', 4);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, ciclo_id) VALUES ('Hugh', 'Jackman', 'Smith', '2001-03-03', 'Masculino', '123456785', '12345678O', 'hugh.jackman@example.com', null, 'Australian', 'Acting, Singing', 5);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, fk_ciclo) VALUES ('Jorge', 'Doe', NULL , '2000-01-01', 'Masculino', '123456781', '12345678A', 'john.doe@example.com', 'john.smith@example.com', 'American', 'Java, Python', 1);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, fk_ciclo) VALUES ('Jane', 'Doe', 'Johnson', '2000-02-02', 'Femenino', '123456782', '12345678B', 'jane.doe@example.com', 'jane.johnson@example.com', 'American', 'Guitara', 2);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, fk_ciclo) VALUES ('Robert', 'Smith', NULL , '2000-03-03', 'Masculino', '123456783', '12345678C', 'robert.smith@example.com', NULL , 'British', 'Eletricista', 3);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, fk_ciclo) VALUES ('Emily', 'Johnson', 'Smith', '2000-04-04', 'Femenino', '123456784', '12345678D', 'emily.johnson@example.com', 'emily.smith@example.com', 'British', 'Moviles', 4);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, fk_ciclo) VALUES ('James', 'Brown', 'Johnson', '2000-05-05', 'Masculino', '123456785', '12345678E', 'james.brown@example.com', NULL, 'Australian', 'Deportista', 5);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, fk_ciclo) VALUES ('Michael', 'Jackson', 'Smith', '2000-06-06', 'Masculino', '123456786', '12345678F', 'michael.jackson@example.com', 'michael.smith@example.com', 'American', 'Music, Dance', 1);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, fk_ciclo) VALUES ('Emma', 'Watson', 'Johnson', '2000-07-07', 'Femenino', '123456787', '12345678G', 'emma.watson@example.com', 'emma.johnson@example.com', 'British', 'Acting, French', 2);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, fk_ciclo) VALUES ('Tom', 'Cruise',NULL , '2000-08-08', 'Masculino', '123456788', '12345678H', 'tom.cruise@example.com',NULL, 'American', 'Acting, Stunts', 3);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, fk_ciclo) VALUES ('Jennifer', 'Lawrence', 'Smith', '2000-09-09', 'Femenino', '123456789', '12345678I', 'jennifer.lawrence@example.com', 'jennifer.smith@example.com', 'American', 'Acting, Archery', 4);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, fk_ciclo) VALUES ('Chris', 'Hemsworth', 'Johnson', '2000-10-10', 'Masculino', '123456780', '12345678J', 'chris.hemsworth@example.com',NULL , 'Australian', 'Acting, Fitness', 5);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, fk_ciclo) VALUES ('Brad', 'Pitt', 'Johnson', '2000-11-11', 'Masculino', '123456781', '12345678K', 'brad.pitt@example.com', 'brad.johnson@example.com', 'American', 'Acting, Production', 1);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, fk_ciclo) VALUES ('Angelina', 'Jolie', 'Smith', '2000-12-12', 'Femenino', '123456782', '12345678L', 'angelina.jolie@example.com', 'angelina.smith@example.com', 'American', 'Acting, Humanitarian', 2);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, fk_ciclo) VALUES ('Leonardo', 'DiCaprio', NULL , '2001-01-01', 'Masculino', '123456783', '12345678M', 'leonardo.dicaprio@example.com',NULL , 'American', 'Acting, Environmental activism', 3);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, fk_ciclo) VALUES ('Scarlett', 'Johansson', 'Johnson', '2001-02-02', 'Femenino', '123456784', '12345678N', 'scarlett.johansson@example.com', 'scarlett.johnson@example.com', 'American', 'Acting, Singing', 4);
INSERT INTO alumnos (nombre, apellido, apellido2, fecha_nacimiento, genero, nia, dni, correo, correo2, nacionalidad, keywords, fk_ciclo) VALUES ('Hugh', 'Jackman', 'Smith', '2001-03-03', 'Masculino', '123456785', '12345678O', 'hugh.jackman@example.com', null, 'Australian', 'Acting, Singing', 5);
-- Insert into Empresa table
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('LuzT', '123456789W1', 'luzt@example.com', '12345678901', 'trabajador,python', 1);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('PC R&R', '123456789W2', 'pcrnr@example.com', '12345678902', 'jugador', 2);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('Runners', '123456789W3', 'run@example.com', '12345678903', 'bailador', 3);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('Keytara', '123456789W4', 'keytara@example.com', '12345678904', 'programador', 4);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('Movil', '123456789W5', 'movil@example.com', '12345678905', 'animales', 5);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('TechFlow', '123456789W6', 'techflow@example.com', '12345678906', 'innovation,technology', 1);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('HealthFirst', '123456789W7', 'healthfirst@example.com', '12345678907', 'healthcare,wellness', 2);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('EcoLife', '123456789W8', 'ecolife@example.com', '12345678908', 'sustainability,environment', 3);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('FinTrack', '123456789W9', 'fintrack@example.com', '12345678909', 'finance,investment', 4);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('EduSphere', '123456789W0', 'edusphere@example.com', '12345678900', 'education,elearning', 5);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('GreenTech', '123456789W6', 'greentech@example.com', '12345678906', 'renewable,energy', 1);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('FoodJoy', '123456789W7', 'foodjoy@example.com', '12345678907', 'food,delivery', 2);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('FitLife', '123456789W8', 'fitlife@example.com', '12345678908', 'fitness,health', 3);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('WealthTrack', '123456789W9', 'wealthtrack@example.com', '12345678909', 'finance,investment', 4);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('LearnSphere', '123456789W0', 'learnsphere@example.com', '12345678900', 'education,elearning', 5);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, fk_sector) VALUES ('LuzT', '123456789W1', 'luzt@example.com', '12345678901', 'trabajador,python', 1);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, fk_sector) VALUES ('PC R&R', '123456789W2', 'pcrnr@example.com', '12345678902', 'jugador', 2);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, fk_sector) VALUES ('Runners', '123456789W3', 'run@example.com', '12345678903', 'bailador', 3);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, fk_sector) VALUES ('Keytara', '123456789W4', 'keytara@example.com', '12345678904', 'programador', 4);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, fk_sector) VALUES ('Movil', '123456789W5', 'movil@example.com', '12345678905', 'animales', 5);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, fk_sector) VALUES ('TechFlow', '123456789W6', 'techflow@example.com', '12345678906', 'innovation,technology', 1);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, fk_sector) VALUES ('HealthFirst', '123456789W7', 'healthfirst@example.com', '12345678907', 'healthcare,wellness', 2);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, fk_sector) VALUES ('EcoLife', '123456789W8', 'ecolife@example.com', '12345678908', 'sustainability,environment', 3);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, fk_sector) VALUES ('FinTrack', '123456789W9', 'fintrack@example.com', '12345678909', 'finance,investment', 4);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, fk_sector) VALUES ('EduSphere', '123456789W0', 'edusphere@example.com', '12345678900', 'education,elearning', 5);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, fk_sector) VALUES ('GreenTech', '123456789W6', 'greentech@example.com', '12345678906', 'renewable,energy', 1);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, fk_sector) VALUES ('FoodJoy', '123456789W7', 'foodjoy@example.com', '12345678907', 'food,delivery', 2);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, fk_sector) VALUES ('FitLife', '123456789W8', 'fitlife@example.com', '12345678908', 'fitness,health', 3);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, fk_sector) VALUES ('WealthTrack', '123456789W9', 'wealthtrack@example.com', '12345678909', 'finance,investment', 4);
INSERT INTO empresas (nombre, cif, correo, telefono, keywords, fk_sector) VALUES ('LearnSphere', '123456789W0', 'learnsphere@example.com', '12345678900', 'education,elearning', 5);
-- Insert into Contacto table
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, Empresa_id) VALUES ('Juan', 'Gonzales','Gonzales' , 'juan@example.com', '12345678901', 1);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, Empresa_id) VALUES ('Estaban', 'Smit', 'Lokasto', '', '12345678902', 2);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, empresa_id) VALUES ('Pablo', 'Lodrego',null , 'pablo@example.com', '12345678903', 3);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, empresa_id) VALUES ('David', 'Borgia', 'Algosto', 'david4@example.com', '12345678904', 4);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, empresa_id) VALUES ('Logan', 'Porlot',null , 'logan@example.com', null, 5);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, empresa_id) VALUES ('John', 'Doe', 'Smith', 'john.techflow@example.com', '12345678906', 6);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, empresa_id) VALUES ('Jane', 'Doe', 'Johnson', 'jane.healthfirst@example.com', '12345678907', 7);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, empresa_id) VALUES ('Robert', 'Smith', 'Johnson', 'robert.ecolife@example.com', '12345678908', 8);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, empresa_id) VALUES ('Emily', 'Johnson', 'Smith', 'emily.fintrack@example.com', '12345678909', 9);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, empresa_id) VALUES ('James', 'Brown', 'Johnson', 'james.edusphere@example.com', '12345678900', 10);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, empresa_id) VALUES ('Michael', 'Jackson', 'Smith', 'michael.greentech@example.com', '12345678906', 11);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, empresa_id) VALUES ('Emma', 'Watson', 'Johnson', 'emma.foodjoy@example.com', '12345678907', 12);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, empresa_id) VALUES ('Tom', 'Cruise', 'Smith', 'tom.fitlife@example.com', '12345678908', 13);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, empresa_id) VALUES ('Jennifer', 'Lawrence', 'Johnson', 'jennifer.wealthtrack@example.com', '12345678909', 14);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, empresa_id) VALUES ('Chris', 'Hemsworth', 'Smith', 'chris.learnsphere@example.com', '12345678900', 15);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES ('Juan', 'Gonzales','Gonzales' , 'juan@example.com', '12345678901', 1);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES ('Estaban', 'Smit', 'Lokasto', '', '12345678902', 2);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES ('Pablo', 'Lodrego',null , 'pablo@example.com', '12345678903', 3);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES ('David', 'Borgia', 'Algosto', 'david4@example.com', '12345678904', 4);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES ('Logan', 'Porlot',null , 'logan@example.com', null, 5);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES ('John', 'Doe', 'Smith', 'john.techflow@example.com', '12345678906', 6);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES ('Jane', 'Doe', 'Johnson', 'jane.healthfirst@example.com', '12345678907', 7);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES ('Robert', 'Smith', 'Johnson', 'robert.ecolife@example.com', '12345678908', 8);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES ('Emily', 'Johnson', 'Smith', 'emily.fintrack@example.com', '12345678909', 9);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES ('James', 'Brown', 'Johnson', 'james.edusphere@example.com', '12345678900', 10);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES ('Michael', 'Jackson', 'Smith', 'michael.greentech@example.com', '12345678906', 11);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES ('Emma', 'Watson', 'Johnson', 'emma.foodjoy@example.com', '12345678907', 12);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES ('Tom', 'Cruise', 'Smith', 'tom.fitlife@example.com', '12345678908', 13);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES ('Jennifer', 'Lawrence', 'Johnson', 'jennifer.wealthtrack@example.com', '12345678909', 14);
INSERT INTO contactos (nombre, apellido, apellido2, correo, telefono, fk_empressa) VALUES ('Chris', 'Hemsworth', 'Smith', 'chris.learnsphere@example.com', '12345678900', 15);
-- Insert into Sucursal table
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, empresa_id) VALUES ('Sucursal1', 'Denia', 'Calle 123', true, 1);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, empresa_id) VALUES ('Sucursal2', 'Javea', 'Calle Verdadera 123', true, 2);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, empresa_id) VALUES ('Sucursal3', 'Teulada', 'Calle Alog 123', true, 3);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, empresa_id) VALUES ('Sucursal4', 'Benitachell', 'Calle Loco 123', true, 4);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, empresa_id) VALUES ('Sucursal5', 'Benissa', 'Calle Norm 123', true, 5);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, empresa_id) VALUES ('Sucursal6', 'City6', 'Street 123', true, 6);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, empresa_id) VALUES ('Sucursal7', 'City7', 'Street 456', true, 7);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, empresa_id) VALUES ('Sucursal8', 'City8', 'Street 789', true, 8);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, empresa_id) VALUES ('Sucursal9', 'City9', 'Street 321', true, 9);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, empresa_id) VALUES ('Sucursal10', 'City10', 'Street 654', true, 10);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, empresa_id) VALUES ('Sucursal11', 'City11', 'Street 987', true, 11);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, empresa_id) VALUES ('Sucursal12', 'City12', 'Street 135', true, 12);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, empresa_id) VALUES ('Sucursal13', 'City13', 'Street 246', true, 13);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, empresa_id) VALUES ('Sucursal14', 'City14', 'Street 579', true, 14);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, empresa_id) VALUES ('Sucursal15', 'City15', 'Street 753', true, 15);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, fk_empressa) VALUES ('Sucursal1', 'Denia', 'Calle 123', true, 1);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, fk_empressa) VALUES ('Sucursal2', 'Javea', 'Calle Verdadera 123', true, 2);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, fk_empressa) VALUES ('Sucursal3', 'Teulada', 'Calle Alog 123', true, 3);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, fk_empressa) VALUES ('Sucursal4', 'Benitachell', 'Calle Loco 123', true, 4);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, fk_empressa) VALUES ('Sucursal5', 'Benissa', 'Calle Norm 123', true, 5);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, fk_empressa) VALUES ('Sucursal6', 'City6', 'Street 123', true, 6);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, fk_empressa) VALUES ('Sucursal7', 'City7', 'Street 456', true, 7);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, fk_empressa) VALUES ('Sucursal8', 'City8', 'Street 789', true, 8);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, fk_empressa) VALUES ('Sucursal9', 'City9', 'Street 321', true, 9);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, fk_empressa) VALUES ('Sucursal10', 'City10', 'Street 654', true, 10);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, fk_empressa) VALUES ('Sucursal11', 'City11', 'Street 987', true, 11);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, fk_empressa) VALUES ('Sucursal12', 'City12', 'Street 135', true, 12);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, fk_empressa) VALUES ('Sucursal13', 'City13', 'Street 246', true, 13);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, fk_empressa) VALUES ('Sucursal14', 'City14', 'Street 579', true, 14);
INSERT INTO sucursales (nombre, localidad, direccion, sede_central, fk_empressa) VALUES ('Sucursal15', 'City15', 'Street 753', true, 15);
-- Insert into Oferta table
INSERT INTO Ofertas (nombre, descripcion, fecha, sucursal_id) VALUES ('Oferta1', 'Description1', '2023-01-11', 1);
INSERT INTO Ofertas (nombre, descripcion, fecha, sucursal_id) VALUES ('Oferta2', 'Description2', '2023-01-12', 2);
INSERT INTO Ofertas (nombre, descripcion, fecha, sucursal_id) VALUES ('Oferta3', 'Description3', '2023-01-13', 3);
INSERT INTO Ofertas (nombre, descripcion, fecha, sucursal_id) VALUES ('Oferta4', 'Description4', '2023-01-14', 4);
INSERT INTO Ofertas (nombre, descripcion, fecha, sucursal_id) VALUES ('Oferta5', 'Description5', '2023-01-15', 5);
INSERT INTO Ofertas (nombre, descripcion, fecha, sucursal_id) VALUES ('Oferta6', 'Description6', '2023-01-16', 6);
INSERT INTO Ofertas (nombre, descripcion, fecha, sucursal_id) VALUES ('Oferta7', 'Description7', '2023-01-17', 7);
INSERT INTO Ofertas (nombre, descripcion, fecha, sucursal_id) VALUES ('Oferta8', 'Description8', '2023-01-18', 8);
INSERT INTO Ofertas (nombre, descripcion, fecha, sucursal_id) VALUES ('Oferta9', 'Description9', '2023-01-19', 9);
INSERT INTO Ofertas (nombre, descripcion, fecha, sucursal_id) VALUES ('Oferta10', 'Description10', '2023-01-20', 10);
INSERT INTO Ofertas (nombre, descripcion, fecha, sucursal_id) VALUES ('Oferta11', 'Description11', '2023-01-21', 11);
INSERT INTO Ofertas (nombre, descripcion, fecha, sucursal_id) VALUES ('Oferta12', 'Description12', '2023-01-22', 12);
INSERT INTO Ofertas (nombre, descripcion, fecha, sucursal_id) VALUES ('Oferta13', 'Description13', '2023-01-23', 13);
INSERT INTO Ofertas (nombre, descripcion, fecha, sucursal_id) VALUES ('Oferta14', 'Description14', '2023-01-24', 14);
INSERT INTO Ofertas (nombre, descripcion, fecha, sucursal_id) VALUES ('Oferta15', 'Description15', '2023-01-25', 15);
INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('Oferta1', 'Description1', '2023-01-11', 1,1);
INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('Oferta2', 'Description2', '2023-01-12', 2,2);
INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('Oferta3', 'Description3', '2023-01-13', 3,3);
INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('Oferta4', 'Description4', '2023-01-14', 4,1);
INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('Oferta5', 'Description5', '2023-01-15', 5,2);
INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('Oferta6', 'Description6', '2023-01-16', 6,3);
INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('Oferta7', 'Description7', '2023-01-17', 7,4);
INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('Oferta8', 'Description8', '2023-01-18', 8,4);
INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('Oferta9', 'Description9', '2023-01-19', 9,4);
INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('Oferta10', 'Description10', '2023-01-20', 10,5);
INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('Oferta11', 'Description11', '2023-01-21', 11,5);
INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('Oferta12', 'Description12', '2023-01-22', 12,1);
INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('Oferta13', 'Description13', '2023-01-23', 13,2);
INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('Oferta14', 'Description14', '2023-01-24', 14,3);
INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('Oferta15', 'Description15', '2023-01-25', 15,2);
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (1, 1); -- Jorge with Java

@ -66,7 +66,8 @@ public class Alumno {
private String keywords;
@ManyToMany(cascade = {CascadeType.ALL},fetch = FetchType.EAGER)
@ManyToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH},fetch = FetchType.EAGER)
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinTable(
name = "Alumno_Skill",
joinColumns = @JoinColumn(name = "fk_alumno",referencedColumnName = "id"),
@ -74,8 +75,8 @@ public class Alumno {
)
private Set<Skill> skills;
@ManyToOne(cascade = {CascadeType.ALL},fetch = FetchType.EAGER)
@JoinColumn(name = "Ciclo_id",referencedColumnName = "id")
@ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH},fetch = FetchType.EAGER)
@JoinColumn(name = "fk_ciclo",referencedColumnName = "id")
@OnDelete(action = OnDeleteAction.CASCADE)
private Ciclo ciclo;

@ -28,8 +28,8 @@ public class Ciclo {
@Column(length = 70)
private String codigo;
@ManyToOne(cascade = {CascadeType.ALL},fetch = FetchType.EAGER)
@JoinColumn(name = "Familia_id",referencedColumnName = "id")
@ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH},fetch = FetchType.EAGER)
@JoinColumn(name = "fk_familia",referencedColumnName = "id")
@OnDelete(action = OnDeleteAction.CASCADE)
private Familia familia;

@ -37,8 +37,8 @@ public class Contacto {
@Column(length = 70)
private String telefono;
@ManyToOne(cascade = {CascadeType.ALL},fetch = FetchType.LAZY)
@JoinColumn(name = "Empresa_id",referencedColumnName = "id")
@ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH},fetch = FetchType.LAZY)
@JoinColumn(name = "fk_empressa",referencedColumnName = "id")
@OnDelete(action = OnDeleteAction.CASCADE)
private Empresa empresa;

@ -39,8 +39,8 @@ public class Empresa {
@Column(length = 2500)
private String keywords;
@ManyToOne(cascade = {CascadeType.ALL},fetch = FetchType.EAGER)
@JoinColumn(name = "Sector_id",referencedColumnName = "id")
@ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH},fetch = FetchType.EAGER)
@JoinColumn(name = "fk_sector",referencedColumnName = "id")
@OnDelete(action = OnDeleteAction.CASCADE)
private Sector sector;

@ -34,12 +34,18 @@ public class Oferta {
@ManyToOne(cascade = {CascadeType.ALL},fetch = FetchType.EAGER)
@JoinColumn(name = "Sucursal_id")
@ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH},fetch = FetchType.EAGER)
@JoinColumn(name = "fk_sucursal",referencedColumnName = "id")
@OnDelete(action = OnDeleteAction.CASCADE)
private Sucursal sucursal;
@ManyToMany(cascade = {CascadeType.ALL},fetch = FetchType.EAGER)
@ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH},fetch = FetchType.EAGER)
@JoinColumn(name = "fk_ciclo",referencedColumnName = "id")
@OnDelete(action = OnDeleteAction.CASCADE)
private Ciclo ciclo;
@ManyToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH},fetch = FetchType.EAGER)
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinTable(
name = "Oferta_Skill",
joinColumns = @JoinColumn(name = "fk_oferta",referencedColumnName = "id"),

@ -5,6 +5,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import java.util.Set;

@ -35,8 +35,8 @@ public class Sucursal {
@Name("sede_central")
private boolean sedeCentral;
@ManyToOne(cascade = {CascadeType.ALL},fetch = FetchType.LAZY)
@JoinColumn(name = "Empresa_id")
@ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH},fetch = FetchType.LAZY)
@JoinColumn(name = "fk_empressa", referencedColumnName = "id")
@OnDelete(action = OnDeleteAction.CASCADE)
private Empresa empresa;

@ -8,9 +8,8 @@ import org.springframework.data.jpa.repository.Query;
import java.util.ArrayList;
public interface AlumnoRepository extends JpaRepository<Alumno, Long> {
//TODO alter query so in like all the other elemnts are included
@Query(value = "SELECT * FROM alumnos u WHERE MATCH(u.nombre, u.keywords, " +
"u.apellido, u.apellido2, u.correo, u.correo2, u.nacionalidad, u.genero, u.dni, u.nia ) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
public ArrayList<Alumno> getAlumnoByKeywordsOrName(String keyword1);
// @Query(value = "SELECT * FROM alumnos u WHERE MATCH(u.nombre, u.keywords, " +
// "u.apellido, u.apellido2, u.correo, u.correo2, u.nacionalidad, u.genero, u.dni, u.nia ) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
// public ArrayList<Alumno> getAlumnoByKeywordsOrName(String keyword1);
}

@ -9,8 +9,8 @@ import java.util.ArrayList;
public interface CicloRepository extends JpaRepository<Ciclo, Long> {
@Query(value = "SELECT * FROM ciclos u WHERE MATCH(u.nombre, u.familias) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
public Ciclo getCicloByKeywordsOrName(String keyword1);
// @Query(value = "SELECT * FROM ciclos u WHERE MATCH(u.nombre, u.familias) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
// public Ciclo getCicloByKeywordsOrName(String keyword1);
@Query(value = "Select * from ciclos c where c.familia_id = ?1", nativeQuery = true)
public ArrayList<Ciclo> findCicloByFamiliaId(Long id);

@ -7,9 +7,18 @@ import org.springframework.data.jpa.repository.Query;
import java.util.ArrayList;
public interface ContactoRepository extends JpaRepository<Contacto, Long> {
@Query("SELECT c FROM Contacto c WHERE c.empresa.sector.id = ?1")
@Query("SELECT c FROM Contacto c WHERE c.empresa.id = ?1")
ArrayList<Contacto> findBySector(Long id);
@Query(value = "SELECT * FROM contactos u WHERE MATCH(u.nombre, u.apellido,u.apellido2, u.correo, u.telefono) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
public ArrayList<Contacto> getContactoFullTextSeach(String keyword1);
// @Query(value = "SELECT * FROM contactos u WHERE MATCH(u.nombre, u.apellido,u.apellido2, u.correo, u.telefono) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
// public ArrayList<Contacto> getContactoFullTextSeach(String keyword1);
@Query(value="Delete from contactos where fk_empressa =?1", nativeQuery = true)
public void deleteByEmpresaId(Long id);
@Query(value="SELECT * FROM contactos WHERE fk_empressa = ?1", nativeQuery = true)
public ArrayList<Contacto> findByEmpresaId(Long id);
@Query(value="SELECT * FROM contactos WHERE nombre=?1", nativeQuery = true)
boolean existsByNombre(String nombre);
}

@ -18,13 +18,13 @@ public interface EmpressaRepository extends JpaRepository<Empresa, Long>, JpaSpe
// @Query(value = "SELECT * FROM empresas u WHERE MATCH(u.nombre, u.keywords) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
// public ArrayList<Empresa> getEmpressaByKeywordsOrName(String word);
@Query(value = "SELECT * FROM empresas u WHERE u.sector_id = ?1", nativeQuery = true)
@Query(value = "SELECT * FROM empresas u WHERE u.fk_sector = ?1", nativeQuery = true)
public ArrayList<Empresa> findBySector(Long id);
@Query(value = "SELECT * FROM empresas order by id Asc", nativeQuery = true)
List<Empresa> findAllAsc();
@Query("SELECT e FROM Empresa e WHERE e.nombre LIKE %:query% OR e.cif LIKE %:query% OR e.correo LIKE %:query% OR e.telefono LIKE %:query% OR e.keywords LIKE %:query% OR e.sector.nombre LIKE %:query%")
@Query("SELECT e FROM Empresa e WHERE e.nombre LIKE %:query% OR e.cif LIKE %:query% OR e.correo LIKE %:query% OR e.telefono LIKE %:query% OR e.keywords LIKE %:query% OR e.sector.nombre LIKE %:query% OR CAST(e.id AS string) = :query")
List<Empresa> search(@Param("query") String query);
@Query("SELECT e FROM Empresa e WHERE e.cif = :cif")

@ -7,8 +7,8 @@ import org.springframework.data.jpa.repository.Query;
import java.util.Optional;
public interface FamiliaRepository extends JpaRepository<Familia, Long> {
@Query(value = "SELECT * FROM familias u WHERE MATCH(u.nombre) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
public Familia getFamiliaFullTextSeach(String keyword1);
// @Query(value = "SELECT * FROM familias u WHERE MATCH(u.nombre) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
// public Familia getFamiliaFullTextSeach(String keyword1);
@Query(value = "SELECT * FROM familias u WHERE MATCH(u.nombre) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
Optional<Object> findByName(String name);

@ -2,12 +2,26 @@ package com.example.proyectofinal.repositories.empresas;
import com.example.proyectofinal.models.empresas.Oferta;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.util.ArrayList;
import java.util.List;
public interface OfertaRepository extends JpaRepository<Oferta, Long> {
@Query(value = "SELECT * FROM ofertas u WHERE MATCH(u.nombre, u.fecha) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
public ArrayList<Oferta> getOfertaFullTextSeach(String word);
// @Query(value = "SELECT * FROM ofertas u WHERE MATCH(u.nombre, u.fecha) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
// public ArrayList<Oferta> getOfertaFullTextSeach(String word);
@Query(value="Select * from ofertas where fk_sucursal = ?1", nativeQuery = true)
public List<Oferta> findBySucursalId(Long id);
@Query(value="Select * from ofertas where fk_ciclo = ?1", nativeQuery = true)
public List<Oferta> findBySCiclolId(Long id);
@Modifying
@Query(value = "DELETE FROM oferta_skill WHERE fk_oferta = ?1", nativeQuery = true)
void deleteSkillsByOfertaId(Long id);
}

@ -3,13 +3,20 @@ package com.example.proyectofinal.repositories.empresas;
import com.example.proyectofinal.models.empresas.Sector;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
public interface SectorRepository extends JpaRepository<Sector, Long> {
@Query("SELECT s FROM Sector s WHERE s.nombre = ?1")
Sector findByNombre(String nombre);
@Query(value = "SELECT * FROM sectores u WHERE MATCH(u.nombre) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
public Sector getSectorFullTextSeach(String word);
@Query("SELECT s FROM Sector s WHERE s.nombre LIKE %:query% OR CAST(s.id AS string) LIKE %:query%")
List<Sector> search(@Param("query") String query);
// @Query(value = "SELECT * FROM sectores u WHERE MATCH(u.nombre) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
// public Sector getSectorFullTextSeach(String word);
}

@ -8,7 +8,9 @@ import java.util.ArrayList;
public interface SkillRepository extends JpaRepository<Skill, Long> {
@Query(value = "SELECT * FROM skills u WHERE MATCH(u.nombre) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
public ArrayList<Skill> getSkillFullTextSeach(String word);
// @Query(value = "SELECT * FROM skills u WHERE MATCH(u.nombre) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
// public ArrayList<Skill> getSkillFullTextSeach(String word);
}

@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.ArrayList;
import java.util.List;
public interface SucursalRepository extends JpaRepository<Sucursal, Long> {
@ -12,6 +13,6 @@ public interface SucursalRepository extends JpaRepository<Sucursal, Long> {
// @Query(value = "SELECT * FROM sucursales u WHERE MATCH(u.nombre, u.localidad,u.direccion) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
// public ArrayList<Sucursal> getSucursalFullTextSeach(String word);
@Query(value="Delete from sucursales where empresa_id =?1", nativeQuery = true)
public void deleteAllSucursalByEmpresaId(Long id);
@Query(value="Select * from sucursales where fk_empressa = ?1", nativeQuery = true)
public List<Sucursal> findByEmpresaId(Long id);
}

@ -1,9 +1,13 @@
package com.example.proyectofinal.servicios;
import com.example.proyectofinal.models.empresas.Contacto;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.servicios.implemetations.IContactos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import com.example.proyectofinal.repositories.empresas.ContactoRepository;
@ -22,7 +26,11 @@ public class ContactosService implements IContactos {
@Override
public Page<Contacto> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir) {
return null;
Sort sort = sortDir.equalsIgnoreCase(Sort.Direction.ASC.name())
? Sort.by(sortField).ascending() :
Sort.by(sortField).descending();
Pageable pageable = PageRequest.of(pageNum - 1,pageSize,sort);
return this.contactoRepository.findAll(pageable);
}
@Override
@ -49,4 +57,17 @@ public class ContactosService implements IContactos {
public List<Contacto> search(String query) {
return List.of();
}
@Override
public void deleteByEmpresa(Empresa empresa) {
List<Contacto> contactos = contactoRepository.findByEmpresaId(empresa.getId());
for (Contacto contacto : contactos) {
contactoRepository.deleteById(contacto.getId());
}
}
@Override
public boolean exists(Contacto contacto) {
return contactoRepository.existsByNombre(contacto.getNombre());
}
}

@ -1,8 +1,13 @@
package com.example.proyectofinal.servicios;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.models.empresas.Oferta;
import com.example.proyectofinal.models.empresas.Sucursal;
import com.example.proyectofinal.repositories.empresas.EmpressaRepository;
import com.example.proyectofinal.repositories.empresas.OfertaRepository;
import com.example.proyectofinal.repositories.empresas.SkillRepository;
import com.example.proyectofinal.servicios.implemetations.IEmpresa;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@ -10,6 +15,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@ -23,6 +29,8 @@ public class EmpresaService implements IEmpresa {
private SucursalService sucursalService;
@Autowired
private OfertaService ofertaService;
@Autowired
private OfertaRepository ofertaRepository;
@Override
@ -49,11 +57,22 @@ public class EmpresaService implements IEmpresa {
return empressaRepository.save(empresa);
}
@Transactional
@Override
public void deleteById(Long id) {
Empresa empresa = empressaRepository.findById(id).orElse(null);
if(empresa != null){
if (empresa != null) {
contactosService.deleteByEmpresa(empresa);
List<Sucursal> sucursales = sucursalService.findByEmpresa(empresa);
for (Sucursal sucursal : sucursales) {
List<Oferta> ofertas = ofertaService.findBySucursal(sucursal);
for (Oferta oferta : ofertas) {
ofertaRepository.deleteSkillsByOfertaId(oferta.getId());
ofertaService.deleteById(oferta.getId());
}
sucursalService.deleteById(sucursal.getId());
}
empressaRepository.deleteById(id);
}
}
@ -68,5 +87,10 @@ public class EmpresaService implements IEmpresa {
return empressaRepository.existsCif(cif);
}
@Override
public List<Empresa> findBySector(Long id) {
return empressaRepository.findBySector(id);
}
}

@ -1,6 +1,7 @@
package com.example.proyectofinal.servicios;
import com.example.proyectofinal.models.empresas.Oferta;
import com.example.proyectofinal.models.empresas.Sucursal;
import com.example.proyectofinal.repositories.empresas.OfertaRepository;
import com.example.proyectofinal.servicios.implemetations.IOferta;
import org.springframework.beans.factory.annotation.Autowired;
@ -48,4 +49,9 @@ public class OfertaService implements IOferta {
public List<Oferta> search(String query) {
return List.of();
}
@Override
public List<Oferta> findBySucursal(Sucursal sucursal) {
return ofertaRepository.findBySucursalId(sucursal.getId());
}
}

@ -1,10 +1,17 @@
package com.example.proyectofinal.servicios;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.models.empresas.Oferta;
import com.example.proyectofinal.models.empresas.Sector;
import com.example.proyectofinal.models.empresas.Sucursal;
import com.example.proyectofinal.repositories.empresas.OfertaRepository;
import com.example.proyectofinal.repositories.empresas.SectorRepository;
import com.example.proyectofinal.servicios.implemetations.ISector;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import java.util.List;
@ -13,6 +20,17 @@ public class SectorService implements ISector {
@Autowired
private SectorRepository sectorRepository;
@Autowired
private EmpresaService empresaService;
@Autowired
private ContactosService contactosService;
@Autowired
private SucursalService sucursalService;
@Autowired
private OfertaService ofertaService;
@Autowired
private OfertaRepository ofertaRepository;
@Override
public List<Sector> findAll() {
@ -21,7 +39,11 @@ public class SectorService implements ISector {
@Override
public Page<Sector> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir) {
return null;
Sort sort = sortDir.equalsIgnoreCase(Sort.Direction.ASC.name())
? Sort.by(sortField).ascending() :
Sort.by(sortField).descending();
Pageable pageable = PageRequest.of(pageNum - 1,pageSize,sort);
return this.sectorRepository.findAll(pageable);
}
@Override
@ -41,11 +63,19 @@ public class SectorService implements ISector {
@Override
public void deleteById(Long id) {
List<Empresa> empresas = empresaService.findBySector(id);
for (Empresa empresa : empresas) {
empresaService.deleteById(empresa.getId());
}
sectorRepository.deleteById(id);
}
@Override
public List<Sector> search(String query) {
return List.of();
return sectorRepository.search(query);
}
public boolean exists(Sector sector) {
return sectorRepository.findByNombre(sector.getNombre()) != null;
}
}

@ -1,5 +1,6 @@
package com.example.proyectofinal.servicios;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.models.empresas.Sucursal;
import com.example.proyectofinal.repositories.empresas.SucursalRepository;
import com.example.proyectofinal.servicios.implemetations.ISucursal;
@ -48,4 +49,10 @@ public class SucursalService implements ISucursal {
public List<Sucursal> search(String query) {
return List.of();
}
@Override
public List<Sucursal> findByEmpresa(Empresa empresa) {
return sucursalRepository.findByEmpresaId(empresa.getId());
}
}

@ -1,6 +1,7 @@
package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.models.empresas.Contacto;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.models.empresas.Sucursal;
import org.springframework.data.domain.Page;
@ -20,4 +21,8 @@ public interface IContactos {
void deleteById(Long id);
List<Contacto> search(String query);
void deleteByEmpresa(Empresa empresa);
boolean exists(Contacto contacto);
}

@ -21,4 +21,6 @@ public interface IEmpresa {
Empresa exists(Empresa empresa);
List<Empresa> findBySector(Long id);
}

@ -1,6 +1,7 @@
package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.models.empresas.Oferta;
import com.example.proyectofinal.models.empresas.Sucursal;
import org.springframework.data.domain.Page;
import java.util.List;
@ -19,4 +20,6 @@ public interface IOferta {
void deleteById(Long id);
List<Oferta> search(String query);
List<Oferta> findBySucursal(Sucursal sucursal);
}

@ -19,4 +19,6 @@ public interface ISector {
void deleteById(Long id);
List<Sector> search(String query);
public boolean exists(Sector sector);
}

@ -1,5 +1,6 @@
package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.models.empresas.Sucursal;
import org.springframework.data.domain.Page;
@ -19,4 +20,6 @@ public interface ISucursal {
void deleteById(Long id);
List<Sucursal> search(String query);
List<Sucursal> findByEmpresa(Empresa empresa);
}

@ -13,19 +13,31 @@
<body>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
<h1>Listado de Ofertas<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<h1>Listado de Alumnos<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<div class="table">
<table class ="table table-hover table-responsive-xl">
<thead class="thread-light">
<tr>
<th>Id</th>
<th>Nombre</th>
<th>Apellido 1</th>
<th>Apellido 2</th>
<th>Correo</th>
<th>Telefono</th>
<th>Empressa</th>
</tr>
</thead>
<tbody>
<tr class="cell" th:each="sector :${sectores}">
<td>[[${sector.id}]]</td>
<td><a th:href="@{/sector/{id}(id=${sector.id})}">[[${sector.nombre}]]</a></td>
<tr class="cell" th:each="contacto :${contactos}">
<td>[[${contacto.id}]]</td>
<td>[[${contacto.nombre}]]</td>
<td>[[${contacto.apellido}]]</td>
<td>[[${contacto.apellido2}]]</td>
<td>[[${contacto.correo}]]</td>
<td>[[${contacto.telefono}]]</td>
<td>[[${contacto.empresa.nombre}]]</td>
</tr>
</tbody>
</table>

@ -1,34 +0,0 @@
$(document).ready(function() {
$("#modal-container").load("/empresas/createEmpresaModal");
});
$(document).ready(function() {
// Load the modal HTML into #modal-container
$("#modal-container").load("/empresas/createEmpresaModal", function() {
// Get the modal
var modal = document.getElementById("empresaCreateModal");
// Get the button that opens the modal
var btn = document.getElementById("create-icon");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
});
});

@ -0,0 +1,147 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Creacion: Empresa</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" th:href="@{/top.css}">
<style>
form {
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
width: 100%;
max-width: none;
margin: auto;
padding: 25px;
margin-top: 100px;
}
.btn {
margin-top: 25px;
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
}
form input[type="submit"], form input[type="button"] {
width: 100px;
}
form input[type="text"]{
width: 75%;
}
form label{
font-size: 20px;
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
body, h1 {
margin: 0;
padding: 0;
width: 100%;
box-sizing: border-box;
}
</style>
</head>
<body>
<h1>Añadir Empresa<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<form th:action="@{/contacto/save}" method="post" enctype="multipart/form-data" th:object="${contacto}">
<input type="hidden" th:field="*{id}"/>
<div class="p-3">
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="nombre">Nombre</label>
<div class = "col-sm-9">
<input type="text" th:field="*{nombre}" required minlength="2" maxlength="128" class="form-control" id="nombre">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="cif">Apellido</label>
<div class = "col-sm-9">
<input type="text" th:field="*{apellido}" title="Entra un nombre" class="form-control" id="cif">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="apellido2">Apellido2</label>
<div class = "col-sm-9">
<input type="text" th:field="*{apellido2}" class="form-control" id="apellido2">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="correo">Correo</label>
<div class = "col-sm-9">
<input type="text" th:field="*{correo}" required pattern="^\d{10}$" title="Entra un numero de telefono valido de 10 digitos" class="form-control" id="correo">
</div>
</div>
<!--
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="Telefono">Keywords</label>
<div class = "col-sm-9">
<input type="text" th:field="*{keywords}" required pattern="([a-zA-Z0-9]+,)*[a-zA-Z0-9]+" title="Los keywords tiene que ser separados por una ," class="form-control" id="keywords">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="sector">Empresas</label>
<div class = "col-sm-9">
<select th:field="*{sector.id}" class="form-control" id="sector">
<option th:each="sector : ${sectores}" th:value="${sector.id}" th:text="${sector.nombre}"></option>
</select>
</div>
</div>
<div class="text-center">
<input type="submit" value="Guardar" class="btn"/>
<input type="button" value="Cancelar" id="btnCancelar" class="btn" onclick="goBack()"/>
</div>
</div>
</form>-->
<script>
function goBack() {
console.log("goBack function called");
window.history.back();
}
$(document).ready(function () {
$("form").on("submit", function (event) {
event.preventDefault();
var formData = $(this).serialize();
var sectorId = $('#sector').val();
formData += '&sector=' + encodeURIComponent(sectorId);
$.ajax({
url: '/empresa/save',
type: 'post',
data: formData,
success: function (message) {
if(message === "La empresa fue guardado con exito") {
alert("La empresa fue guardado con exito")
window.history.go(-1); // Go back two pages
} else if(message === "Este empresa ya existe en la base de datos"){
alert("Este empresa ya existe en la base de datos");
window.history.go(-1);
}else{
alert("Error, consulata a los informaticos")
window.history.go(-1)
}
},
error: function (jqXHR) {
alert(jqXHR.responseText);
window.history.back();
}
});
});
});
</script>
</body>
</html>

@ -0,0 +1,145 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Update: Empresa</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" th:href="@{/top.css}">
<style>
form {
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
width: 100%;
max-width: none;
margin: auto;
padding: 25px;
margin-top: 100px;
}
.btn {
margin-top: 25px;
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
}
form input[type="submit"], form input[type="button"] {
width: 100px;
}
form input[type="text"]{
width: 75%;
}
form label{
font-size: 20px;
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
body, h1 {
margin: 0;
padding: 0;
width: 100%;
box-sizing: border-box;
}
</style>
</head>
<body>
<h1>Editar datos de Empresa<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<form th:action="@{/empresa/update}" method="post" enctype="multipart/form-data" th:object="${empresa}">
<input type="hidden" th:field="*{id}"/>
<div class="p-3">
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="nombre">Nombre</label>
<div class = "col-sm-9">
<input type="text" th:field="*{nombre}" th:value="*{nombre}" required minlength="2" maxlength="128" class="form-control" id="nombre">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="cif">Cif</label>
<div class = "col-sm-9">
<input type="text" th:field="*{cif}" th:value="*{cif}" required pattern="^[A-HJ-NP-SUVW]{1}[0-9]{7}[0-9A-J]{1}$" title="Entra un cif valido eje. W12345678" class="form-control" id="cif">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="correo">Correo</label>
<div class = "col-sm-9">
<input type="text" th:field="*{correo}" th:value="*{correo}" required pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" title="Entra en correo valido." class="form-control" id="correo">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="telefono">Telefono</label>
<div class = "col-sm-9">
<input type="text" th:field="*{telefono}" th:value="*{telefono}" required pattern="^\d{10}$" title="Entra un numero de telefono valido de 10 digitos" class="form-control" id="telefono">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="keywords">Keywords</label>
<div class = "col-sm-9">
<input type="text" th:field="*{keywords}" th:value="*{keywords}" required pattern="([a-zA-Z0-9]+,)*[a-zA-Z0-9]+" title="Los keywords tiene que ser separados por una ," class="form-control" id="keywords">
</div>
</div>
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="sector">Sector</label>
<div class = "col-sm-9">
<select th:field="*{sector.id}" class="form-control" id="sector">
<option th:each="sector : ${sectores}" th:value="${sector.id}" th:text="${sector.nombre}" th:selected="${sector.id == empresa.sector.id}"></option>
</select>
</div>
</div>
<div class="text-center">
<input type="submit" value="Guardar" class="btn"/>
<input type="button" value="Cancelar" id="btnCancelar" class="btn" onclick="goBack()"/>
</div>
</div>
</form>
<script>
function goBack() {
console.log("goBack function called");
window.history.back();
}
$(document).ready(function () {
$("form").on("submit", function (event) {
event.preventDefault();
var formData = $(this).serialize();
var sectorId = $('#sector').val();
formData += '&sector=' + encodeURIComponent(sectorId);
$.ajax({
url: '/empresa/update',
type: 'post',
data: formData,
success: function (message) {
if(message === "Los datos de la empresa fue renovados con exito") {
alert("Los datos de la empresa fue renovada con exito")
window.history.go(-1); // Go back two pages
}else{
alert("Error, consulata a los informaticos")
window.history.go(-1)
}
},
error: function (jqXHR) {
alert(jqXHR.responseText);
window.history.back();
}
});
});
});
</script>
</body>
</html>

@ -124,7 +124,7 @@
success: function (message) {
if(message === "La empresa fue guardado con exito") {
alert("La empresa fue guardado con exito")
window.history.go(-2); // Go back two pages
window.history.go(-1); // Go back two pages
} else if(message === "Este empresa ya existe en la base de datos"){
alert("Este empresa ya existe en la base de datos");
window.history.go(-1);

@ -125,7 +125,7 @@
success: function (message) {
if(message === "Los datos de la empresa fue renovados con exito") {
alert("Los datos de la empresa fue renovada con exito")
window.history.go(-2); // Go back two pages
window.history.go(-1); // Go back two pages
}else{
alert("Error, consulata a los informaticos")
window.history.go(-1)

@ -0,0 +1,107 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Creacion: Sector</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" th:href="@{/top.css}">
<style>
form {
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
width: 100%;
max-width: none;
margin: auto;
padding: 25px;
margin-top: 100px;
}
.btn {
margin-top: 25px;
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
}
form input[type="submit"], form input[type="button"] {
width: 100px;
}
form input[type="text"]{
width: 75%;
}
form label{
font-size: 20px;
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
body, h1 {
margin: 0;
padding: 0;
width: 100%;
box-sizing: border-box;
}
</style>
</head>
<body>
<h1>Añadir Sector<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<form th:action="@{/sector/save}" method="post" enctype="multipart/form-data" th:object="${sector}">
<input type="hidden" th:field="*{id}"/>
<div class="p-3">
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="nombre">Nombre</label>
<div class = "col-sm-9">
<input type="text" th:field="*{nombre}" required minlength="2" maxlength="128" class="form-control" id="nombre">
</div>
</div>
<div class="text-center">
<input type="submit" value="Guardar" class="btn"/>
<input type="button" value="Cancelar" id="btnCancelar" class="btn" onclick="goBack()"/>
</div>
</div>
</form>
<script>
function goBack() {
console.log("goBack function called");
window.history.back();
}
$(document).ready(function () {
$("form").on("submit", function (event) {
event.preventDefault();
var formData = $(this).serialize();
var sectorId = $('#sector').val();
formData += '&sector=';
$.ajax({
url: '/sector/save',
type: 'post',
data: formData,
success: function (message) {
if(message === "El sector fue guardado con exito") {
alert("El sector fue guardado con exito")
window.history.go(-1); // Go back two pages
} else if(message === "Este sector ya existe en la base de datos"){
alert("Este sector ya existe en la base de datos");
window.history.go(-1);
}else{
alert("Error, consulata a los informaticos")
window.history.go(-1)
}
},
error: function (jqXHR) {
alert(jqXHR.responseText);
window.history.back();
}
});
});
});
</script>
</body>
</html>

@ -0,0 +1,107 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Update: Sector</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" th:href="@{/top.css}">
<style>
form {
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
width: 100%;
max-width: none;
margin: auto;
padding: 25px;
margin-top: 100px;
}
.btn {
margin-top: 25px;
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
}
form input[type="submit"], form input[type="button"] {
width: 100px;
}
form input[type="text"]{
width: 75%;
}
form label{
font-size: 20px;
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
body, h1 {
margin: 0;
padding: 0;
width: 100%;
box-sizing: border-box;
}
</style>
</head>
<body>
<h1>Editar datos del Sector<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<form th:action="@{/sector/update}" method="post" enctype="multipart/form-data" th:object="${sector}">
<input type="hidden" th:field="*{id}"/>
<div class="p-3">
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="nombre">Nombre</label>
<div class = "col-sm-9">
<input type="text" th:field="*{nombre}" th:value="*{nombre}" required minlength="2" maxlength="128" class="form-control" id="nombre">
</div>
</div>
<div class="text-center">
<input type="submit" value="Guardar" class="btn"/>
<input type="button" value="Cancelar" id="btnCancelar" class="btn" onclick="goBack()"/>
</div>
</div>
</form>
<script>
function goBack() {
console.log("goBack function called");
window.history.back();
}
$(document).ready(function () {
$("form").on("submit", function (event) {
event.preventDefault();
var formData = $(this).serialize();
var sectorId = $('#sector').val();
formData += '&sector=';
$.ajax({
url: '/sector/update',
type: 'post',
data: formData,
success: function (message) {
if(message === "El sector ha sido actualizado") {
alert("El sector ha sido actualizado")
window.history.go(-1);
}else{
alert("Error, consulata a los informaticos")
window.history.go(-1)
}
},
error: function (jqXHR) {
alert(jqXHR.responseText);
window.history.back();
}
});
});
});
</script>
</body>
</html>

@ -57,7 +57,7 @@
</div>
<select name="searchOption" id="searchOption">
<option value="empresas">Empresa</option>
<option value="sectorer">Sector</option>
<option value="sectores">Sector</option>
<option value="alumnos" >Alumno</option>
<option value="ofertas">Oferta</option>
<option value="sucursales">Sucursal</option>

@ -3,36 +3,73 @@
<head>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">
<link rel="stylesheet" type="text/css" th:href="@{/style.css}">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<meta charset="UTF-8">
<title>Title</title>
<title>Lista: Sectore</title>
<style>
</style>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
<h1>Listado de Alumnos<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<div class="table">
<table class ="table table-hover table-responsive-xl">
<thead class="thread-light">
<tr>
<th>Id</th>
<th>Nombre</th>
<th>Apellido 1</th>
<th>Apellido 2</th>
<th>Correo</th>
<th>Telefono</th>
<th>Empressa</th>
<div class="header">
<button onclick="goBack()">Atras</button>
<h1>Listado de Sectores</h1>
<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a>
</div>
<input type="text" id="myInput" placeholder="Buscar por...."> <i class="fas fa-plus" id="create-icon"></i>
<div class="table-container">
<table class="table" id="table">
<thead class="thread-light">
<tr>
<th class="table-header">
<a th:href="@{'/buscador/contactos/page/' + ${currentPage} + '?sortField=id&sortDir=' + ${reverseSortDir}}">
Id
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/contactos/page/' + ${currentPage} + '?sortField=nombre&sortDir=' + ${reverseSortDir}}">
Nombre
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/contactos/page/' + ${currentPage} + '?sortField=apellido&sortDir=' + ${reverseSortDir}}">
Apellido
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/contactos/page/' + ${currentPage} + '?sortField=apellido2&sortDir=' + ${reverseSortDir}}">
Apellido2
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/contactos/page/' + ${currentPage} + '?sortField=correo2&sortDir=' + ${reverseSortDir}}">
Correo
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/contactos/page/' + ${currentPage} + '?sortField=telefono&sortDir=' + ${reverseSortDir}}">
Telefono
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/contactos/page/' + ${currentPage} + '?sortField=empresa.nombre&sortDir=' + ${reverseSortDir}}">
Sector
</a>
</th>
</tr>
</thead>
<tbody>
<tr class="cell" th:each="contacto :${contactos}">
<td>[[${contacto.id}]]</td>
<td>[[${contacto.nombre}]]</td>
<td>
[[${contacto.nombre}]]
<i id="edit-icon" class="fas fa-pen-square"></i>
<i id="delete-icon" class="fas fa-ban"></i>
</td>
<td>[[${contacto.apellido}]]</td>
<td>[[${contacto.apellido2}]]</td>
<td>[[${contacto.correo}]]</td>
@ -42,12 +79,141 @@
</tbody>
</table>
</div>
<button onclick="goBack()">Atras</button>
<div class="page">
<nav aria-label="Page navigation" id="paginationControls">
<ul class="pagination">
<li class="page-item" th:classappend="${currentPage == 1 ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Prim</a>
</li>
<li class="page-item" th:classappend="${currentPage == 1 ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${currentPage - 1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Ant</a>
</li>
<li class="page-item" th:each="pageNum : ${#numbers.sequence(1, totalPages)}" th:classappend="${pageNum eq currentPage ? 'active' : ''}">
<th:block th:if="${pageNum lt 3 or pageNum gt totalPages - 2 or pageNum eq currentPage - 2 or pageNum eq currentPage - 1 or pageNum eq currentPage or pageNum eq currentPage + 1 or pageNum eq currentPage + 2}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${pageNum} + '?query=' + ${query} + '&size=' + ${currentSize}}">[[${pageNum}]]</a>
</th:block>
<th:block th:if="${pageNum eq 3 and currentPage gt 5}">...</th:block>
<th:block th:if="${pageNum eq totalPages - 2 and currentPage lt totalPages - 4}">...</th:block>
</li>
<li class="page-item" th:classappend="${currentPage == totalPages ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${currentPage + 1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Sig</a>
</li>
<li class="page-item" th:classappend="${currentPage == totalPages ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${totalPages} + '?query=' + ${query} + '&size=' + ${currentSize}}">Ult</a>
</li>
</ul>
</nav>
</div>
<select id="entriesCount">
<option th:each="item : ${itemsPage}" th:value="${item}" th:text="${item}" th:selected="${item == currentSize}"></option>
</select>
<div id="modalDelete" class ="modal">
<div class="modal-content">
<p>¿Estas seguro que quires borar este elemnto?</p>
<span class="delete">Borar</span>
<span class="close">Cancelar</span>
</div>
</div>
<script src="/orderTable.js"></script>
<script>
function goBack() {
window.history.back();
}
document.querySelector('#myInput').addEventListener('input', function() {
var query = document.querySelector('#myInput').value;
var paginationControls = document.querySelector('#paginationControls');
var entriesCountDropdown = document.querySelector('#entriesCount');
if (query == '') {
// If the search bar is empty, show the pagination controls and the entries count dropdown, and reload the page
paginationControls.style.display = '';
entriesCountDropdown.style.display = '';
table.style.pointerEvents = '';
location.reload();
} else {
// If the search bar is not empty, hide the pagination controls and the entries count dropdown, and perform the search
paginationControls.style.display = 'none';
entriesCountDropdown.style.display = 'none';
table.style.pointerEvents = 'none';
fetch('/buscador/contactos/search?query=' + query)
.then(response => response.json())
.then(data => {
var tableBody = document.querySelector('#table tbody');
tableBody.innerHTML = '';
data.forEach(contacto => {
var row = document.createElement('tr');
row.innerHTML = `
<td>${contacto.id}</td>
<td>
${contacto.nombre}
<i id="edit-icon" class="fas fa-pen-square"></i>
<i id="delete-icon" class="fas fa-ban"></i>
</td>
<td>[[${contacto.apellido}]]</td>
<td>[[${contacto.apellido2}]]</td>
<td>[[${contacto.correo}]]</td>
<td>[[${contacto.telefono}]]</td>
<td>[[${contacto.empresa.nombre}]]</td>
`;
tableBody.appendChild(row);
});
});
}
});
<!--
document.getElementById('create-icon').addEventListener('click', function() {
window.location = "/admin/contacto/create";
});
document.querySelector('#table').addEventListener('click', function(event) {
if (event.target.matches('#edit-icon')) {
const rowId = event.target.closest('tr').firstElementChild.textContent;
window.location = "/admin/contacto/update/" + rowId;
} else if (event.target.matches('#delete-icon')) {
const rowId = event.target.closest('tr').firstElementChild.textContent;
var modal = document.getElementById("modalDelete");
var closeSpan = document.getElementsByClassName("close")[0];
var deleteSpan = document.getElementsByClassName("delete")[0];
modal.style.display = "block";
document.body.style.pointerEvents = 'none';
modal.style.pointerEvents = 'auto';
closeSpan.onclick = function() {
modal.style.display = "none";
document.body.style.pointerEvents = 'auto';
}
deleteSpan.onclick = function() {
$.ajax({
url: '/contacto/delete/' + rowId,
type: 'GET',
success: function(response) {
if (response==="La empresa ha sido eliminado") {
alert("Empresa borrada con exito");
window.location.reload();
}else{
alert("Error al borrar la empresa");
}
}
});
}
window.onclick = function(event) {
if (event.target === modal) {
modal.style.display = "none";
document.body.style.pointerEvents = 'auto';
}
}
}
});-->
</script>
</body>
</html>

@ -83,23 +83,23 @@
<nav aria-label="Page navigation" id="paginationControls">
<ul class="pagination">
<li class="page-item" th:classappend="${currentPage == 1 ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${1} + '?query=' + ${query}}">Prim</a>
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Prim</a>
</li>
<li class="page-item" th:classappend="${currentPage == 1 ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${currentPage - 1} + '?query=' + ${query}}">Ant</a>
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${currentPage - 1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Ant</a>
</li>
<li class="page-item" th:each="pageNum : ${#numbers.sequence(1, totalPages)}" th:classappend="${pageNum eq currentPage ? 'active' : ''}">
<th:block th:if="${pageNum lt 3 or pageNum gt totalPages - 2 or pageNum eq currentPage - 2 or pageNum eq currentPage - 1 or pageNum eq currentPage or pageNum eq currentPage + 1 or pageNum eq currentPage + 2}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${pageNum} + '?query=' + ${query}}">[[${pageNum}]]</a>
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${pageNum} + '?query=' + ${query} + '&size=' + ${currentSize}}">[[${pageNum}]]</a>
</th:block>
<th:block th:if="${pageNum eq 3 and currentPage gt 5}">...</th:block>
<th:block th:if="${pageNum eq totalPages - 2 and currentPage lt totalPages - 4}">...</th:block>
</li>
<li class="page-item" th:classappend="${currentPage == totalPages ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${currentPage + 1} + '?query=' + ${query}}">Sig</a>
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${currentPage + 1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Sig</a>
</li>
<li class="page-item" th:classappend="${currentPage == totalPages ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${totalPages} + '?query=' + ${query}}">Ult</a>
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${totalPages} + '?query=' + ${query} + '&size=' + ${currentSize}}">Ult</a>
</li>
</ul>
</nav>
@ -220,7 +220,7 @@
});
}
window.onclick = function(event) {
if (event.target == modal) {
if (event.target === modal) {
modal.style.display = "none";
document.body.style.pointerEvents = 'auto';
}

@ -6,7 +6,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<meta charset="UTF-8">
<title>Lista Empresas</title>
<title>Lista:Sectores</title>
<style>
</style>
@ -14,7 +14,7 @@
<body>
<div class="header">
<button onclick="goBack()">Atras</button>
<h1>Listado de Empresas</h1>
<h1>Listado de Sectores</h1>
<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a>
</div>
@ -37,18 +37,13 @@
</th>
</thead>
<tbody>
<tr class="cell" th:each="empresa :${empresas}">
<td>[[${empresa.id}]]</td>
<tr class="cell" th:each="sector :${sectores}">
<td>[[${sector.id}]]</td>
<td>
<a th:href="@{/templates/admin/empresa/{id}(id=${empresa.id})}">[[${empresa.nombre}]]</a>
<a th:href="@{/sector/{id}(id=${sector.id})}">[[${sector.nombre}]]</a>
<i id="edit-icon" class="fas fa-pen-square"></i>
<i id="delete-icon" class="fas fa-ban"></i>
</td>
<td>[[${empresa.cif}]]</td>
<td>[[${empresa.correo}]]</td>
<td>[[${empresa.telefono}]]</td>
<td>[[${empresa.keywords}]]</td>
<td>[[${empresa.sector.nombre}]]</td>
</tr>
</tbody>
</table>
@ -57,23 +52,23 @@
<nav aria-label="Page navigation" id="paginationControls">
<ul class="pagination">
<li class="page-item" th:classappend="${currentPage == 1 ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${1} + '?query=' + ${query}}">Prim</a>
<a class="page-link" th:href="@{'/buscador/sectores/page/' + ${1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Prim</a>
</li>
<li class="page-item" th:classappend="${currentPage == 1 ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${currentPage - 1} + '?query=' + ${query}}">Ant</a>
<a class="page-link" th:href="@{'/buscador/sectores/page/' + ${currentPage - 1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Ant</a>
</li>
<li class="page-item" th:each="pageNum : ${#numbers.sequence(1, totalPages)}" th:classappend="${pageNum eq currentPage ? 'active' : ''}">
<th:block th:if="${pageNum lt 3 or pageNum gt totalPages - 2 or pageNum eq currentPage - 2 or pageNum eq currentPage - 1 or pageNum eq currentPage or pageNum eq currentPage + 1 or pageNum eq currentPage + 2}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${pageNum} + '?query=' + ${query}}">[[${pageNum}]]</a>
<a class="page-link" th:href="@{'/buscador/sectores/page/' + ${pageNum} + '?query=' + ${query} + '&size=' + ${currentSize}}">[[${pageNum}]]</a>
</th:block>
<th:block th:if="${pageNum eq 3 and currentPage gt 5}">...</th:block>
<th:block th:if="${pageNum eq totalPages - 2 and currentPage lt totalPages - 4}">...</th:block>
</li>
<li class="page-item" th:classappend="${currentPage == totalPages ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${currentPage + 1} + '?query=' + ${query}}">Sig</a>
<a class="page-link" th:href="@{'/buscador/sectores/page/' + ${currentPage + 1} + '?query=' + ${query} + '&size=' + ${currentSize}}">Sig</a>
</li>
<li class="page-item" th:classappend="${currentPage == totalPages ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${totalPages} + '?query=' + ${query}}">Ult</a>
<a class="page-link" th:href="@{'/buscador/sectores/page/' + ${totalPages} + '?query=' + ${query} + '&size=' + ${currentSize}}">Ult</a>
</li>
</ul>
</nav>
@ -104,37 +99,30 @@
var entriesCountDropdown = document.querySelector('#entriesCount');
if (query == '') {
// If the search bar is empty, show the pagination controls and the entries count dropdown, and reload the page
paginationControls.style.display = '';
entriesCountDropdown.style.display = '';
table.style.pointerEvents = '';
location.reload();
} else {
// If the search bar is not empty, hide the pagination controls and the entries count dropdown, and perform the search
paginationControls.style.display = 'none';
entriesCountDropdown.style.display = 'none';
table.style.pointerEvents = 'none';
fetch('/buscador/empresas/search?query=' + query)
fetch('/buscador/sectores/search?query=' + query)
.then(response => response.json())
.then(data => {
var tableBody = document.querySelector('#table tbody');
tableBody.innerHTML = '';
data.forEach(empresa => {
data.forEach(sector => {
var row = document.createElement('tr');
row.innerHTML = `
<td>${empresa.id}</td>
<td>${sector.id}</td>
<td>
<a href="/templates/admin/empresa/${empresa.id}">${empresa.nombre}</a>
<a href="/templates/admin/sectores/${sector.id}">${sector.nombre}</a>
<i id="edit-icon" class="fas fa-pen-square"></i>
<i id="delete-icon" class="fas fa-ban"></i>
</td>
<td>${empresa.cif}</td>
<td>${empresa.correo}</td>
<td>${empresa.telefono}</td>
<td>${empresa.keywords}</td>
<td>${empresa.sector.nombre}</td>
`;
tableBody.appendChild(row);
});
@ -143,25 +131,15 @@
});
document.getElementById('create-icon').addEventListener('click', function() {
window.location = "/admin/empresa/create";
console.log("Create button clicked : TEST");
window.location = "/admin/sector/create";
});
<!-- EDIT AND UPDATE -->
document.querySelector('#table').addEventListener('click', function(event) {
//When you have a dynamic table to confirm an icon in a row you need to use event.target.matches('')
//And don forget to use # to specify that is an id
// or a . to specify that is a class
if (event.target.matches('#edit-icon')) {
// Handle edit button click
//This gets the ID of the row by getting the first element of the row by using the closest method
//And then getting the text content of the first element
//event. is the event that was triggered
//target. is the element that was clicked
// closest('tr') is the closest tr element to the clicked element
// firstElementChild is the first element of the tr element and .textContent is the text content of the element
if (event.target.matches('#edit-icon')) {
const rowId = event.target.closest('tr').firstElementChild.textContent;
<!--console.log('Edit button clicked for row with ID:', rowId);-->
window.location = "/admin/empresa/update/" + rowId;
window.location = "/admin/sector/update/" + rowId;
} else if (event.target.matches('#delete-icon')) {
const rowId = event.target.closest('tr').firstElementChild.textContent;
var modal = document.getElementById("modalDelete");
@ -181,29 +159,26 @@
// Your code here
<!--console.log("Delete button clicked for row with ID: ", rowId)-->
$.ajax({
url: '/empresa/delete/' + rowId,
url: '/sector/delete/' + rowId,
type: 'GET',
success: function(response) {
if (response==="La empresa ha sido eliminado") {
if (response==="El sector ha sido eliminado") {
alert("Empresa borrada con exito");
window.location.reload();
}else{
alert("Error al borrar la empresa");
alert("Error al borrar el sector");
}
}
});
}
window.onclick = function(event) {
if (event.target == modal) {
if (event.target === modal) {
modal.style.display = "none";
document.body.style.pointerEvents = 'auto';
}
}
}
});
</script>
</body>
</html>
Loading…
Cancel
Save

Powered by INFORMATICA.FP.EDU.ES.