Terminando las operaciones crud, falta a crear un query para borar todo los elemntos hijos de una empresa, y comenzando a recrear las otras tablas usando el modelo nuevo

master
vicsash 5 months ago
parent 47bfe9c8e0
commit 03e9be9fc0

@ -3,7 +3,7 @@ package com.example.proyectofinal.controllers;
import com.example.proyectofinal.models.empresas.*;
import com.example.proyectofinal.repositories.empresas.*;
import com.example.proyectofinal.servicios.EmpresaService;
import com.example.proyectofinal.servicios.implemetations.IEmpresa;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
@ -16,7 +16,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
@Controller
@ -44,7 +43,7 @@ public class BuscadorController {
private CicloRepository cicloRepository;
@Autowired
private EmpresaService empresaService;
private IEmpresa empresaService;
@GetMapping
public String buscador(){
@ -185,9 +184,7 @@ public class BuscadorController {
public Map<String, Object> getPagAtrEmpresas(int pageNum, String query, int size, String sortField, String sortDir, List<Empresa> empresas, List<Integer> itemsPage) {
Map<String, Object> attributes = new HashMap<>();
Page<Empresa> page = this.empresaService.finadAllpaginated(pageNum, size, "id", "asc");
attributes.put("currentPage", pageNum);
attributes.put("totalPages", page.getTotalPages());
attributes.put("totalItems", page.getTotalElements());

@ -4,24 +4,17 @@ import com.example.proyectofinal.models.empresas.Contacto;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.models.empresas.Sector;
import com.example.proyectofinal.repositories.empresas.ContactoRepository;
import com.example.proyectofinal.repositories.empresas.EmpressaRepository;
import com.example.proyectofinal.servicios.EmpresaService;
import com.example.proyectofinal.servicios.SectorService;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.example.proyectofinal.servicios.implemetations.IEmpresa;
import com.example.proyectofinal.servicios.implemetations.ISector;
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 org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
@Controller
@ -31,10 +24,10 @@ public class EmpressaController {
@Autowired
EmpresaService empresaService;
IEmpresa empresaService;
@Autowired
SectorService sectorService;
ISector sectorService;
@GetMapping("/empresas/{id}")
public String getEmpressaContacts(@PathVariable Long id, Model model) {
@ -56,26 +49,65 @@ public class EmpressaController {
@PostMapping("/empresa/save")
public String guardarCurso(Empresa empresa, @RequestParam("sector.id") Long sectorId, RedirectAttributes redirectAttributes){
public ResponseEntity<String> saveEmpresa(Empresa empresa, @RequestParam("sector.id") Long sectorId){
try{
Sector existingSector = sectorService.findById(sectorId);
if(existingSector != null) {
empresa.setSector(existingSector);
} else {
redirectAttributes.addFlashAttribute("message", "Sector no encontrado");
return "redirect:/admin/empresa/create";
return new ResponseEntity<>("Sector no encontrado", HttpStatus.BAD_REQUEST);
}
if(empresaService.exists(empresa) != null){
redirectAttributes.addFlashAttribute("message", "Este empresa ya existe en la base de datos");
return "redirect:/admin/empresa/create";
System.out.println("Empresa ya existe");
return new ResponseEntity<>("Este empresa ya existe en la base de datos", HttpStatus.BAD_REQUEST);
}else {
empresaService.save(empresa);
redirectAttributes.addFlashAttribute("message", "La empresa fue guardado con exito");
return "redirect:/admin/empresa/create";
return new ResponseEntity<>("La empresa fue guardado con exito", HttpStatus.OK);
}
}catch (Exception e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/admin/empresa/update/{id}")
public String showUpdateForm(Model model, @PathVariable Long id) {
Empresa empresa = empresaService.findById(id);
//System.out.println("Retrieved empresa: " + empresa); // Add logging here
Sector sector = new Sector();
List<Sector> sectores = sectorService.findAll();
//System.out.println("Retrieved sectores: " + sectores); // Add logging here
model.addAttribute("empresa", empresa);
model.addAttribute("sector", sector);
model.addAttribute("sectores", sectores);
return "admin/empresa/update";
}
@PostMapping("/empresa/update")
public ResponseEntity<String> updateEmpresa(Empresa empresa, @RequestParam("sector.id") Long sectorId){
try{
Sector existingSector = sectorService.findById(sectorId);
if(existingSector != null) {
empresa.setSector(existingSector);
} else {
return new ResponseEntity<>("Sector no encontrado", HttpStatus.BAD_REQUEST);
}
empresaService.save(empresa);
return new ResponseEntity<>("Los datos de la empresa fue renovados con exito", HttpStatus.OK);
}catch (Exception e) {
redirectAttributes.addFlashAttribute("message", e.getMessage());
return "redirect:/admin/empresa/create";
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@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);
}catch (Exception e){
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

@ -2,7 +2,7 @@ package com.example.proyectofinal.controllers.modelControllers;
import com.example.proyectofinal.models.empresas.Ciclo;
import com.example.proyectofinal.repositories.empresas.CicloRepository;
import com.example.proyectofinal.servicios.implemetations.FamiliaServImp;
import com.example.proyectofinal.servicios.FamiliaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@ -18,7 +18,7 @@ public class FamiliaController {
private CicloRepository cicloRepository;
@Autowired
private FamiliaServImp familiaService;
private FamiliaService familiaService;
@PostMapping("/crearFamilia")
@ResponseBody

@ -0,0 +1,169 @@
INSERT INTO familias (nombre) VALUES ('Informatica');
INSERT INTO familias (nombre) VALUES ('Sanidad');
INSERT INTO familias (nombre) VALUES ('Economia');
INSERT INTO familias (nombre) VALUES ('Deporte');
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 Skill table
INSERT INTO skills (nombre) VALUES ('Java');
INSERT INTO skills (nombre) VALUES ('Microsoft XL');
INSERT INTO skills (nombre) VALUES ('Bilingue');
INSERT INTO skills (nombre) VALUES ('Trilingue');
INSERT INTO skills (nombre) VALUES ('Multilingue');
INSERT INTO skills (nombre) VALUES ('Python');
INSERT INTO skills (nombre) VALUES ('C++');
INSERT INTO skills (nombre) VALUES ('C#');
INSERT INTO skills (nombre) VALUES ('HTML');
INSERT INTO skills (nombre) VALUES ('CSS');
INSERT INTO skills (nombre) VALUES ('JavaScript');
INSERT INTO skills (nombre) VALUES ('PHP');
INSERT INTO skills (nombre) VALUES ('SQL');
INSERT INTO skills (nombre) VALUES ('Marketing');
INSERT INTO skills (nombre) VALUES ('Traductor');
-- Insert into Sector table
INSERT INTO sectores (nombre) VALUES ('Electricidad');
INSERT INTO sectores (nombre) VALUES ('Informatica');
INSERT INTO sectores (nombre) VALUES ('Deporte');
INSERT INTO sectores (nombre) VALUES ('Musica');
INSERT INTO sectores (nombre) VALUES ('Electronica');
INSERT INTO sectores (nombre) VALUES ('Turismo');
INSERT INTO sectores (nombre) VALUES ('Sanidad');
INSERT INTO sectores (nombre) VALUES ('Educacion');
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 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 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 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 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 Alumno_Skill (fk_alumno, fk_skills) VALUES (1, 1); -- Jorge with Java
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (3, 2); -- Robert with Microsoft XL
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (4, 14); -- Emily with Marketing
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (5, 13); -- James with SQL
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (6, 6); -- Michael with Python
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (7, 12); -- Emma with JavaScript
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (8, 5); -- Tom with CSS
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (9, 3); -- Jennifer with Bilingue
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (10, 4); -- Chris with Trilingue
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (11, 2); -- Brad with Microsoft XL
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (12, 1); -- Angelina with Java
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (13, 7); -- Leonardo with C++
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (14, 11); -- Scarlett with PHP
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (15, 10); -- Hugh with JavaScript
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (1, 1);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (2, 2);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (3, 5);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (4, 3);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (5, 6);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (6, 7);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (7, 4);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (8, 10);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (9, 12);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (10, 11);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (11, 13);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (12, 14);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (13, 8);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (14, 9);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (15, 15);

@ -2,6 +2,8 @@ package com.example.proyectofinal.models.empresas;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@ -74,6 +76,7 @@ public class Alumno {
@ManyToOne(cascade = {CascadeType.ALL},fetch = FetchType.EAGER)
@JoinColumn(name = "Ciclo_id",referencedColumnName = "id")
@OnDelete(action = OnDeleteAction.CASCADE)
private Ciclo ciclo;
public Alumno(@NonNull String nombre, @NonNull String apellido, String apellido2, @NonNull Date fechaNacimiento, @NonNull String genero, @NonNull String nia, @NonNull String dni, @NonNull String correo, String correo2, @NonNull String nacionalidad, @NonNull String keyword, Set<Skill> skills, Ciclo ciclo) {

@ -6,6 +6,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
@Entity
@AllArgsConstructor
@ -28,6 +30,7 @@ public class Ciclo {
@ManyToOne(cascade = {CascadeType.ALL},fetch = FetchType.EAGER)
@JoinColumn(name = "Familia_id",referencedColumnName = "id")
@OnDelete(action = OnDeleteAction.CASCADE)
private Familia familia;
public Ciclo(@NonNull String nombre, @NonNull String codigo, Familia familia) {

@ -6,6 +6,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
@Entity
@AllArgsConstructor
@ -37,6 +39,7 @@ public class Contacto {
@ManyToOne(cascade = {CascadeType.ALL},fetch = FetchType.LAZY)
@JoinColumn(name = "Empresa_id",referencedColumnName = "id")
@OnDelete(action = OnDeleteAction.CASCADE)
private Empresa empresa;
public Contacto(@NonNull String nombre, @NonNull String apellido1, String apellido2, String correo, String telefono, Empresa empresa) {

@ -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;
@Entity
@AllArgsConstructor
@ -39,6 +41,7 @@ public class Empresa {
@ManyToOne(cascade = {CascadeType.ALL},fetch = FetchType.EAGER)
@JoinColumn(name = "Sector_id",referencedColumnName = "id")
@OnDelete(action = OnDeleteAction.CASCADE)
private Sector sector;
public Empresa(@NonNull String nombre, @NonNull String cif, @NonNull String correo, @NonNull String telefono1, @NonNull String keywords, Sector sector) {

@ -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 org.springframework.format.annotation.DateTimeFormat;
import java.util.Set;
@ -34,6 +36,7 @@ public class Oferta {
@ManyToOne(cascade = {CascadeType.ALL},fetch = FetchType.EAGER)
@JoinColumn(name = "Sucursal_id")
@OnDelete(action = OnDeleteAction.CASCADE)
private Sucursal sucursal;
@ManyToMany(cascade = {CascadeType.ALL},fetch = FetchType.EAGER)

@ -6,6 +6,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
@Entity
@AllArgsConstructor
@ -35,6 +37,7 @@ public class Sucursal {
@ManyToOne(cascade = {CascadeType.ALL},fetch = FetchType.LAZY)
@JoinColumn(name = "Empresa_id")
@OnDelete(action = OnDeleteAction.CASCADE)
private Empresa empresa;
public Sucursal(@NonNull String nombre, @NonNull String localidad, @NonNull String direccion, @NonNull boolean sedeCentral, Empresa empresa) {

@ -27,8 +27,8 @@ public interface EmpressaRepository extends JpaRepository<Empresa, Long>, JpaSpe
@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%")
List<Empresa> search(@Param("query") String query);
@Query("SELECT e FROM Empresa e WHERE e.nombre = :nombre")
Empresa existsName(@Param("nombre") String empresaName);
@Query("SELECT e FROM Empresa e WHERE e.cif = :cif")
Empresa existsCif(@Param("cif") String empresaName);

@ -8,7 +8,10 @@ import java.util.ArrayList;
public interface SucursalRepository extends JpaRepository<Sucursal, Long> {
//there is value = and nativeQuery = true so the query is written in SQL refering to the table in the database
@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);
// //there is value = and nativeQuery = true so the query is written in SQL refering to the table in the database
// @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);
}

@ -0,0 +1,52 @@
package com.example.proyectofinal.servicios;
import com.example.proyectofinal.models.empresas.Contacto;
import com.example.proyectofinal.servicios.implemetations.IContactos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import com.example.proyectofinal.repositories.empresas.ContactoRepository;
import java.util.List;
@Service
public class ContactosService implements IContactos {
@Autowired
private ContactoRepository contactoRepository;
@Override
public List<Contacto> findAll() {
return List.of();
}
@Override
public Page<Contacto> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir) {
return null;
}
@Override
public Contacto findById(Long id) {
return contactoRepository.findById(id).orElse(null);
}
@Override
public Contacto findByName(String name) {
return null;
}
@Override
public Contacto save(Contacto contacto) {
return contactoRepository.save(contacto);
}
@Override
public void deleteById(Long id) {
contactoRepository.deleteById(id);
}
@Override
public List<Contacto> search(String query) {
return List.of();
}
}

@ -1,24 +1,72 @@
package com.example.proyectofinal.servicios;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.repositories.empresas.EmpressaRepository;
import com.example.proyectofinal.servicios.implemetations.IEmpresa;
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;
public interface EmpresaService {
@Service
public class EmpresaService implements IEmpresa {
List<Empresa> findAll();
@Autowired
private EmpressaRepository empressaRepository;
@Autowired
private ContactosService contactosService;
@Autowired
private SucursalService sucursalService;
@Autowired
private OfertaService ofertaService;
Page<Empresa> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir);
Empresa findById(Long id);
@Override
public List<Empresa> findAll() {
return empressaRepository.findAll();
}
Empresa save(Empresa empresa);
@Override
public Page<Empresa> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir) {
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.empressaRepository.findAll(pageable);
}
void deleteById(Long id);
@Override
public Empresa findById(Long id) {
return empressaRepository.findById(id).orElse(null);
}
List<Empresa> search(String query);
@Override
public Empresa save(Empresa empresa) {
return empressaRepository.save(empresa);
}
@Override
public void deleteById(Long id) {
Empresa empresa = empressaRepository.findById(id).orElse(null);
if(empresa != null){
}
}
@Override
public List<Empresa> search(String query ) {
return empressaRepository.search(query);
}
@Override
public Empresa exists(Empresa empresa) {
String cif = empresa.getCif();
return empressaRepository.existsCif(cif);
}
Empresa exists(Empresa empresa);
}

@ -1,4 +1,4 @@
package com.example.proyectofinal.servicios.implemetations;
package com.example.proyectofinal.servicios;
import com.example.proyectofinal.models.empresas.Familia;
import com.example.proyectofinal.repositories.empresas.FamiliaRepository;
@ -6,7 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class FamiliaServImp {
public class FamiliaService {
@Autowired
private FamiliaRepository familiaRepository;

@ -0,0 +1,51 @@
package com.example.proyectofinal.servicios;
import com.example.proyectofinal.models.empresas.Oferta;
import com.example.proyectofinal.repositories.empresas.OfertaRepository;
import com.example.proyectofinal.servicios.implemetations.IOferta;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class OfertaService implements IOferta {
@Autowired
private OfertaRepository ofertaRepository;
@Override
public List<Oferta> findAll() {
return ofertaRepository.findAll();
}
@Override
public Page<Oferta> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir) {
return null;
}
@Override
public Oferta findById(Long id) {
return ofertaRepository.findById(id).orElse(null);
}
@Override
public Oferta findByName(String name) {
return null;
}
@Override
public Oferta save(Oferta oferta) {
return ofertaRepository.save(oferta);
}
@Override
public void deleteById(Long id) {
ofertaRepository.deleteById(id);
}
@Override
public List<Oferta> search(String query) {
return List.of();
}
}

@ -1,23 +1,51 @@
package com.example.proyectofinal.servicios;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.models.empresas.Sector;
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.stereotype.Service;
import java.util.List;
public interface SectorService {
List<Sector> findAll();
Page<Sector> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir);
Sector findById(Long id);
Sector findByName(String name);
Sector save(Sector sector);
void deleteById(Long id);
List<Sector> search(String query);
@Service
public class SectorService implements ISector {
@Autowired
private SectorRepository sectorRepository;
@Override
public List<Sector> findAll() {
return sectorRepository.findAll();
}
@Override
public Page<Sector> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir) {
return null;
}
@Override
public Sector findById(Long id) {
return sectorRepository.findById(id).orElse(null);
}
@Override
public Sector findByName(String name) {
return sectorRepository.findByNombre(name);
}
@Override
public Sector save(Sector sector) {
return sectorRepository.save(sector);
}
@Override
public void deleteById(Long id) {
sectorRepository.deleteById(id);
}
@Override
public List<Sector> search(String query) {
return List.of();
}
}

@ -0,0 +1,51 @@
package com.example.proyectofinal.servicios;
import com.example.proyectofinal.models.empresas.Skill;
import com.example.proyectofinal.repositories.empresas.SkillRepository;
import com.example.proyectofinal.servicios.implemetations.ISkill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class SkillService implements ISkill {
@Autowired
private SkillRepository skillRepository;
@Override
public List<Skill> findAll() {
return skillRepository.findAll();
}
@Override
public Page<Skill> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir) {
return null;
}
@Override
public Skill findById(Long id) {
return skillRepository.findById(id).orElse(null);
}
@Override
public Skill findByName(String name) {
return null;
}
@Override
public Skill save(Skill skill) {
return skillRepository.save(skill);
}
@Override
public void deleteById(Long id) {
skillRepository.deleteById(id);
}
@Override
public List<Skill> search(String query) {
return List.of();
}
}

@ -0,0 +1,51 @@
package com.example.proyectofinal.servicios;
import com.example.proyectofinal.models.empresas.Sucursal;
import com.example.proyectofinal.repositories.empresas.SucursalRepository;
import com.example.proyectofinal.servicios.implemetations.ISucursal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class SucursalService implements ISucursal {
@Autowired
private SucursalRepository sucursalRepository;
@Override
public List<Sucursal> findAll() {
return List.of();
}
@Override
public Page<Sucursal> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir) {
return null;
}
@Override
public Sucursal findById(Long id) {
return sucursalRepository.findById(id).orElse(null);
}
@Override
public Sucursal findByName(String name) {
return null;
}
@Override
public Sucursal save(Sucursal sucursal) {
return sucursalRepository.save(sucursal);
}
@Override
public void deleteById(Long id) {
sucursalRepository.deleteById(id);
}
@Override
public List<Sucursal> search(String query) {
return List.of();
}
}

@ -1,62 +0,0 @@
package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.repositories.empresas.EmpressaRepository;
import com.example.proyectofinal.servicios.EmpresaService;
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;
@Service
public class EmpresaServImp implements EmpresaService {
@Autowired
private EmpressaRepository empressaRepository;
@Override
public List<Empresa> findAll() {
return empressaRepository.findAll();
}
@Override
public Page<Empresa> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir) {
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.empressaRepository.findAll(pageable);
}
@Override
public Empresa findById(Long id) {
return empressaRepository.findById(id).orElse(null);
}
@Override
public Empresa save(Empresa empresa) {
return empressaRepository.save(empresa);
}
@Override
public void deleteById(Long id) {
}
@Override
public List<Empresa> search(String query ) {
return empressaRepository.search(query);
}
@Override
public Empresa exists(Empresa empresa) {
String nombre = empresa.getNombre();
return empressaRepository.existsName(nombre);
}
}

@ -0,0 +1,23 @@
package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.models.empresas.Contacto;
import com.example.proyectofinal.models.empresas.Sucursal;
import org.springframework.data.domain.Page;
import java.util.List;
public interface IContactos {
List<Contacto> findAll();
Page<Contacto> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir);
Contacto findById(Long id);
Contacto findByName(String name);
Contacto save(Contacto contacto);
void deleteById(Long id);
List<Contacto> search(String query);
}

@ -0,0 +1,24 @@
package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.models.empresas.Empresa;
import org.springframework.data.domain.Page;
import java.util.List;
public interface IEmpresa {
List<Empresa> findAll();
Page<Empresa> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir);
Empresa findById(Long id);
Empresa save(Empresa empresa);
void deleteById(Long id);
List<Empresa> search(String query);
Empresa exists(Empresa empresa);
}

@ -0,0 +1,22 @@
package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.models.empresas.Oferta;
import org.springframework.data.domain.Page;
import java.util.List;
public interface IOferta {
List<Oferta> findAll();
Page<Oferta> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir);
Oferta findById(Long id);
Oferta findByName(String name);
Oferta save(Oferta oferta);
void deleteById(Long id);
List<Oferta> search(String query);
}

@ -0,0 +1,22 @@
package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.models.empresas.Sector;
import org.springframework.data.domain.Page;
import java.util.List;
public interface ISector {
List<Sector> findAll();
Page<Sector> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir);
Sector findById(Long id);
Sector findByName(String name);
Sector save(Sector sector);
void deleteById(Long id);
List<Sector> search(String query);
}

@ -0,0 +1,22 @@
package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.models.empresas.Skill;
import org.springframework.data.domain.Page;
import java.util.List;
public interface ISkill {
List<Skill> findAll();
Page<Skill> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir);
Skill findById(Long id);
Skill findByName(String name);
Skill save(Skill skill);
void deleteById(Long id);
List<Skill> search(String query);
}

@ -0,0 +1,22 @@
package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.models.empresas.Sucursal;
import org.springframework.data.domain.Page;
import java.util.List;
public interface ISucursal {
List<Sucursal> findAll();
Page<Sucursal> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir);
Sucursal findById(Long id);
Sucursal findByName(String name);
Sucursal save(Sucursal sucursal);
void deleteById(Long id);
List<Sucursal> search(String query);
}

@ -1,52 +0,0 @@
package com.example.proyectofinal.servicios.implemetations;
import com.example.proyectofinal.models.empresas.Empresa;
import com.example.proyectofinal.models.empresas.Sector;
import com.example.proyectofinal.repositories.empresas.SectorRepository;
import com.example.proyectofinal.servicios.SectorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class SectorSerImp implements SectorService {
@Autowired
private SectorRepository sectorRepository;
@Override
public List<Sector> findAll() {
return sectorRepository.findAll();
}
@Override
public Page<Sector> finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir) {
return null;
}
@Override
public Sector findById(Long id) {
return sectorRepository.findById(id).orElse(null);
}
@Override
public Sector findByName(String name) {
return sectorRepository.findByNombre(name);
}
@Override
public Sector save(Sector sector) {
return sectorRepository.save(sector);
}
@Override
public void deleteById(Long id) {
sectorRepository.deleteById(id);
}
@Override
public List<Sector> search(String query) {
return List.of();
}
}

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<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}">
<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>
<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 Ofertas<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>
</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>
</tbody>
</table>
</div>
<button onclick="goBack()">Atras</button>
<script>
function goBack() {
window.history.back();
}
</script>
</body>
</html>

@ -40,14 +40,10 @@ h1 {
position: relative;
}
.table {
table-layout: fixed;
width: 100%;
}
.table td, .table th {
width: 150px;
height: 50px;
overflow: hidden;
text-overflow: ellipsis;
overflow: visible;
white-space: nowrap;
}
.table thead th {
@ -76,6 +72,28 @@ h1 {
.table {
}
}
@media screen and (max-width: 600px) {
.table td, .table th {
font-size: 14px;
padding: 5px;
}
#edit-icon, #delete-icon {
min-width: 16px;
}
}
@media screen and (max-width: 400px) {
.table td, .table th {
font-size: 12px;
padding: 3px;
}
#edit-icon, #delete-icon {
min-width: 12px;
}
}
.table tr {
height: 10%;
}
@ -116,6 +134,10 @@ html, body {
.page a{
padding:10px;
}
#edit-icon, #delete-icon {
min-width: 24px;
}
#edit-icon {
color: #ffa600;
margin-right: 10px;
@ -139,4 +161,59 @@ html, body {
.no-link-style {
color: inherit;
text-decoration: none;
}
}
.modal{
display: none;
position: fixed;
z-index: 1001;
left: 0;
top: 0;
width: 100vw;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
.modal-content{
background-color: #fefefe;
margin: 20% auto;
padding: 20px;
border: 2px solid #888;
width: 25%;
}
.delete{
background-color: #f8f9fa; /* Light gray background */
color: red;
float: right;
font-size: 28px;
font-weight: bold;
padding: 10px;
}
.close{
background-color: #f8f9fa; /* Light gray background */
color: black;
float: right;
font-size: 28px;
padding: 10px;
font-weight: bold;
}
.close:hover{
color: black;
text-decoration: none;
cursor: pointer;
}
.delete:hover{
color: #ed4040;
text-decoration: none;
cursor: pointer;
}
.modal p{
font-size: 20px;
}

@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Creacion: Familia</title>
<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>
@ -64,28 +64,28 @@
<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}" required minlength="2" maxlength="128" class="form-control" id="cif">
<input type="text" th:field="*{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}" required min="2" class="form-control" id="correo">
<input type="text" th:field="*{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}" required min="2" class="form-control" id="telefono">
<input type="text" th:field="*{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}" required min="2" class="form-control" id="keywords">
<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>
@ -117,33 +117,26 @@
var formData = $(this).serialize();
var sectorId = $('#sector').val();
formData += '&sector=' + encodeURIComponent(sectorId);
$(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 (response) {
if(response === "La empresa fue guardado con exito") {
window.history.go(-2); // Go back two pages
} else {
alert("Hubo un error al guardar la empresa");
window.history.go(-2);
}
},
error: function () {
alert("Hubo un error al guardar la empresa");
window.history.back();
}
});
});
$.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(-2); // 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();
}
});
});
});

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</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(-2); // 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>

@ -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>Title</title>
<title>Lista Empresas</title>
<style>
</style>
@ -109,6 +109,15 @@
<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>
@ -163,6 +172,63 @@
window.location = "/admin/empresa/create";
});
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
const rowId = event.target.closest('tr').firstElementChild.textContent;
<!--console.log('Edit button clicked for row with ID:', rowId);-->
window.location = "/admin/empresa/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() {
// Your code here
<!--console.log("Delete button clicked for row with ID: ", rowId)-->
$.ajax({
url: '/empresa/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>

@ -3,39 +3,207 @@
<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 Empresas</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 Ofertas<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">
<div class="header">
<button onclick="goBack()">Atras</button>
<h1>Listado de Empresas</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>Id</th>
<th>Nombre</th>
</tr>
<th class="table-header">
<a th:href="@{'/buscador/sectores/page/' + ${currentPage} + '?sortField=id&sortDir=' + ${reverseSortDir}}">
Id
</a>
</th>
<th class="table-header">
<a th:href="@{'/buscador/sectores/page/' + ${currentPage} + '?sortField=nombre&sortDir=' + ${reverseSortDir}}">
Nombre
</a>
</th>
</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="empresa :${empresas}">
<td>[[${empresa.id}]]</td>
<td>
<a th:href="@{/templates/admin/empresa/{id}(id=${empresa.id})}">[[${empresa.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>
</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}}">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>
</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>
</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>
</li>
<li class="page-item" th:classappend="${currentPage == totalPages ? 'disabled' : ''}">
<a class="page-link" th:href="@{'/buscador/empresas/page/' + ${totalPages} + '?query=' + ${query}}">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/empresas/search?query=' + query)
.then(response => response.json())
.then(data => {
var tableBody = document.querySelector('#table tbody');
tableBody.innerHTML = '';
data.forEach(empresa => {
var row = document.createElement('tr');
row.innerHTML = `
<td>${empresa.id}</td>
<td>
<a href="/templates/admin/empresa/${empresa.id}">${empresa.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);
});
});
}
});
document.getElementById('create-icon').addEventListener('click', function() {
window.location = "/admin/empresa/create";
});
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
const rowId = event.target.closest('tr').firstElementChild.textContent;
<!--console.log('Edit button clicked for row with ID:', rowId);-->
window.location = "/admin/empresa/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() {
// Your code here
<!--console.log("Delete button clicked for row with ID: ", rowId)-->
$.ajax({
url: '/empresa/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>
Loading…
Cancel
Save

Powered by INFORMATICA.FP.EDU.ES.