├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── src ├── main │ ├── java │ │ └── com │ │ │ └── tallerMecanico │ │ │ ├── dto │ │ │ ├── DetalleFacturaDto.java │ │ │ ├── RolDto.java │ │ │ ├── MarcaDto.java │ │ │ ├── FacturaDto.java │ │ │ ├── TipoMotorDto.java │ │ │ ├── ModeloDto.java │ │ │ ├── EstatusServicioDto.java │ │ │ ├── UsuarioDto.java │ │ │ ├── DetalleOrdenServicioDto.java │ │ │ ├── ActualizacionDto.java │ │ │ ├── RegistroResponseDto.java │ │ │ ├── RegistroUsuarioEmpleadoDto.java │ │ │ ├── RegistroUsuarioClienteDto.java │ │ │ ├── EmpleadoDto.java │ │ │ ├── ClienteDto.java │ │ │ ├── VehiculoDto.java │ │ │ └── OrdenServicioDto.java │ │ │ ├── repository │ │ │ ├── IMarcaRepository.java │ │ │ ├── IFacturaRepository.java │ │ │ ├── IEmpleadoRepository.java │ │ │ ├── ITipoMotorRepository.java │ │ │ ├── IOrdenServicioRepository.java │ │ │ ├── IDetalleFacturaRepository.java │ │ │ ├── IEstatusServicioRepository.java │ │ │ ├── IDetalleOrdenServicioRepository.java │ │ │ ├── IModeloRepository.java │ │ │ ├── IVehiculoRepository.java │ │ │ ├── IRolRepository.java │ │ │ ├── IUsuarioRepository.java │ │ │ └── IClienteRepository.java │ │ │ ├── service │ │ │ ├── IRolService.java │ │ │ ├── IMarcaService.java │ │ │ ├── IModeloService.java │ │ │ ├── IVehiculoService.java │ │ │ ├── IEmpleadoService.java │ │ │ ├── ITipoMotorService.java │ │ │ ├── IOrdenServicioService.java │ │ │ ├── IClienteService.java │ │ │ ├── IEstatusServicioService.java │ │ │ ├── IUsuarioService.java │ │ │ ├── IDetalleOrdenServicioService.java │ │ │ ├── RolService.java │ │ │ ├── MarcaService.java │ │ │ ├── ModeloService.java │ │ │ ├── TipoMotorService.java │ │ │ ├── EstatusServicioService.java │ │ │ ├── DetalleOrdenServicioService.java │ │ │ ├── VehiculoService.java │ │ │ ├── OrdenServicioService.java │ │ │ ├── UsuarioService.java │ │ │ ├── ClienteService.java │ │ │ └── EmpleadoService.java │ │ │ ├── entity │ │ │ ├── Marca.java │ │ │ ├── Rol.java │ │ │ ├── TipoMotor.java │ │ │ ├── EstatusServicio.java │ │ │ ├── Modelo.java │ │ │ ├── DetalleFactura.java │ │ │ ├── DetalleOrdenServicio.java │ │ │ ├── Factura.java │ │ │ ├── Usuario.java │ │ │ ├── Empleado.java │ │ │ ├── Cliente.java │ │ │ ├── Vehiculo.java │ │ │ └── OrdenServicio.java │ │ │ ├── TallerMecanicoApplication.java │ │ │ └── controller │ │ │ ├── RolController.java │ │ │ ├── ModeloController.java │ │ │ ├── VehiculoController.java │ │ │ ├── TipoMotorController.java │ │ │ ├── MarcaController.java │ │ │ ├── OrdenServicioController.java │ │ │ ├── UsuarioController.java │ │ │ ├── EstatusServicioController.java │ │ │ ├── EmpleadoController.java │ │ │ ├── DetalleOrdenServicioController.java │ │ │ └── ClienteController.java │ └── resources │ │ ├── application.properties │ │ ├── marcaAutos.csv │ │ ├── data2.sql │ │ ├── data3.sql │ │ ├── data.sql │ │ └── modelosAutos.csv └── test │ └── java │ └── com │ └── tallerMecanico │ └── TallerMecanicoApplicationTests.java ├── .gitignore ├── pom.xml ├── mvnw.cmd └── mvnw /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RodolfoBaume/TallerMecanicoBackend/master/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar 3 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/DetalleFacturaDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | import com.tallerMecanico.entity.Factura; 4 | 5 | 6 | public record DetalleFacturaDto(long idDetalleFactura, String descripcionServicio, double costo, Factura factura) { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/RolDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | import com.tallerMecanico.entity.Rol; 4 | 5 | public record RolDto(Long idRol, String nombre) { 6 | public RolDto(Rol rol) { 7 | this(rol.getIdRol(), rol.getNombre()); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/MarcaDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | import com.tallerMecanico.entity.Marca; 4 | 5 | public record MarcaDto(long idMarca, String marca) { 6 | 7 | public MarcaDto(Marca marca) { 8 | this(marca.getIdMarca(), marca.getMarca()); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/FacturaDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | import java.util.Date; 4 | 5 | import com.tallerMecanico.entity.OrdenServicio; 6 | 7 | 8 | public record FacturaDto(long idFactura, Date fechaFactura, double monto, OrdenServicio ordenServicio) { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/com/tallerMecanico/TallerMecanicoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class TallerMecanicoApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/TipoMotorDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | import com.tallerMecanico.entity.TipoMotor; 4 | 5 | public record TipoMotorDto(long idTipoMotor, String tipoMotor) { 6 | 7 | public TipoMotorDto(TipoMotor tipoMotor) { 8 | this(tipoMotor.getIdTipoMotor(), tipoMotor.getTipoMotor()); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/repository/IMarcaRepository.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import com.tallerMecanico.entity.Marca; 7 | 8 | @Repository 9 | public interface IMarcaRepository extends JpaRepository{ 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/ModeloDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | import com.tallerMecanico.entity.Marca; 4 | import com.tallerMecanico.entity.Modelo; 5 | 6 | 7 | public record ModeloDto(long idModelo, String modelo, Marca marca) { 8 | 9 | public ModeloDto(Modelo modelo) { 10 | this(modelo.getIdModelo(), modelo.getModelo(),modelo.getMarca()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/repository/IFacturaRepository.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import com.tallerMecanico.entity.Factura; 7 | 8 | @Repository 9 | public interface IFacturaRepository extends JpaRepository{ 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/repository/IEmpleadoRepository.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import com.tallerMecanico.entity.Empleado; 7 | 8 | @Repository 9 | public interface IEmpleadoRepository extends JpaRepository{ 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/repository/ITipoMotorRepository.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import com.tallerMecanico.entity.TipoMotor; 7 | 8 | @Repository 9 | public interface ITipoMotorRepository extends JpaRepository{ 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/repository/IOrdenServicioRepository.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import com.tallerMecanico.entity.OrdenServicio; 7 | 8 | @Repository 9 | public interface IOrdenServicioRepository extends JpaRepository{ 10 | 11 | } -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/EstatusServicioDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | import com.tallerMecanico.entity.EstatusServicio; 4 | 5 | public record EstatusServicioDto(long idEstatusServicio, String estatusServicio) { 6 | 7 | public EstatusServicioDto(EstatusServicio estatusServicio) { 8 | this(estatusServicio.getIdEstatusServicio(), estatusServicio.getEstatusServicio()); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/repository/IDetalleFacturaRepository.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import com.tallerMecanico.entity.DetalleFactura; 7 | 8 | @Repository 9 | public interface IDetalleFacturaRepository extends JpaRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/repository/IEstatusServicioRepository.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import com.tallerMecanico.entity.EstatusServicio; 7 | 8 | @Repository 9 | public interface IEstatusServicioRepository extends JpaRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/repository/IDetalleOrdenServicioRepository.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import com.tallerMecanico.entity.DetalleOrdenServicio; 7 | 8 | @Repository 9 | public interface IDetalleOrdenServicioRepository extends JpaRepository{ 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:postgresql://localhost:5432/tallerMecanico 2 | spring.datasource.username=postgres 3 | spring.datasource.password=12345 4 | spring.datasource.hikari.connection-timeout=20000 5 | spring.datasource.hikari.maximum-pool-size=5 6 | spring.jpa.show-sql=true 7 | spring.jpa.hibernate.ddl-auto=update 8 | spring.datasource.driver-class-name=org.postgresql.Driver 9 | logging.level.org.hibernate.SQL=debug 10 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/repository/IModeloRepository.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import com.tallerMecanico.entity.Modelo; 9 | 10 | @Repository 11 | public interface IModeloRepository extends JpaRepository{ 12 | List findByMarca_IdMarca(Long marcaId); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/repository/IVehiculoRepository.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import com.tallerMecanico.entity.Vehiculo; 9 | 10 | @Repository 11 | public interface IVehiculoRepository extends JpaRepository { 12 | 13 | List findByCliente_IdCliente(Long clienteId); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/repository/IRolRepository.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.repository; 2 | 3 | import java.util.Optional; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import com.tallerMecanico.entity.Rol; 9 | 10 | @Repository 11 | public interface IRolRepository extends JpaRepository { 12 | 13 | // Método para buscar un role por su nombre en nuestra base de datos 14 | Optional findByNombre(String nombre); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/UsuarioDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | import java.util.List; 4 | 5 | import com.tallerMecanico.entity.Cliente; 6 | import com.tallerMecanico.entity.Rol; 7 | import com.tallerMecanico.entity.Usuario; 8 | 9 | 10 | public record UsuarioDto(long idUsuario, String email, String password, Listrol, Cliente cliente) { 11 | public UsuarioDto(Usuario usuario) { 12 | this(usuario.getIdUsuario(), usuario.getEmail(), usuario.getPassword(), usuario.getRol(), usuario.getCliente()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/DetalleOrdenServicioDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | import com.tallerMecanico.entity.DetalleOrdenServicio; 4 | import com.tallerMecanico.entity.OrdenServicio; 5 | 6 | 7 | public record DetalleOrdenServicioDto(long idDetalleOrdenServicios, String descripcionServicio, OrdenServicio ordenServicio) { 8 | 9 | public DetalleOrdenServicioDto(DetalleOrdenServicio detalleOrdenServicio) { 10 | this(detalleOrdenServicio.getIdDetalleOrdenServicio(), detalleOrdenServicio.getDescripcionServicio(), detalleOrdenServicio.getOrdenServicio()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/marcaAutos.csv: -------------------------------------------------------------------------------- 1 | id_marca,marca 2 | 1,Acura 3 | 2,Alfa Romeo 4 | 3,Audi 5 | 4,Bentley 6 | 5,BMW 7 | 6,Chirey 8 | 7,Chrysler 9 | 8,Fiat 10 | 9,Ford Motor 11 | 10,General Motors 12 | 11,Honda 13 | 12,Hyundai 14 | 13,Infiniti 15 | 14,Isuzu 16 | 15,JAC 17 | 16,Jaguar 18 | 17,KIA 19 | 18,Land Rover 20 | 19,Lexus 21 | 20,Lincoln 22 | 21,Mazda 23 | 22,Mercedes Benz 24 | 23,MG Motor 25 | 24,Mini 26 | 25,Mitsubishi 27 | 26,MOTORNATION 28 | 27,Nissan 29 | 28,Omoda 30 | 29,Peugeot 31 | 30,Porsche 32 | 31,Renault 33 | 32,SEAT 34 | 33,Subaru 35 | 34,Suzuki 36 | 35,Toyota 37 | 36,Volkswagen 38 | 37,Volvo 39 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/IRolService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | 8 | import com.tallerMecanico.dto.RolDto; 9 | import com.tallerMecanico.entity.Rol; 10 | 11 | public interface IRolService { 12 | 13 | List findAll(); 14 | 15 | Page findAllPage(Pageable pageable); 16 | 17 | Rol findById(Long idRol); 18 | 19 | Rol createRol(RolDto rol); 20 | 21 | Rol deleteRol(Long idRol); 22 | 23 | Rol updateRol(Long idRol, RolDto rol); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/repository/IUsuarioRepository.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.repository; 2 | 3 | 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import com.tallerMecanico.entity.Usuario; 8 | 9 | @Repository 10 | public interface IUsuarioRepository extends JpaRepository{ 11 | 12 | // Método para poder buscar un usuario mediante su nombre 13 | Usuario findByEmail(String email); 14 | 15 | //Método para poder verificar si un usuario existe en nuestra base de datos 16 | Boolean existsByEmail(String email); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/IMarcaService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | 8 | import com.tallerMecanico.dto.MarcaDto; 9 | import com.tallerMecanico.entity.Marca; 10 | 11 | public interface IMarcaService { 12 | 13 | List findAll(); 14 | 15 | Page findAllPage(Pageable pageable); 16 | 17 | Marca findById(Long idMarca); 18 | 19 | Marca createMarca(MarcaDto marca); 20 | 21 | Marca deleteMarca(Long idMarca); 22 | 23 | Marca updateMarca(Long idMarca, MarcaDto marca); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/ActualizacionDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | import com.tallerMecanico.entity.Cliente; 4 | 5 | public class ActualizacionDto { 6 | 7 | private Cliente cliente; 8 | private String nuevoRol; 9 | 10 | // Constructor, getters y setters 11 | 12 | public Cliente getCliente() { 13 | return cliente; 14 | } 15 | 16 | public void setCliente(Cliente cliente) { 17 | this.cliente = cliente; 18 | } 19 | 20 | public String getNuevoRol() { 21 | return nuevoRol; 22 | } 23 | 24 | public void setNuevoRol(String nuevoRol) { 25 | this.nuevoRol = nuevoRol; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/IModeloService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | 8 | import com.tallerMecanico.dto.ModeloDto; 9 | import com.tallerMecanico.entity.Modelo; 10 | 11 | public interface IModeloService { 12 | 13 | List findAll(); 14 | 15 | Modelo findById(Long idModelo); 16 | 17 | Page findAllPage(Pageable pageable); 18 | 19 | Modelo createModelo(ModeloDto modelo); 20 | 21 | Modelo deleteModelo(Long idModelo); 22 | 23 | Modelo updateModelo(Long idModelo, ModeloDto modelo); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/RegistroResponseDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | 4 | public class RegistroResponseDto { 5 | 6 | private String mensaje; 7 | private Long idUsuario; 8 | 9 | public RegistroResponseDto(String mensaje, Long idUsuario) { 10 | this.mensaje = mensaje; 11 | this.idUsuario = idUsuario; 12 | } 13 | 14 | public String getMensaje() { 15 | return mensaje; 16 | } 17 | 18 | public void setMensaje(String mensaje) { 19 | this.mensaje = mensaje; 20 | } 21 | 22 | public Long getIdUsuario() { 23 | return idUsuario; 24 | } 25 | 26 | public void setIdUsuario(Long idUsuario) { 27 | this.idUsuario = idUsuario; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/IVehiculoService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | 8 | import com.tallerMecanico.dto.VehiculoDto; 9 | import com.tallerMecanico.entity.Vehiculo; 10 | 11 | public interface IVehiculoService { 12 | 13 | List findAll(); 14 | 15 | Page findAllPage(Pageable pageable); 16 | 17 | Vehiculo findById(Long idVehiculo); 18 | 19 | Vehiculo createVehiculo(VehiculoDto vehiculo); 20 | 21 | Vehiculo deleteVehiculo(Long idVehiculo); 22 | 23 | Vehiculo updateVehiculo(Long idVehiculo, VehiculoDto vehiculo); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/repository/IClienteRepository.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.data.jpa.repository.Query; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import com.tallerMecanico.entity.Cliente; 10 | 11 | @Repository 12 | public interface IClienteRepository extends JpaRepository { 13 | 14 | @Query("SELECT c FROM Cliente c WHERE c.nombre LIKE %?1% OR c.apellidoPaterno LIKE %?1% OR c.apellidoMaterno LIKE %?1% OR c.telefono LIKE %?1%") 15 | List findByNombreApellidoPaternoApellidoMaternoTelefonoLike(String searchTerm); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/IEmpleadoService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | 8 | import com.tallerMecanico.dto.EmpleadoDto; 9 | import com.tallerMecanico.entity.Empleado; 10 | 11 | public interface IEmpleadoService { 12 | 13 | List findAll(); 14 | 15 | Page findAllPage(Pageable pageable); 16 | 17 | Empleado findById(Long idEmpleado); 18 | 19 | Empleado createEmpleado(EmpleadoDto empleado, Long idUsuario); 20 | 21 | Empleado deleteEmpleado(Long idEmpleado); 22 | 23 | Empleado updateEmpleado(Long idEmpleado, EmpleadoDto empleado); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/RegistroUsuarioEmpleadoDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | public class RegistroUsuarioEmpleadoDto { 4 | private UsuarioDto usuario; 5 | private EmpleadoDto empleado; 6 | 7 | public RegistroUsuarioEmpleadoDto(UsuarioDto usuario, EmpleadoDto empleado) { 8 | super(); 9 | this.usuario = usuario; 10 | this.empleado = empleado; 11 | } 12 | 13 | public UsuarioDto getUsuario() { 14 | return usuario; 15 | } 16 | 17 | public void setUsuario(UsuarioDto usuario) { 18 | this.usuario = usuario; 19 | } 20 | 21 | public EmpleadoDto getEmpleado() { 22 | return empleado; 23 | } 24 | 25 | public void setEmpleado(EmpleadoDto empleado) { 26 | this.empleado = empleado; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/ITipoMotorService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | 8 | import com.tallerMecanico.dto.TipoMotorDto; 9 | import com.tallerMecanico.entity.TipoMotor; 10 | 11 | public interface ITipoMotorService { 12 | 13 | List findAll(); 14 | 15 | Page findAllPage(Pageable pageable); 16 | 17 | TipoMotor findById(Long idTipoMotor); 18 | 19 | TipoMotor createTipoMotor(TipoMotorDto tipoMotor); 20 | 21 | TipoMotor deleteTipoMotor(Long idTipoMotor); 22 | 23 | TipoMotor updateTipoMotor(Long idTipoMotor, TipoMotorDto tipoMotor); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/RegistroUsuarioClienteDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | 4 | public class RegistroUsuarioClienteDto { 5 | private UsuarioDto usuario; 6 | private ClienteDto cliente; 7 | 8 | 9 | public RegistroUsuarioClienteDto(UsuarioDto usuario, ClienteDto cliente) { 10 | super(); 11 | this.usuario = usuario; 12 | this.cliente = cliente; 13 | } 14 | 15 | 16 | public UsuarioDto getUsuario() { 17 | return usuario; 18 | } 19 | 20 | 21 | public void setUsuario(UsuarioDto usuario) { 22 | this.usuario = usuario; 23 | } 24 | 25 | 26 | public ClienteDto getCliente() { 27 | return cliente; 28 | } 29 | 30 | 31 | public void setCliente(ClienteDto cliente) { 32 | this.cliente = cliente; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/EmpleadoDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | import com.tallerMecanico.entity.Empleado; 4 | import com.tallerMecanico.entity.Usuario; 5 | 6 | 7 | public record EmpleadoDto( 8 | long idEmpleado, 9 | String nombre, 10 | String apellidoPaterno, 11 | String apellidoMaterno, 12 | long nss, 13 | String curp, 14 | String rfc, 15 | String puesto, 16 | String observaciones, 17 | Usuario usuario) { 18 | 19 | public EmpleadoDto(Empleado empleado) { 20 | this(empleado.getIdEmpleado(), empleado.getNombre(), empleado.getApellidoPaterno(), empleado.getApellidoMaterno(), empleado.getNss(), empleado.getCurp(), empleado.getRfc(), empleado.getPuesto(), empleado.getObservaciones(), empleado.getUsuario() ); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/ClienteDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | import java.util.List; 4 | 5 | import com.tallerMecanico.entity.Cliente; 6 | import com.tallerMecanico.entity.Usuario; 7 | import com.tallerMecanico.entity.Vehiculo; 8 | 9 | 10 | public record ClienteDto( 11 | long idCliente, 12 | String nombre, 13 | String apellidoPaterno, 14 | String apellidoMaterno, 15 | String domicilio, 16 | String telefono, 17 | Usuario usuario, 18 | List vehiculos) { 19 | 20 | public ClienteDto(Cliente cliente) { 21 | this(cliente.getIdCliente(), cliente.getNombre(), cliente.getApellidoPaterno(), cliente.getApellidoMaterno(), cliente.getDomicilio(), cliente.getTelefono(), cliente.getUsuario(), cliente.getVehiculos()); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/IOrdenServicioService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | 8 | import com.tallerMecanico.dto.OrdenServicioDto; 9 | import com.tallerMecanico.entity.OrdenServicio; 10 | 11 | public interface IOrdenServicioService { 12 | 13 | List findAll(); 14 | 15 | Page findAllPage(Pageable pageable); 16 | 17 | OrdenServicio findById(Long idOrdenServicio); 18 | 19 | OrdenServicio createOrdenServicio(OrdenServicioDto ordenServicio); 20 | 21 | OrdenServicio deleteOrdenServicio(Long idOrdenServicio); 22 | 23 | OrdenServicio updateOrdenServicio(Long idOrdenServicio, OrdenServicioDto ordenServicio); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/IClienteService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | 8 | import com.tallerMecanico.dto.ClienteDto; 9 | import com.tallerMecanico.entity.Cliente; 10 | 11 | public interface IClienteService { 12 | 13 | List findAll(); 14 | 15 | Page findAllPage(Pageable pageable); 16 | 17 | Cliente findById(Long idCliente); 18 | 19 | Cliente createCliente(ClienteDto cliente, Long idUsuario); 20 | 21 | Cliente deleteCliente(Long idCliente); 22 | 23 | Cliente updateCliente(Long idCliente, ClienteDto cliente); 24 | 25 | List buscarClientesPorNombreApellidoPaternoApellidoMaternoTelefono(String searchTerm); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/IEstatusServicioService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | 8 | import com.tallerMecanico.dto.EstatusServicioDto; 9 | import com.tallerMecanico.entity.EstatusServicio; 10 | 11 | public interface IEstatusServicioService { 12 | 13 | List findAll(); 14 | 15 | Page findAllPage(Pageable pageable); 16 | 17 | EstatusServicio findById(Long idEstatusServicio); 18 | 19 | EstatusServicio createEstatusServicio(EstatusServicioDto estatusServicio); 20 | 21 | EstatusServicio deleteEstatusServicio(Long idEstatusServicio); 22 | 23 | EstatusServicio updateEstatusServicio(Long idEstatusServicio, EstatusServicioDto estatusServicio); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/IUsuarioService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.http.ResponseEntity; 8 | 9 | import com.tallerMecanico.dto.RegistroResponseDto; 10 | import com.tallerMecanico.dto.UsuarioDto; 11 | import com.tallerMecanico.entity.Usuario; 12 | 13 | public interface IUsuarioService { 14 | 15 | List findAll(); 16 | 17 | Page findAllPage(Pageable pageable); 18 | 19 | Usuario findById(Long idUsuario); 20 | 21 | ResponseEntity registrarUsuario(UsuarioDto dtoRegistro, String role); 22 | 23 | Usuario deleteUsuario(Long idUsuario); 24 | 25 | Usuario updateUsuario(Long idUsuario, UsuarioDto usuario); 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/VehiculoDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | import java.util.List; 4 | 5 | import com.tallerMecanico.entity.Cliente; 6 | import com.tallerMecanico.entity.Modelo; 7 | import com.tallerMecanico.entity.OrdenServicio; 8 | import com.tallerMecanico.entity.TipoMotor; 9 | import com.tallerMecanico.entity.Vehiculo; 10 | 11 | 12 | public record VehiculoDto(long idVehiculo, String vin, String matricula, Modelo modelo, int anioModelo, String color, TipoMotor tipoMotor, String imagen, Cliente cliente, List ordenServicio) { 13 | 14 | public VehiculoDto(Vehiculo vehiculo) { 15 | this(vehiculo.getIdVehiculo(), vehiculo.getVin(), vehiculo.getMatricula(), vehiculo.getModelo(), vehiculo.getAnioModelo(), vehiculo.getColor(), vehiculo.getTipoMotor(), vehiculo.getImagen(), vehiculo.getCliente(),vehiculo.getOrdenServicio()); 16 | } 17 | } -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/IDetalleOrdenServicioService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | 8 | import com.tallerMecanico.dto.DetalleOrdenServicioDto; 9 | import com.tallerMecanico.entity.DetalleOrdenServicio; 10 | 11 | public interface IDetalleOrdenServicioService { 12 | 13 | List findAll(); 14 | 15 | Page findAllPage(Pageable pageable); 16 | 17 | DetalleOrdenServicio findById(Long idDetalleOrdenServicio); 18 | 19 | DetalleOrdenServicio createDetalleOrdenServicio(DetalleOrdenServicioDto detalleOrdenServicio); 20 | 21 | DetalleOrdenServicio deleteDetalleOrdenServicio(Long idDetalleOrdenServicio); 22 | 23 | DetalleOrdenServicio updateDetalleOrdenServicio(Long idDetalleOrdenServicio, DetalleOrdenServicioDto detalleOrdenServicio); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/entity/Marca.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.entity; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.GeneratedValue; 5 | import jakarta.persistence.GenerationType; 6 | import jakarta.persistence.Id; 7 | import jakarta.persistence.Table; 8 | 9 | 10 | @Entity 11 | @Table(name = "marcas") 12 | public class Marca { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.IDENTITY) 15 | private long idMarca; 16 | private String marca; 17 | 18 | public Marca() { 19 | super(); 20 | } 21 | 22 | public Marca(long idMarca, String marca) { 23 | super(); 24 | this.idMarca = idMarca; 25 | this.marca = marca; 26 | } 27 | 28 | public long getIdMarca() { 29 | return idMarca; 30 | } 31 | 32 | public void setIdMarca(long idMarca) { 33 | this.idMarca = idMarca; 34 | } 35 | 36 | public String getMarca() { 37 | return marca; 38 | } 39 | 40 | public void setMarca(String marca) { 41 | this.marca = marca; 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/entity/Rol.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.entity; 2 | 3 | import jakarta.persistence.Column; 4 | import jakarta.persistence.Entity; 5 | import jakarta.persistence.GeneratedValue; 6 | import jakarta.persistence.GenerationType; 7 | import jakarta.persistence.Id; 8 | import jakarta.persistence.Table; 9 | 10 | @Entity 11 | @Table(name = "roles") 12 | public class Rol { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.IDENTITY) 15 | @Column(name = "id_rol") 16 | private Long idRol; 17 | private String nombre; 18 | 19 | public Rol() { 20 | super(); 21 | } 22 | 23 | public Rol(Long idRol, String nombre) { 24 | super(); 25 | this.idRol = idRol; 26 | this.nombre = nombre; 27 | } 28 | 29 | public Long getIdRol() { 30 | return idRol; 31 | } 32 | 33 | public void setIdRol(Long idRol) { 34 | this.idRol = idRol; 35 | } 36 | 37 | public String getNombre() { 38 | return nombre; 39 | } 40 | 41 | public void setNombre(String nombre) { 42 | this.nombre = nombre; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/dto/OrdenServicioDto.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.dto; 2 | 3 | import java.util.Date; 4 | 5 | import com.tallerMecanico.entity.Empleado; 6 | import com.tallerMecanico.entity.EstatusServicio; 7 | import com.tallerMecanico.entity.Factura; 8 | import com.tallerMecanico.entity.OrdenServicio; 9 | import com.tallerMecanico.entity.Vehiculo; 10 | 11 | public record OrdenServicioDto(long idOrdenServicio, Date fechaOrden, String falla, String kilometraje, 12 | String observaciones, EstatusServicio estatusServicio, Factura factura, Vehiculo vehiculo, String comentarios, 13 | Empleado empleado) { 14 | 15 | public OrdenServicioDto(OrdenServicio ordenServicio) { 16 | this(ordenServicio.getIdOrdenServicio(), ordenServicio.getFechaOrden(), ordenServicio.getFalla(), 17 | ordenServicio.getKilometraje(), ordenServicio.getObservaciones(), ordenServicio.getEstatusServicio(), 18 | ordenServicio.getFactura(), ordenServicio.getVehiculo(), ordenServicio.getComentarios(), 19 | ordenServicio.getEmpleado()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/resources/data2.sql: -------------------------------------------------------------------------------- 1 | -- Insertar usuarios 2 | 3 | -- Insertar en la tabla usuarios 4 | INSERT INTO usuarios (email, password) 5 | SELECT 'usuario1@gmail.com', '12345' 6 | WHERE NOT EXISTS (SELECT * FROM usuarios WHERE email = 'usuario1@gmail.com'); 7 | 8 | -- Insertar en la tabla usuarios_roles si la combinación usuario_id y rol_id no existe 9 | INSERT INTO usuarios_roles (usuario_id, rol_id) 10 | SELECT 1, 1 11 | WHERE NOT EXISTS ( 12 | SELECT * 13 | FROM usuarios_roles 14 | WHERE usuario_id = 1 15 | AND rol_id = 1 16 | ); 17 | 18 | -- Insertar en la tabla empleados asociando el usuario al empleado correspondiente si no hay duplicados 19 | INSERT INTO empleados (nombre, apellido_paterno, apellido_materno, nss, curp, rfc, puesto, observaciones, usuario_id) 20 | SELECT 'Empleado1', 'ApellidoPaternoEmpleado', 'ApellidoMaternoEmpleado', 1234567890, 'CurpEmpleado', 'RfcEmpleado', 'PuestoEmpleado', 'ObservacionesEmpleado', 1 21 | WHERE NOT EXISTS ( 22 | SELECT * 23 | FROM empleados 24 | WHERE usuario_id = 1 25 | ); 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/entity/TipoMotor.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.entity; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.GeneratedValue; 5 | import jakarta.persistence.GenerationType; 6 | import jakarta.persistence.Id; 7 | import jakarta.persistence.Table; 8 | 9 | 10 | @Entity 11 | @Table(name = "tipoMotor") 12 | public class TipoMotor { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.IDENTITY) 15 | private long idTipoMotor; 16 | private String tipoMotor; 17 | 18 | public TipoMotor() { 19 | super(); 20 | } 21 | 22 | public TipoMotor(long idTipoMotor, String tipoMotor) { 23 | super(); 24 | this.idTipoMotor = idTipoMotor; 25 | this.tipoMotor = tipoMotor; 26 | } 27 | 28 | public long getIdTipoMotor() { 29 | return idTipoMotor; 30 | } 31 | 32 | public void setIdTipoMotor(long idTipoMotor) { 33 | this.idTipoMotor = idTipoMotor; 34 | } 35 | 36 | public String getTipoMotor() { 37 | return tipoMotor; 38 | } 39 | 40 | public void setTipoMotor(String tipoMotor) { 41 | this.tipoMotor = tipoMotor; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/entity/EstatusServicio.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.entity; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.GeneratedValue; 5 | import jakarta.persistence.GenerationType; 6 | import jakarta.persistence.Id; 7 | import jakarta.persistence.Table; 8 | 9 | @Entity 10 | @Table(name = "estatusServicio") 11 | public class EstatusServicio { 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.IDENTITY) 14 | private long idEstatusServicio; 15 | private String estatusServicio; 16 | 17 | public EstatusServicio() { 18 | super(); 19 | } 20 | 21 | public EstatusServicio(long idEstatusServicio, String estatusServicio) { 22 | super(); 23 | this.idEstatusServicio = idEstatusServicio; 24 | this.estatusServicio = estatusServicio; 25 | } 26 | 27 | public long getIdEstatusServicio() { 28 | return idEstatusServicio; 29 | } 30 | 31 | public void setIdEstatusServicio(long idEstatusServicio) { 32 | this.idEstatusServicio = idEstatusServicio; 33 | } 34 | 35 | public String getEstatusServicio() { 36 | return estatusServicio; 37 | } 38 | 39 | public void setEstatusServicio(String estatusServicio) { 40 | this.estatusServicio = estatusServicio; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/resources/data3.sql: -------------------------------------------------------------------------------- 1 | -- Insertar usuarios 2 | 3 | -- Insertar en la tabla usuarios 4 | INSERT INTO usuarios (email, password) 5 | SELECT 'usuario1@gmail.com', '12345' 6 | WHERE NOT EXISTS (SELECT * FROM usuarios WHERE email = 'usuario1@gmail.com'); 7 | 8 | -- Insertar en la tabla usuarios_roles si la combinación usuario_id y rol_id no existe 9 | INSERT INTO usuarios_roles (usuario_id, rol_id) 10 | SELECT currval(pg_get_serial_sequence('usuarios', 'id_usuario')), 1 11 | WHERE NOT EXISTS ( 12 | SELECT * 13 | FROM usuarios_roles 14 | WHERE usuario_id = currval(pg_get_serial_sequence('usuarios', 'id_usuario')) 15 | AND rol_id = 1 16 | ); 17 | 18 | -- Insertar en la tabla empleados asociando el usuario al empleado correspondiente si no hay duplicados 19 | INSERT INTO empleados (nombre, apellido_paterno, apellido_materno, nss, curp, rfc, puesto, observaciones, usuario_id) 20 | SELECT 'Empleado1', 'ApellidoPaternoEmpleado', 'ApellidoMaternoEmpleado', 1234567890, 'CurpEmpleado', 'RfcEmpleado', 'PuestoEmpleado', 'ObservacionesEmpleado', currval(pg_get_serial_sequence('usuarios', 'id_usuario')) 21 | WHERE NOT EXISTS ( 22 | SELECT * 23 | FROM empleados 24 | WHERE usuario_id = currval(pg_get_serial_sequence('usuarios', 'id_usuario')) 25 | ); 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/entity/Modelo.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.entity; 2 | 3 | 4 | import jakarta.persistence.Entity; 5 | import jakarta.persistence.FetchType; 6 | import jakarta.persistence.GeneratedValue; 7 | import jakarta.persistence.GenerationType; 8 | import jakarta.persistence.Id; 9 | import jakarta.persistence.JoinColumn; 10 | import jakarta.persistence.ManyToOne; 11 | import jakarta.persistence.Table; 12 | 13 | @Entity 14 | @Table(name="modelos") 15 | public class Modelo { 16 | @Id 17 | @GeneratedValue(strategy = GenerationType.IDENTITY) 18 | private long idModelo; 19 | private String modelo; 20 | 21 | @ManyToOne(fetch = FetchType.EAGER) 22 | @JoinColumn(name = "marcaId") 23 | private Marca marca; 24 | 25 | public Modelo() { 26 | super(); 27 | } 28 | 29 | public Modelo(long idModelo, String modelo, Marca marca) { 30 | super(); 31 | this.idModelo = idModelo; 32 | this.modelo = modelo; 33 | this.marca = marca; 34 | } 35 | 36 | public long getIdModelo() { 37 | return idModelo; 38 | } 39 | 40 | public void setIdModelo(long idModelo) { 41 | this.idModelo = idModelo; 42 | } 43 | 44 | public String getModelo() { 45 | return modelo; 46 | } 47 | 48 | public void setModelo(String modelo) { 49 | this.modelo = modelo; 50 | } 51 | 52 | public Marca getMarca() { 53 | return marca; 54 | } 55 | 56 | public void setMarca(Marca marca) { 57 | this.marca = marca; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/entity/DetalleFactura.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.entity; 2 | 3 | 4 | import jakarta.persistence.Entity; 5 | import jakarta.persistence.GeneratedValue; 6 | import jakarta.persistence.GenerationType; 7 | import jakarta.persistence.Id; 8 | import jakarta.persistence.ManyToOne; 9 | import jakarta.persistence.Table; 10 | 11 | 12 | @Entity 13 | @Table(name = "detalleFacturas") 14 | public class DetalleFactura { 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private long idDetalleFactura; 18 | private String descripcionServicio; 19 | private double costo; 20 | @ManyToOne 21 | private Factura factura; 22 | 23 | public DetalleFactura() { 24 | super(); 25 | } 26 | 27 | public DetalleFactura(long idDetalleFactura, String descripcionServicio, double costo, Factura factura) { 28 | super(); 29 | this.idDetalleFactura = idDetalleFactura; 30 | this.descripcionServicio = descripcionServicio; 31 | this.costo = costo; 32 | this.factura = factura; 33 | } 34 | 35 | public long getIdDetalleFactura() { 36 | return idDetalleFactura; 37 | } 38 | 39 | public void setIdDetalleFactura(long idDetalleFactura) { 40 | this.idDetalleFactura = idDetalleFactura; 41 | } 42 | 43 | public String getDescripcionServicio() { 44 | return descripcionServicio; 45 | } 46 | 47 | public void setDescripcionServicio(String descripcionServicio) { 48 | this.descripcionServicio = descripcionServicio; 49 | } 50 | 51 | public double getCosto() { 52 | return costo; 53 | } 54 | 55 | public void setCosto(double costo) { 56 | this.costo = costo; 57 | } 58 | 59 | public Factura getFactura() { 60 | return factura; 61 | } 62 | 63 | public void setFactura(Factura factura) { 64 | this.factura = factura; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/entity/DetalleOrdenServicio.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.entity; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.GeneratedValue; 5 | import jakarta.persistence.GenerationType; 6 | import jakarta.persistence.Id; 7 | import jakarta.persistence.JoinColumn; 8 | import jakarta.persistence.ManyToOne; 9 | import jakarta.persistence.Table; 10 | 11 | 12 | @Entity 13 | @Table(name = "detalleOrdenServicios") 14 | public class DetalleOrdenServicio { 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private long idDetalleOrdenServicio; 18 | private String descripcionServicio; 19 | @ManyToOne 20 | @JoinColumn(name = "ordenServicioId") 21 | private OrdenServicio ordenServicio; 22 | 23 | public DetalleOrdenServicio() { 24 | super(); 25 | } 26 | 27 | public DetalleOrdenServicio(long idDetalleOrdenServicio, String descripcionServicio, OrdenServicio ordenServicio) { 28 | super(); 29 | this.idDetalleOrdenServicio = idDetalleOrdenServicio; 30 | this.descripcionServicio = descripcionServicio; 31 | this.ordenServicio = ordenServicio; 32 | } 33 | 34 | public long getIdDetalleOrdenServicio() { 35 | return idDetalleOrdenServicio; 36 | } 37 | 38 | public void setIdDetalleOrdenServicio(long idDetalleOrdenServicio) { 39 | this.idDetalleOrdenServicio = idDetalleOrdenServicio; 40 | } 41 | 42 | public String getDescripcionServicio() { 43 | return descripcionServicio; 44 | } 45 | 46 | public void setDescripcionServicio(String descripcionServicio) { 47 | this.descripcionServicio = descripcionServicio; 48 | } 49 | 50 | public OrdenServicio getOrdenServicio() { 51 | return ordenServicio; 52 | } 53 | 54 | public void setOrdenServicio(OrdenServicio ordenServicio) { 55 | this.ordenServicio = ordenServicio; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | -- estatus servicios 2 | INSERT INTO estatus_servicio(estatus_servicio) 3 | SELECT 'Nuevo' WHERE NOT EXISTS (SELECT * FROM estatus_servicio WHERE estatus_servicio = 'Nuevo'); 4 | 5 | INSERT INTO estatus_servicio(estatus_servicio) 6 | SELECT 'Pendiente' WHERE NOT EXISTS (SELECT * FROM estatus_servicio WHERE estatus_servicio = 'Pendiente'); 7 | 8 | INSERT INTO estatus_servicio(estatus_servicio) 9 | SELECT 'Progreso' WHERE NOT EXISTS (SELECT * FROM estatus_servicio WHERE estatus_servicio = 'Progreso'); 10 | 11 | INSERT INTO estatus_servicio(estatus_servicio) 12 | SELECT 'Terminado' WHERE NOT EXISTS (SELECT * FROM estatus_servicio WHERE estatus_servicio = 'Terminado'); 13 | 14 | INSERT INTO estatus_servicio(estatus_servicio) 15 | SELECT 'Entregado' WHERE NOT EXISTS (SELECT * FROM estatus_servicio WHERE estatus_servicio = 'Entregado'); 16 | 17 | -- Tipo Motor 18 | INSERT INTO tipo_motor(tipo_motor) 19 | SELECT 'Gasolina' WHERE NOT EXISTS (SELECT * FROM tipo_motor WHERE tipo_motor = 'Gasolina'); 20 | 21 | INSERT INTO tipo_motor(tipo_motor) 22 | SELECT 'Diesel' WHERE NOT EXISTS (SELECT * FROM tipo_motor WHERE tipo_motor = 'Diesel'); 23 | 24 | INSERT INTO tipo_motor(tipo_motor) 25 | SELECT 'Eléctrico' WHERE NOT EXISTS (SELECT * FROM tipo_motor WHERE tipo_motor = 'Eléctrico'); 26 | 27 | INSERT INTO tipo_motor(tipo_motor) 28 | SELECT 'Hibrido' WHERE NOT EXISTS (SELECT * FROM tipo_motor WHERE tipo_motor = 'Hibrido'); 29 | 30 | 31 | -- tabla roles 32 | INSERT INTO roles(nombre) 33 | SELECT 'ADMIN' WHERE NOT EXISTS (SELECT * FROM roles WHERE nombre = 'ADMIN'); 34 | 35 | INSERT INTO roles(nombre) 36 | SELECT 'EMPLEADO' WHERE NOT EXISTS (SELECT * FROM roles WHERE nombre = 'EMPLEADO'); 37 | 38 | INSERT INTO roles(nombre) 39 | SELECT 'CLIENTE' WHERE NOT EXISTS (SELECT * FROM roles WHERE nombre = 'CLIENTE'); 40 | 41 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/RolService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | import java.util.NoSuchElementException; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.domain.Pageable; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.transaction.annotation.Transactional; 11 | 12 | import com.tallerMecanico.dto.RolDto; 13 | import com.tallerMecanico.entity.Rol; 14 | import com.tallerMecanico.repository.IRolRepository; 15 | 16 | @Service 17 | public class RolService implements IRolService { 18 | 19 | @Autowired 20 | private IRolRepository rolRepository; 21 | 22 | // Consulta todos 23 | @Transactional(readOnly = true) 24 | public List findAll() { 25 | return (List) rolRepository.findAll(); 26 | } 27 | 28 | // consulta todos para paginación 29 | @Transactional(readOnly = true) 30 | public Page findAllPage(Pageable pageable) { 31 | return rolRepository.findAll(pageable); 32 | } 33 | 34 | // consulta por id 35 | @Transactional(readOnly = true) 36 | public Rol findById(Long idRol) { 37 | return rolRepository.findById(idRol).orElse(null); 38 | } 39 | 40 | // Crear 41 | @Transactional 42 | public Rol createRol(RolDto rol) { 43 | Rol rolEntity = new Rol(); 44 | rolEntity.setNombre(rol.nombre()); 45 | return rolRepository.save(rolEntity); 46 | } 47 | 48 | // Eliminar 49 | public Rol deleteRol(Long idRol) { 50 | rolRepository.deleteById(idRol); 51 | return null; 52 | } 53 | 54 | // Modificar 55 | @Transactional 56 | public Rol updateRol(Long idRol, RolDto rol) { 57 | Rol rolEntity = rolRepository.findById(idRol) 58 | .orElseThrow(() -> new NoSuchElementException("Rol no encontrado con el ID: " + idRol)); 59 | rolEntity.setNombre(rol.nombre()); 60 | return rolRepository.save(rolEntity); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 3.2.3 10 | 11 | 12 | com.tallerMecanico 13 | tallerMecanico 14 | 0.0.1-SNAPSHOT 15 | tallerMecanico 16 | Demo project for Spring Boot 17 | 18 | 17 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-data-jpa 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-devtools 33 | runtime 34 | true 35 | 36 | 37 | org.postgresql 38 | postgresql 39 | runtime 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-test 44 | test 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-maven-plugin 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/MarcaService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | import java.util.NoSuchElementException; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.domain.Pageable; 9 | import org.springframework.data.domain.Sort; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import com.tallerMecanico.dto.MarcaDto; 14 | import com.tallerMecanico.entity.Marca; 15 | import com.tallerMecanico.repository.IMarcaRepository; 16 | 17 | @Service 18 | public class MarcaService implements IMarcaService { 19 | 20 | @Autowired 21 | private IMarcaRepository marcaRepository; 22 | 23 | // Consulta todos 24 | @Transactional(readOnly = true) 25 | public List findAll() { 26 | return (List) marcaRepository.findAll(Sort.by("idMarca")); 27 | } 28 | 29 | // consulta todos para paginación 30 | @Transactional(readOnly = true) 31 | public Page findAllPage(Pageable pageable) { 32 | return marcaRepository.findAll(pageable); 33 | } 34 | 35 | // consulta por id 36 | @Transactional(readOnly = true) 37 | public Marca findById(Long idMarca) { 38 | return marcaRepository.findById(idMarca).orElse(null); 39 | } 40 | 41 | // Crear 42 | @Transactional 43 | public Marca createMarca(MarcaDto marca) { 44 | Marca marcaEntity = new Marca(); 45 | marcaEntity.setMarca(marca.marca()); 46 | return marcaRepository.save(marcaEntity); 47 | } 48 | 49 | // Eliminar 50 | public Marca deleteMarca(Long idMarca) { 51 | marcaRepository.deleteById(idMarca); 52 | return null; 53 | } 54 | 55 | // Modificar 56 | @Transactional 57 | public Marca updateMarca(Long idMarca, MarcaDto marca) { 58 | Marca marcaEntity = marcaRepository.findById(idMarca) 59 | .orElseThrow(() -> new NoSuchElementException("Marca no encontrada con el ID: " + idMarca)); 60 | marcaEntity.setMarca(marca.marca()); 61 | return marcaRepository.save(marcaEntity); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/ModeloService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | import java.util.NoSuchElementException; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.domain.Pageable; 9 | import org.springframework.data.domain.Sort; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import com.tallerMecanico.dto.ModeloDto; 14 | import com.tallerMecanico.entity.Modelo; 15 | import com.tallerMecanico.repository.IModeloRepository; 16 | 17 | @Service 18 | public class ModeloService implements IModeloService { 19 | 20 | @Autowired 21 | private IModeloRepository modeloRepository; 22 | 23 | // Consulta todos 24 | @Transactional(readOnly = true) 25 | public List findAll() { 26 | return (List) modeloRepository.findAll(Sort.by("idModelo")); 27 | } 28 | 29 | // consulta todos para paginación 30 | @Transactional(readOnly = true) 31 | public Page findAllPage(Pageable pageable) { 32 | return modeloRepository.findAll(pageable); 33 | } 34 | 35 | // consulta por id 36 | @Transactional(readOnly = true) 37 | public Modelo findById(Long idModelo) { 38 | return modeloRepository.findById(idModelo).orElse(null); 39 | } 40 | 41 | // Crear 42 | @Transactional 43 | public Modelo createModelo(ModeloDto modelo) { 44 | Modelo modeloEntity = new Modelo(); 45 | modeloEntity.setModelo(modelo.modelo()); 46 | modeloEntity.setMarca(modelo.marca()); 47 | return modeloRepository.save(modeloEntity); 48 | } 49 | 50 | // Eliminar 51 | public Modelo deleteModelo(Long idModelo) { 52 | modeloRepository.deleteById(idModelo); 53 | return null; 54 | } 55 | 56 | // Modificar 57 | @Transactional 58 | public Modelo updateModelo(Long idModelo, ModeloDto modelo) { 59 | Modelo modeloEntity = modeloRepository.findById(idModelo) 60 | .orElseThrow(() -> new NoSuchElementException("Modelo no encontrado con el ID: " + idModelo)); 61 | modeloEntity.setModelo(modelo.modelo()); 62 | modeloEntity.setMarca(modelo.marca()); 63 | return modeloRepository.save(modeloEntity); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/TipoMotorService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | import java.util.NoSuchElementException; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.domain.Pageable; 9 | import org.springframework.data.domain.Sort; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import com.tallerMecanico.dto.TipoMotorDto; 14 | import com.tallerMecanico.entity.TipoMotor; 15 | import com.tallerMecanico.repository.ITipoMotorRepository; 16 | 17 | @Service 18 | public class TipoMotorService implements ITipoMotorService { 19 | 20 | @Autowired 21 | private ITipoMotorRepository tipoMotorRepository; 22 | 23 | // Consulta todos 24 | @Transactional(readOnly = true) 25 | public List findAll() { 26 | return (List) tipoMotorRepository.findAll(Sort.by("idTipoMotor")); 27 | } 28 | 29 | // consulta todos para paginación 30 | @Transactional(readOnly = true) 31 | public Page findAllPage(Pageable pageable) { 32 | return tipoMotorRepository.findAll(pageable); 33 | } 34 | 35 | // consulta por id 36 | @Transactional(readOnly = true) 37 | public TipoMotor findById(Long idTipoMotor) { 38 | return tipoMotorRepository.findById(idTipoMotor).orElse(null); 39 | } 40 | 41 | // Crear 42 | @Transactional 43 | public TipoMotor createTipoMotor(TipoMotorDto tipoMotor) { 44 | TipoMotor tipoMotorEntity = new TipoMotor(); 45 | tipoMotorEntity.setTipoMotor(tipoMotor.tipoMotor()); 46 | return tipoMotorRepository.save(tipoMotorEntity); 47 | } 48 | 49 | // Eliminar 50 | public TipoMotor deleteTipoMotor(Long idTipoMotor) { 51 | tipoMotorRepository.deleteById(idTipoMotor); 52 | return null; 53 | } 54 | 55 | // Modificar 56 | @Transactional 57 | public TipoMotor updateTipoMotor(Long idTipoMotor, TipoMotorDto tipoMotor) { 58 | TipoMotor tipoMotorEntity = tipoMotorRepository.findById(idTipoMotor) 59 | .orElseThrow(() -> new NoSuchElementException("Tipo de Motor no encontrado con el ID: " + idTipoMotor)); 60 | tipoMotorEntity.setTipoMotor(tipoMotor.tipoMotor()); 61 | return tipoMotorRepository.save(tipoMotorEntity); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/entity/Factura.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.entity; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | import jakarta.persistence.CascadeType; 8 | import jakarta.persistence.Entity; 9 | import jakarta.persistence.GeneratedValue; 10 | import jakarta.persistence.GenerationType; 11 | import jakarta.persistence.Id; 12 | import jakarta.persistence.JoinColumn; 13 | import jakarta.persistence.OneToMany; 14 | import jakarta.persistence.OneToOne; 15 | import jakarta.persistence.Table; 16 | 17 | @Entity 18 | @Table(name = "facturas") 19 | public class Factura { 20 | @Id 21 | @GeneratedValue(strategy = GenerationType.IDENTITY) 22 | private long idFactura; 23 | private Date fechaFactura; 24 | private double monto; 25 | @OneToOne 26 | @JoinColumn(name="ordenServicio_id") 27 | private OrdenServicio ordenServicio; 28 | @OneToMany(mappedBy = "factura", cascade = CascadeType.ALL, orphanRemoval = true) 29 | private List detalleFacturas = new ArrayList<>(); 30 | 31 | public Factura() { 32 | super(); 33 | } 34 | 35 | public Factura(long idFactura, Date fechaFactura, double monto, OrdenServicio ordenServicio, 36 | List detalleFacturas) { 37 | super(); 38 | this.idFactura = idFactura; 39 | this.fechaFactura = fechaFactura; 40 | this.monto = monto; 41 | this.ordenServicio = ordenServicio; 42 | this.detalleFacturas = detalleFacturas; 43 | } 44 | 45 | public long getIdFactura() { 46 | return idFactura; 47 | } 48 | 49 | public void setIdFactura(long idFactura) { 50 | this.idFactura = idFactura; 51 | } 52 | 53 | public Date getFechaFactura() { 54 | return fechaFactura; 55 | } 56 | 57 | public void setFechaFactura(Date fechaFactura) { 58 | this.fechaFactura = fechaFactura; 59 | } 60 | 61 | public double getMonto() { 62 | return monto; 63 | } 64 | 65 | public void setMonto(double monto) { 66 | this.monto = monto; 67 | } 68 | 69 | public OrdenServicio getOrdenServicio() { 70 | return ordenServicio; 71 | } 72 | 73 | public void setOrdenServicio(OrdenServicio ordenServicio) { 74 | this.ordenServicio = ordenServicio; 75 | } 76 | 77 | public List getDetalleFacturas() { 78 | return detalleFacturas; 79 | } 80 | 81 | public void setDetalleFacturas(List detalleFacturas) { 82 | this.detalleFacturas = detalleFacturas; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/EstatusServicioService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | import java.util.NoSuchElementException; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.domain.Pageable; 9 | import org.springframework.data.domain.Sort; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import com.tallerMecanico.dto.EstatusServicioDto; 14 | import com.tallerMecanico.entity.EstatusServicio; 15 | import com.tallerMecanico.repository.IEstatusServicioRepository; 16 | 17 | @Service 18 | public class EstatusServicioService implements IEstatusServicioService { 19 | 20 | @Autowired 21 | private IEstatusServicioRepository estatusServicioRepository; 22 | 23 | // Consulta todos 24 | @Transactional(readOnly = true) 25 | public List findAll() { 26 | return (List) estatusServicioRepository.findAll(Sort.by("idEstatusServicio")); 27 | } 28 | 29 | // consulta todos para paginación 30 | @Transactional(readOnly = true) 31 | public Page findAllPage(Pageable pageable) { 32 | return estatusServicioRepository.findAll(pageable); 33 | } 34 | 35 | // consulta por id 36 | @Transactional(readOnly = true) 37 | public EstatusServicio findById(Long idEstatusServicio) { 38 | return estatusServicioRepository.findById(idEstatusServicio).orElse(null); 39 | } 40 | 41 | // Crear 42 | @Transactional 43 | public EstatusServicio createEstatusServicio(EstatusServicioDto estatusServicio) { 44 | EstatusServicio estatusServicioEntity = new EstatusServicio(); 45 | estatusServicioEntity.setEstatusServicio(estatusServicio.estatusServicio()); 46 | return estatusServicioRepository.save(estatusServicioEntity); 47 | } 48 | 49 | // Eliminar 50 | public EstatusServicio deleteEstatusServicio(Long idEstatusServicio) { 51 | estatusServicioRepository.deleteById(idEstatusServicio); 52 | return null; 53 | } 54 | 55 | // Modificar 56 | @Transactional 57 | public EstatusServicio updateEstatusServicio(Long idEstatusServicio, EstatusServicioDto estatusServicio) { 58 | EstatusServicio estatusServicioEntity = estatusServicioRepository.findById(idEstatusServicio) 59 | .orElseThrow(() -> new NoSuchElementException("Estatus de servicio no encontrado con el ID: " + idEstatusServicio)); 60 | estatusServicioEntity.setEstatusServicio(estatusServicio.estatusServicio()); 61 | return estatusServicioRepository.save(estatusServicioEntity); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/entity/Usuario.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.entity; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.fasterxml.jackson.annotation.JsonIgnore; 7 | 8 | import jakarta.persistence.CascadeType; 9 | import jakarta.persistence.Column; 10 | import jakarta.persistence.Entity; 11 | import jakarta.persistence.FetchType; 12 | import jakarta.persistence.GeneratedValue; 13 | import jakarta.persistence.GenerationType; 14 | import jakarta.persistence.Id; 15 | import jakarta.persistence.JoinColumn; 16 | import jakarta.persistence.JoinTable; 17 | import jakarta.persistence.ManyToMany; 18 | import jakarta.persistence.OneToOne; 19 | import jakarta.persistence.Table; 20 | 21 | @Entity 22 | @Table(name = "usuarios") 23 | public class Usuario { 24 | @Id 25 | @GeneratedValue(strategy = GenerationType.IDENTITY) 26 | @Column(name = "id_usuario") 27 | private long idUsuario; 28 | private String email; 29 | private String password; 30 | @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.MERGE) 31 | @JoinTable(name = "usuarios_roles", joinColumns = @JoinColumn(name = "usuario_id", referencedColumnName = "id_usuario") 32 | , inverseJoinColumns = @JoinColumn(name = "rol_id", referencedColumnName = "id_rol")) 33 | private List rol = new ArrayList<>(); 34 | @OneToOne(mappedBy = "usuario") 35 | @JsonIgnore 36 | private Cliente cliente; 37 | @OneToOne(mappedBy = "usuario") 38 | @JsonIgnore 39 | private Empleado empleado; 40 | 41 | public Usuario() { 42 | super(); 43 | } 44 | 45 | public Usuario(long idUsuario, String email, String password, List rol, Cliente cliente, Empleado empleado) { 46 | super(); 47 | this.idUsuario = idUsuario; 48 | this.email = email; 49 | this.password = password; 50 | this.rol = rol; 51 | this.cliente = cliente; 52 | this.empleado = empleado; 53 | } 54 | 55 | public long getIdUsuario() { 56 | return idUsuario; 57 | } 58 | 59 | public void setIdUsuario(long idUsuario) { 60 | this.idUsuario = idUsuario; 61 | } 62 | 63 | public String getEmail() { 64 | return email; 65 | } 66 | 67 | public void setEmail(String email) { 68 | this.email = email; 69 | } 70 | 71 | public String getPassword() { 72 | return password; 73 | } 74 | 75 | public void setPassword(String password) { 76 | this.password = password; 77 | } 78 | 79 | public List getRol() { 80 | return rol; 81 | } 82 | 83 | public void setRol(List rol) { 84 | this.rol = rol; 85 | } 86 | 87 | public Cliente getCliente() { 88 | return cliente; 89 | } 90 | 91 | public void setCliente(Cliente cliente) { 92 | this.cliente = cliente; 93 | } 94 | 95 | public Empleado getEmpleado() { 96 | return empleado; 97 | } 98 | 99 | public void setEmpleado(Empleado empleado) { 100 | this.empleado = empleado; 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/DetalleOrdenServicioService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | import java.util.NoSuchElementException; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.domain.Pageable; 9 | import org.springframework.data.domain.Sort; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import com.tallerMecanico.dto.DetalleOrdenServicioDto; 14 | import com.tallerMecanico.entity.DetalleOrdenServicio; 15 | import com.tallerMecanico.repository.IDetalleOrdenServicioRepository; 16 | 17 | @Service 18 | public class DetalleOrdenServicioService implements IDetalleOrdenServicioService { 19 | 20 | @Autowired 21 | private IDetalleOrdenServicioRepository detalleOrdenServicioRepository; 22 | 23 | // Consulta todos 24 | @Transactional(readOnly = true) 25 | public List findAll() { 26 | return (List) detalleOrdenServicioRepository.findAll(Sort.by("idDetalleOrdenServicio")); 27 | } 28 | 29 | // consulta todos para paginación 30 | @Transactional(readOnly = true) 31 | public Page findAllPage(Pageable pageable) { 32 | return detalleOrdenServicioRepository.findAll(pageable); 33 | } 34 | 35 | // consulta por id 36 | @Transactional(readOnly = true) 37 | public DetalleOrdenServicio findById(Long idDetalleOrdenServicio) { 38 | return detalleOrdenServicioRepository.findById(idDetalleOrdenServicio).orElse(null); 39 | } 40 | 41 | // Crear 42 | @Transactional 43 | public DetalleOrdenServicio createDetalleOrdenServicio(DetalleOrdenServicioDto detalleOrdenServicio) { 44 | DetalleOrdenServicio detalleOrdenServicioEntity = new DetalleOrdenServicio(); 45 | detalleOrdenServicioEntity.setDescripcionServicio(detalleOrdenServicio.descripcionServicio()); 46 | detalleOrdenServicioEntity.setOrdenServicio(detalleOrdenServicio.ordenServicio()); 47 | return detalleOrdenServicioRepository.save(detalleOrdenServicioEntity); 48 | } 49 | 50 | // Eliminar 51 | public DetalleOrdenServicio deleteDetalleOrdenServicio(Long idDetalleOrdenServicio) { 52 | detalleOrdenServicioRepository.deleteById(idDetalleOrdenServicio); 53 | return null; 54 | } 55 | 56 | // Modificar 57 | @Transactional 58 | public DetalleOrdenServicio updateDetalleOrdenServicio(Long idDetalleOrdenServicio, DetalleOrdenServicioDto detalleOrdenServicio) { 59 | DetalleOrdenServicio detalleOrdenServicioEntity = detalleOrdenServicioRepository.findById(idDetalleOrdenServicio) 60 | .orElseThrow(() -> new NoSuchElementException("Modelo no encontrado con el ID: " + idDetalleOrdenServicio)); 61 | detalleOrdenServicioEntity.setDescripcionServicio(detalleOrdenServicio.descripcionServicio()); 62 | detalleOrdenServicioEntity.setOrdenServicio(detalleOrdenServicio.ordenServicio()); 63 | return detalleOrdenServicioRepository.save(detalleOrdenServicioEntity); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/VehiculoService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | import java.util.NoSuchElementException; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.domain.Pageable; 9 | import org.springframework.data.domain.Sort; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import com.tallerMecanico.dto.VehiculoDto; 14 | import com.tallerMecanico.entity.Vehiculo; 15 | import com.tallerMecanico.repository.IVehiculoRepository; 16 | 17 | @Service 18 | public class VehiculoService implements IVehiculoService{ 19 | 20 | @Autowired 21 | private IVehiculoRepository vehiculoRepository; 22 | 23 | // Consulta todos 24 | @Transactional(readOnly = true) 25 | public List findAll() { 26 | return (List) vehiculoRepository.findAll(Sort.by("idVehiculo")); 27 | } 28 | 29 | // consulta todos para paginación 30 | @Transactional(readOnly = true) 31 | public Page findAllPage(Pageable pageable) { 32 | return vehiculoRepository.findAll(pageable); 33 | } 34 | 35 | // consulta por id 36 | @Transactional(readOnly = true) 37 | public Vehiculo findById(Long idVehiculo) { 38 | return vehiculoRepository.findById(idVehiculo).orElse(null); 39 | } 40 | 41 | // Crear 42 | @Transactional 43 | public Vehiculo createVehiculo(VehiculoDto vehiculo) { 44 | Vehiculo vehiculoEntity = new Vehiculo(); 45 | vehiculoEntity.setVin(vehiculo.vin()); 46 | vehiculoEntity.setMatricula(vehiculo.matricula()); 47 | vehiculoEntity.setAnioModelo(vehiculo.anioModelo()); 48 | vehiculoEntity.setColor(vehiculo.color()); 49 | vehiculoEntity.setTipoMotor(vehiculo.tipoMotor()); 50 | vehiculoEntity.setImagen(vehiculo.imagen()); 51 | vehiculoEntity.setModelo(vehiculo.modelo()); 52 | vehiculoEntity.setOrdenServicio(vehiculo.ordenServicio()); 53 | vehiculoEntity.setCliente(vehiculo.cliente()); 54 | return vehiculoRepository.save(vehiculoEntity); 55 | } 56 | 57 | // Eliminar 58 | public Vehiculo deleteVehiculo(Long idVehiculo) { 59 | vehiculoRepository.deleteById(idVehiculo); 60 | return null; 61 | } 62 | 63 | // Modificar 64 | @Transactional 65 | public Vehiculo updateVehiculo(Long idVehiculo, VehiculoDto vehiculo) { 66 | Vehiculo vehiculoEntity = vehiculoRepository.findById(idVehiculo) 67 | .orElseThrow(() -> new NoSuchElementException("Vehiculo no encontrado con el ID: " + idVehiculo)); 68 | vehiculoEntity.setVin(vehiculo.vin()); 69 | vehiculoEntity.setMatricula(vehiculo.matricula()); 70 | vehiculoEntity.setAnioModelo(vehiculo.anioModelo()); 71 | vehiculoEntity.setColor(vehiculo.color()); 72 | vehiculoEntity.setTipoMotor(vehiculo.tipoMotor()); 73 | vehiculoEntity.setImagen(vehiculo.imagen()); 74 | vehiculoEntity.setModelo(vehiculo.modelo()); 75 | vehiculoEntity.setOrdenServicio(vehiculo.ordenServicio()); 76 | vehiculoEntity.setCliente(vehiculo.cliente()); 77 | return vehiculoRepository.save(vehiculoEntity); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/entity/Empleado.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.entity; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.GeneratedValue; 5 | import jakarta.persistence.GenerationType; 6 | import jakarta.persistence.Id; 7 | import jakarta.persistence.JoinColumn; 8 | import jakarta.persistence.OneToOne; 9 | import jakarta.persistence.Table; 10 | 11 | 12 | @Entity 13 | @Table(name = "empleados") 14 | public class Empleado { 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private long idEmpleado; 18 | private String nombre; 19 | private String apellidoPaterno; 20 | private String apellidoMaterno; 21 | private long nss; 22 | private String curp; 23 | private String rfc; 24 | private String puesto; 25 | private String observaciones; 26 | @OneToOne 27 | @JoinColumn(name = "usuario_id") 28 | private Usuario usuario; 29 | 30 | public Empleado() { 31 | super(); 32 | } 33 | 34 | public Empleado(long idEmpleado, String nombre, String apellidoPaterno, String apellidoMaterno, long nss, 35 | String curp, String rfc, String puesto, String observaciones, Usuario usuario) { 36 | super(); 37 | this.idEmpleado = idEmpleado; 38 | this.nombre = nombre; 39 | this.apellidoPaterno = apellidoPaterno; 40 | this.apellidoMaterno = apellidoMaterno; 41 | this.nss = nss; 42 | this.curp = curp; 43 | this.rfc = rfc; 44 | this.puesto = puesto; 45 | this.observaciones = observaciones; 46 | this.usuario = usuario; 47 | } 48 | 49 | public long getIdEmpleado() { 50 | return idEmpleado; 51 | } 52 | 53 | public void setIdEmpleado(long idEmpleado) { 54 | this.idEmpleado = idEmpleado; 55 | } 56 | 57 | public String getNombre() { 58 | return nombre; 59 | } 60 | 61 | public void setNombre(String nombre) { 62 | this.nombre = nombre; 63 | } 64 | 65 | public String getApellidoPaterno() { 66 | return apellidoPaterno; 67 | } 68 | 69 | public void setApellidoPaterno(String apellidoPaterno) { 70 | this.apellidoPaterno = apellidoPaterno; 71 | } 72 | 73 | public String getApellidoMaterno() { 74 | return apellidoMaterno; 75 | } 76 | 77 | public void setApellidoMaterno(String apellidoMaterno) { 78 | this.apellidoMaterno = apellidoMaterno; 79 | } 80 | 81 | public long getNss() { 82 | return nss; 83 | } 84 | 85 | public void setNss(long nss) { 86 | this.nss = nss; 87 | } 88 | 89 | public String getCurp() { 90 | return curp; 91 | } 92 | 93 | public void setCurp(String curp) { 94 | this.curp = curp; 95 | } 96 | 97 | public String getRfc() { 98 | return rfc; 99 | } 100 | 101 | public void setRfc(String rfc) { 102 | this.rfc = rfc; 103 | } 104 | 105 | public String getPuesto() { 106 | return puesto; 107 | } 108 | 109 | public void setPuesto(String puesto) { 110 | this.puesto = puesto; 111 | } 112 | 113 | public String getObservaciones() { 114 | return observaciones; 115 | } 116 | 117 | public void setObservaciones(String observaciones) { 118 | this.observaciones = observaciones; 119 | } 120 | 121 | public Usuario getUsuario() { 122 | return usuario; 123 | } 124 | 125 | public void setUsuario(Usuario usuario) { 126 | this.usuario = usuario; 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/entity/Cliente.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.entity; 2 | 3 | import java.util.List; 4 | 5 | import com.fasterxml.jackson.annotation.JsonManagedReference; 6 | 7 | import jakarta.persistence.CascadeType; 8 | import jakarta.persistence.Entity; 9 | import jakarta.persistence.GeneratedValue; 10 | import jakarta.persistence.GenerationType; 11 | import jakarta.persistence.Id; 12 | import jakarta.persistence.JoinColumn; 13 | import jakarta.persistence.OneToMany; 14 | import jakarta.persistence.OneToOne; 15 | import jakarta.persistence.Table; 16 | 17 | 18 | @Entity 19 | @Table(name = "clientes") 20 | public class Cliente { 21 | @Id 22 | @GeneratedValue(strategy = GenerationType.IDENTITY) 23 | private long idCliente; 24 | private String nombre; 25 | private String apellidoPaterno; 26 | private String apellidoMaterno; 27 | private String domicilio; 28 | private String telefono; 29 | @OneToOne 30 | @JoinColumn(name = "usuario_id") 31 | private Usuario usuario; 32 | @OneToMany(cascade = CascadeType.ALL) 33 | @JoinColumn(name = "clienteId") 34 | @JsonManagedReference 35 | private List vehiculos; 36 | 37 | 38 | public Cliente() { 39 | super(); 40 | } 41 | 42 | 43 | public Cliente(long idCliente, String nombre, String apellidoPaterno, String apellidoMaterno, String domicilio, 44 | String telefono, Usuario usuario, List vehiculos) { 45 | super(); 46 | this.idCliente = idCliente; 47 | this.nombre = nombre; 48 | this.apellidoPaterno = apellidoPaterno; 49 | this.apellidoMaterno = apellidoMaterno; 50 | this.domicilio = domicilio; 51 | this.telefono = telefono; 52 | this.usuario = usuario; 53 | this.vehiculos = vehiculos; 54 | } 55 | 56 | 57 | public long getIdCliente() { 58 | return idCliente; 59 | } 60 | 61 | 62 | public void setIdCliente(long idCliente) { 63 | this.idCliente = idCliente; 64 | } 65 | 66 | 67 | public String getNombre() { 68 | return nombre; 69 | } 70 | 71 | 72 | public void setNombre(String nombre) { 73 | this.nombre = nombre; 74 | } 75 | 76 | 77 | public String getApellidoPaterno() { 78 | return apellidoPaterno; 79 | } 80 | 81 | 82 | public void setApellidoPaterno(String apellidoPaterno) { 83 | this.apellidoPaterno = apellidoPaterno; 84 | } 85 | 86 | 87 | public String getApellidoMaterno() { 88 | return apellidoMaterno; 89 | } 90 | 91 | 92 | public void setApellidoMaterno(String apellidoMaterno) { 93 | this.apellidoMaterno = apellidoMaterno; 94 | } 95 | 96 | 97 | public String getDomicilio() { 98 | return domicilio; 99 | } 100 | 101 | 102 | public void setDomicilio(String domicilio) { 103 | this.domicilio = domicilio; 104 | } 105 | 106 | 107 | public String getTelefono() { 108 | return telefono; 109 | } 110 | 111 | 112 | public void setTelefono(String telefono) { 113 | this.telefono = telefono; 114 | } 115 | 116 | 117 | public Usuario getUsuario() { 118 | return usuario; 119 | } 120 | 121 | 122 | public void setUsuario(Usuario usuario) { 123 | this.usuario = usuario; 124 | } 125 | 126 | 127 | public List getVehiculos() { 128 | return vehiculos; 129 | } 130 | 131 | 132 | public void setVehiculos(List vehiculos) { 133 | this.vehiculos = vehiculos; 134 | } 135 | 136 | 137 | } 138 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/OrdenServicioService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | import java.util.NoSuchElementException; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.domain.Pageable; 9 | import org.springframework.data.domain.Sort; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import com.tallerMecanico.dto.OrdenServicioDto; 14 | import com.tallerMecanico.entity.OrdenServicio; 15 | import com.tallerMecanico.repository.IOrdenServicioRepository; 16 | 17 | @Service 18 | public class OrdenServicioService implements IOrdenServicioService { 19 | 20 | @Autowired 21 | private IOrdenServicioRepository ordenServicioRepository; 22 | 23 | // Consulta todos 24 | @Transactional(readOnly = true) 25 | public List findAll() { 26 | return (List) ordenServicioRepository.findAll(Sort.by("idOrdenServicio")); 27 | } 28 | 29 | // consulta todos para paginación 30 | @Transactional(readOnly = true) 31 | public Page findAllPage(Pageable pageable) { 32 | return ordenServicioRepository.findAll(pageable); 33 | } 34 | 35 | // consulta por id 36 | @Transactional(readOnly = true) 37 | public OrdenServicio findById(Long idOrdenServicio) { 38 | return ordenServicioRepository.findById(idOrdenServicio).orElse(null); 39 | } 40 | 41 | // Crear 42 | @Transactional 43 | public OrdenServicio createOrdenServicio(OrdenServicioDto ordenServicio) { 44 | OrdenServicio ordenServicioEntity = new OrdenServicio(); 45 | ordenServicioEntity.setFechaOrden(ordenServicio.fechaOrden()); 46 | ordenServicioEntity.setFalla(ordenServicio.falla()); 47 | ordenServicioEntity.setKilometraje(ordenServicio.kilometraje()); 48 | ordenServicioEntity.setObservaciones(ordenServicio.observaciones()); 49 | ordenServicioEntity.setEstatusServicio(ordenServicio.estatusServicio()); 50 | ordenServicioEntity.setFactura(ordenServicio.factura()); 51 | ordenServicioEntity.setVehiculo(ordenServicio.vehiculo()); 52 | ordenServicioEntity.setComentarios(ordenServicio.comentarios()); 53 | ordenServicioEntity.setEmpleado(ordenServicio.empleado()); 54 | return ordenServicioRepository.save(ordenServicioEntity); 55 | } 56 | 57 | // Eliminar 58 | public OrdenServicio deleteOrdenServicio(Long idOrdenServicio) { 59 | ordenServicioRepository.deleteById(idOrdenServicio); 60 | return null; 61 | } 62 | 63 | // Modificar 64 | @Transactional 65 | public OrdenServicio updateOrdenServicio(Long idOrdenServicio, OrdenServicioDto ordenServicio) { 66 | OrdenServicio ordenServicioEntity = ordenServicioRepository.findById(idOrdenServicio) 67 | .orElseThrow(() -> new NoSuchElementException("Orden de Servicio no encontrada con el ID: " + idOrdenServicio)); 68 | ordenServicioEntity.setFechaOrden(ordenServicio.fechaOrden()); 69 | ordenServicioEntity.setFalla(ordenServicio.falla()); 70 | ordenServicioEntity.setKilometraje(ordenServicio.kilometraje()); 71 | ordenServicioEntity.setObservaciones(ordenServicio.observaciones()); 72 | ordenServicioEntity.setEstatusServicio(ordenServicio.estatusServicio()); 73 | ordenServicioEntity.setVehiculo(ordenServicio.vehiculo()); 74 | ordenServicioEntity.setComentarios(ordenServicio.comentarios()); 75 | ordenServicioEntity.setEmpleado(ordenServicio.empleado()); 76 | return ordenServicioRepository.save(ordenServicioEntity); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/entity/Vehiculo.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.entity; 2 | 3 | import java.util.List; 4 | 5 | import com.fasterxml.jackson.annotation.JsonBackReference; 6 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 7 | 8 | import jakarta.persistence.CascadeType; 9 | import jakarta.persistence.Entity; 10 | import jakarta.persistence.FetchType; 11 | import jakarta.persistence.GeneratedValue; 12 | import jakarta.persistence.GenerationType; 13 | import jakarta.persistence.Id; 14 | import jakarta.persistence.JoinColumn; 15 | import jakarta.persistence.ManyToOne; 16 | import jakarta.persistence.OneToMany; 17 | import jakarta.persistence.Table; 18 | 19 | @Entity 20 | @Table(name = "vehiculos") 21 | public class Vehiculo { 22 | @Id 23 | @GeneratedValue(strategy = GenerationType.IDENTITY) 24 | private long idVehiculo; 25 | private String vin; 26 | private String matricula; 27 | @ManyToOne(fetch = FetchType.LAZY) 28 | @JoinColumn(name = "modeloId") 29 | @JsonIgnoreProperties({"hibernateLazyInitializer","handler"}) 30 | private Modelo modelo; 31 | private int anioModelo; 32 | private String color; 33 | @ManyToOne(fetch = FetchType.EAGER) 34 | @JoinColumn(name = "tipoMotorId") 35 | private TipoMotor tipoMotor; 36 | private String imagen; 37 | @ManyToOne 38 | @JoinColumn(name = "clienteId") 39 | @JsonBackReference 40 | private Cliente cliente; 41 | @OneToMany(cascade = CascadeType.ALL) 42 | @JoinColumn(name = "vehiculoId") 43 | //@JsonManagedReference 44 | private List ordenServicio; 45 | 46 | public Vehiculo() { 47 | super(); 48 | } 49 | 50 | public Vehiculo(long idVehiculo, String vin, String matricula, Modelo modelo, int anioModelo, String color, 51 | TipoMotor tipoMotor, String imagen, Cliente cliente, List ordenServicio) { 52 | super(); 53 | this.idVehiculo = idVehiculo; 54 | this.vin = vin; 55 | this.matricula = matricula; 56 | this.modelo = modelo; 57 | this.anioModelo = anioModelo; 58 | this.color = color; 59 | this.tipoMotor = tipoMotor; 60 | this.imagen = imagen; 61 | this.cliente = cliente; 62 | this.ordenServicio = ordenServicio; 63 | } 64 | 65 | public long getIdVehiculo() { 66 | return idVehiculo; 67 | } 68 | 69 | public void setIdVehiculo(long idVehiculo) { 70 | this.idVehiculo = idVehiculo; 71 | } 72 | 73 | public String getVin() { 74 | return vin; 75 | } 76 | 77 | public void setVin(String vin) { 78 | this.vin = vin; 79 | } 80 | 81 | public String getMatricula() { 82 | return matricula; 83 | } 84 | 85 | public void setMatricula(String matricula) { 86 | this.matricula = matricula; 87 | } 88 | 89 | public Modelo getModelo() { 90 | return modelo; 91 | } 92 | 93 | public void setModelo(Modelo modelo) { 94 | this.modelo = modelo; 95 | } 96 | 97 | public int getAnioModelo() { 98 | return anioModelo; 99 | } 100 | 101 | public void setAnioModelo(int anioModelo) { 102 | this.anioModelo = anioModelo; 103 | } 104 | 105 | public String getColor() { 106 | return color; 107 | } 108 | 109 | public void setColor(String color) { 110 | this.color = color; 111 | } 112 | 113 | public TipoMotor getTipoMotor() { 114 | return tipoMotor; 115 | } 116 | 117 | public void setTipoMotor(TipoMotor tipoMotor) { 118 | this.tipoMotor = tipoMotor; 119 | } 120 | 121 | public String getImagen() { 122 | return imagen; 123 | } 124 | 125 | public void setImagen(String imagen) { 126 | this.imagen = imagen; 127 | } 128 | 129 | public Cliente getCliente() { 130 | return cliente; 131 | } 132 | 133 | public void setCliente(Cliente cliente) { 134 | this.cliente = cliente; 135 | } 136 | 137 | public List getOrdenServicio() { 138 | return ordenServicio; 139 | } 140 | 141 | public void setOrdenServicio(List ordenServicio) { 142 | this.ordenServicio = ordenServicio; 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/UsuarioService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | import java.util.NoSuchElementException; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.data.domain.Page; 9 | import org.springframework.data.domain.Pageable; 10 | import org.springframework.data.domain.Sort; 11 | import org.springframework.http.HttpStatus; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.stereotype.Service; 14 | import org.springframework.transaction.annotation.Transactional; 15 | 16 | import com.tallerMecanico.dto.RegistroResponseDto; 17 | import com.tallerMecanico.dto.UsuarioDto; 18 | import com.tallerMecanico.entity.Rol; 19 | import com.tallerMecanico.entity.Usuario; 20 | import com.tallerMecanico.repository.IRolRepository; 21 | import com.tallerMecanico.repository.IUsuarioRepository; 22 | 23 | 24 | @Service 25 | public class UsuarioService implements IUsuarioService { 26 | 27 | @Autowired 28 | private IUsuarioRepository usuarioRepository; 29 | private IRolRepository rolRepository; 30 | 31 | @Autowired 32 | public UsuarioService(IUsuarioRepository usuarioRepository, IRolRepository rolRepository) { 33 | this.usuarioRepository = usuarioRepository; 34 | this.rolRepository = rolRepository; 35 | } 36 | 37 | // Consulta todos 38 | @Transactional(readOnly = true) 39 | public List findAll() { 40 | return (List) usuarioRepository.findAll(Sort.by("idUsuario")); 41 | } 42 | 43 | // consulta todos para paginación 44 | @Transactional(readOnly = true) 45 | public Page findAllPage(Pageable pageable) { 46 | return usuarioRepository.findAll(pageable); 47 | } 48 | 49 | // consulta por id 50 | @Transactional(readOnly = true) 51 | public Usuario findById(Long idUsuario) { 52 | return usuarioRepository.findById(idUsuario).orElse(null); 53 | } 54 | 55 | /* 56 | // Crear 57 | @Transactional 58 | public Usuario createUsuario(UsuarioDto usuario) { 59 | Usuario usuarioEntity = new Usuario(); 60 | usuarioEntity.setIdUsuario(usuario.idUsuario()); 61 | usuarioEntity.setEmail(usuario.email()); 62 | usuarioEntity.setPassword(usuario.password()); 63 | return usuarioRepository.save(usuarioEntity); 64 | } 65 | */ 66 | // register 67 | public ResponseEntity registrarUsuario(UsuarioDto dtoRegistro, String role) { 68 | if (usuarioRepository.existsByEmail(dtoRegistro.email())) { 69 | return new ResponseEntity<>(new RegistroResponseDto("El usuario ya existe, intenta con otro", null), HttpStatus.BAD_REQUEST); 70 | } 71 | 72 | Usuario usuario = new Usuario(); 73 | usuario.setEmail(dtoRegistro.email()); 74 | usuario.setPassword(dtoRegistro.password()); 75 | 76 | Rol rol = rolRepository.findByNombre(role).orElse(null); 77 | 78 | if (rol == null) { 79 | return new ResponseEntity<>(new RegistroResponseDto("Rol no válido", null), HttpStatus.BAD_REQUEST); 80 | } 81 | 82 | usuario.setRol(Collections.singletonList(rol)); 83 | usuarioRepository.save(usuario); 84 | 85 | // Obtener el usuario recién creado con ID generado 86 | Usuario usuarioGuardado = usuarioRepository.findByEmail(dtoRegistro.email()); 87 | 88 | if (usuarioGuardado != null) { 89 | RegistroResponseDto responseDto = new RegistroResponseDto("Registro exitoso", usuarioGuardado.getIdUsuario()); 90 | return new ResponseEntity<>(responseDto, HttpStatus.OK); 91 | } else { 92 | return new ResponseEntity<>(new RegistroResponseDto("Error al obtener el ID del usuario", null), HttpStatus.INTERNAL_SERVER_ERROR); 93 | } 94 | } 95 | 96 | // Eliminar 97 | public Usuario deleteUsuario(Long idUsuario) { 98 | usuarioRepository.deleteById(idUsuario); 99 | return null; 100 | } 101 | 102 | // Modificar 103 | @Transactional 104 | public Usuario updateUsuario(Long idUsuario, UsuarioDto usuario) { 105 | Usuario usuarioEntity = usuarioRepository.findById(idUsuario) 106 | .orElseThrow(() -> new NoSuchElementException("Usuario no encontrado con el ID: " + idUsuario)); 107 | usuarioEntity.setIdUsuario(usuario.idUsuario()); 108 | usuarioEntity.setEmail(usuario.email()); 109 | usuarioEntity.setPassword(usuario.password()); 110 | return usuarioRepository.save(usuarioEntity); 111 | } 112 | 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/ClienteService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | import java.util.NoSuchElementException; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.domain.Pageable; 9 | import org.springframework.data.domain.Sort; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import com.tallerMecanico.dto.ClienteDto; 14 | import com.tallerMecanico.entity.Cliente; 15 | import com.tallerMecanico.entity.Usuario; 16 | import com.tallerMecanico.repository.IClienteRepository; 17 | import com.tallerMecanico.repository.IUsuarioRepository; 18 | 19 | @Service 20 | public class ClienteService implements IClienteService { 21 | 22 | @Autowired 23 | private IClienteRepository clienteRepository; 24 | 25 | @Autowired 26 | private IUsuarioRepository usuarioRepository; 27 | 28 | // Consulta todos 29 | @Transactional(readOnly = true) 30 | public List findAll() { 31 | return (List) clienteRepository.findAll(Sort.by("idCliente")); 32 | } 33 | 34 | // consulta todos para paginación 35 | @Transactional(readOnly = true) 36 | public Page findAllPage(Pageable pageable) { 37 | return clienteRepository.findAll(pageable); 38 | } 39 | 40 | // consulta por id 41 | @Transactional(readOnly = true) 42 | public Cliente findById(Long idCliente) { 43 | return clienteRepository.findById(idCliente).orElse(null); 44 | } 45 | 46 | // Crear 47 | @Transactional 48 | public Cliente createCliente(ClienteDto cliente, Long idUsuario) { 49 | Cliente clienteEntity = new Cliente(); 50 | clienteEntity.setNombre(cliente.nombre()); 51 | clienteEntity.setApellidoPaterno(cliente.apellidoPaterno()); 52 | clienteEntity.setApellidoMaterno(cliente.apellidoMaterno()); 53 | clienteEntity.setDomicilio(cliente.domicilio()); 54 | clienteEntity.setTelefono(cliente.telefono()); 55 | 56 | // Asignar el idUsuario al cliente 57 | Usuario usuario = new Usuario(); // Debes cargar el usuario del repositorio utilizando su id, o bien asegurarte 58 | // de que el clienteDto contenga la información completa del usuario 59 | usuario.setIdUsuario(idUsuario); 60 | clienteEntity.setUsuario(usuario); 61 | 62 | clienteEntity.setVehiculos(cliente.vehiculos()); 63 | 64 | return clienteRepository.save(clienteEntity); 65 | } 66 | 67 | // Eliminar 68 | /* 69 | * public Cliente deleteCliente(Long idCliente) { 70 | * clienteRepository.deleteById(idCliente); return null; } 71 | */ 72 | 73 | // Eliminar Cliente y usuario 74 | @Transactional 75 | public Cliente deleteCliente(Long idCliente) { 76 | // Buscar el cliente por su ID 77 | Cliente cliente = clienteRepository.findById(idCliente).orElse(null); 78 | if (cliente == null) { 79 | // Si el cliente no existe, retornar o manejar el caso según corresponda 80 | return cliente; 81 | } 82 | 83 | // Obtener el usuario asociado al cliente 84 | Usuario usuario = cliente.getUsuario(); 85 | if (usuario != null) { 86 | // Eliminar los roles asignados al usuario 87 | usuario.getRol().clear(); // Eliminar todos los roles asignados al usuario 88 | // Guardar el usuario para que se actualicen las relaciones 89 | usuarioRepository.save(usuario); 90 | // Eliminar el usuario 91 | usuarioRepository.delete(usuario); 92 | } 93 | 94 | // Ahora se puede eliminar el cliente 95 | clienteRepository.delete(cliente); 96 | return cliente; 97 | } 98 | 99 | // Modificar 100 | @Transactional 101 | public Cliente updateCliente(Long idCliente, ClienteDto cliente) { 102 | Cliente clienteEntity = clienteRepository.findById(idCliente) 103 | .orElseThrow(() -> new NoSuchElementException("Cliente no encontrado con el ID: " + idCliente)); 104 | clienteEntity.setNombre(cliente.nombre()); 105 | clienteEntity.setApellidoPaterno(cliente.apellidoPaterno()); 106 | clienteEntity.setApellidoMaterno(cliente.apellidoMaterno()); 107 | clienteEntity.setDomicilio(cliente.domicilio()); 108 | clienteEntity.setTelefono(cliente.telefono()); 109 | clienteEntity.setVehiculos(cliente.vehiculos()); 110 | return clienteRepository.save(clienteEntity); 111 | } 112 | 113 | 114 | public List buscarClientesPorNombreApellidoPaternoApellidoMaternoTelefono(String searchTerm) { 115 | return clienteRepository.findByNombreApellidoPaternoApellidoMaternoTelefonoLike(searchTerm); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/service/EmpleadoService.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.service; 2 | 3 | import java.util.List; 4 | import java.util.NoSuchElementException; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.domain.Pageable; 9 | import org.springframework.data.domain.Sort; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import com.tallerMecanico.dto.EmpleadoDto; 14 | import com.tallerMecanico.entity.Empleado; 15 | import com.tallerMecanico.entity.Usuario; 16 | import com.tallerMecanico.repository.IEmpleadoRepository; 17 | import com.tallerMecanico.repository.IUsuarioRepository; 18 | 19 | @Service 20 | public class EmpleadoService implements IEmpleadoService { 21 | 22 | @Autowired 23 | private IEmpleadoRepository empleadoRepository; 24 | 25 | @Autowired 26 | private IUsuarioRepository usuarioRepository; 27 | 28 | // Consulta todos 29 | @Transactional(readOnly = true) 30 | public List findAll() { 31 | return (List) empleadoRepository.findAll(Sort.by("idEmpleado")); 32 | } 33 | 34 | // consulta todos para paginación 35 | @Transactional(readOnly = true) 36 | public Page findAllPage(Pageable pageable) { 37 | return empleadoRepository.findAll(pageable); 38 | } 39 | 40 | // consulta por id 41 | @Transactional(readOnly = true) 42 | public Empleado findById(Long idEmpleado) { 43 | return empleadoRepository.findById(idEmpleado).orElse(null); 44 | } 45 | 46 | // Crear 47 | @Transactional 48 | public Empleado createEmpleado(EmpleadoDto empleado, Long idUsuario) { 49 | Empleado empleadoEntity = new Empleado(); 50 | empleadoEntity.setNombre(empleado.nombre()); 51 | empleadoEntity.setApellidoPaterno(empleado.apellidoPaterno()); 52 | empleadoEntity.setApellidoMaterno(empleado.apellidoMaterno()); 53 | empleadoEntity.setNss(empleado.nss()); 54 | empleadoEntity.setCurp(empleado.curp()); 55 | empleadoEntity.setRfc(empleado.rfc()); 56 | empleadoEntity.setPuesto(empleado.puesto()); 57 | empleadoEntity.setObservaciones(empleado.observaciones()); 58 | 59 | // Asignar el idUsuario al empleado 60 | Usuario usuario = new Usuario(); // Debes cargar el usuario del repositorio utilizando su id, o bien asegurarte 61 | // de que el clienteDto contenga la información completa del usuario 62 | usuario.setIdUsuario(idUsuario); 63 | empleadoEntity.setUsuario(usuario); 64 | 65 | return empleadoRepository.save(empleadoEntity); 66 | } 67 | 68 | // Eliminar 69 | /* 70 | * public Empleado deleteEmpleado(Long idEmpleado) { 71 | * empleadoRepository.deleteById(idEmpleado); return null; } 72 | */ 73 | 74 | // Eliminar Empleado y usuario 75 | @Transactional 76 | public Empleado deleteEmpleado(Long idEmpleado) { 77 | // Buscar el empleado por su ID 78 | Empleado empleado = empleadoRepository.findById(idEmpleado).orElse(null); 79 | if (empleado == null) { 80 | // Si el empelado no existe, retornar o manejar el caso según corresponda 81 | return empleado; 82 | } 83 | 84 | // Obtener el usuario asociado al cliente 85 | Usuario usuario = empleado.getUsuario(); 86 | if (usuario != null) { 87 | // Eliminar los roles asignados al usuario 88 | usuario.getRol().clear(); // Eliminar todos los roles asignados al usuario 89 | // Guardar el usuario para que se actualicen las relaciones 90 | usuarioRepository.save(usuario); 91 | // Eliminar el usuario 92 | usuarioRepository.delete(usuario); 93 | } 94 | 95 | // Ahora se puede eliminar el empleado 96 | empleadoRepository.delete(empleado); 97 | return empleado; 98 | } 99 | 100 | 101 | // Modificar 102 | @Transactional 103 | public Empleado updateEmpleado(Long idEmpleado, EmpleadoDto empleado) { 104 | Empleado empleadoEntity = empleadoRepository.findById(idEmpleado) 105 | .orElseThrow(() -> new NoSuchElementException("Empleado no encontrado con el ID: " + idEmpleado)); 106 | empleadoEntity.setNombre(empleado.nombre()); 107 | empleadoEntity.setApellidoPaterno(empleado.apellidoPaterno()); 108 | empleadoEntity.setApellidoMaterno(empleado.apellidoMaterno()); 109 | empleadoEntity.setNss(empleado.nss()); 110 | empleadoEntity.setCurp(empleado.curp()); 111 | empleadoEntity.setRfc(empleado.rfc()); 112 | empleadoEntity.setPuesto(empleado.puesto()); 113 | empleadoEntity.setObservaciones(empleado.observaciones()); 114 | return empleadoRepository.save(empleadoEntity); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/entity/OrdenServicio.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.entity; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.Date; 6 | import java.util.List; 7 | 8 | import com.fasterxml.jackson.annotation.JsonIdentityInfo; 9 | import com.fasterxml.jackson.annotation.ObjectIdGenerators; 10 | 11 | import jakarta.persistence.CascadeType; 12 | import jakarta.persistence.Column; 13 | import jakarta.persistence.Entity; 14 | 15 | import jakarta.persistence.FetchType; 16 | import jakarta.persistence.GeneratedValue; 17 | import jakarta.persistence.GenerationType; 18 | import jakarta.persistence.Id; 19 | import jakarta.persistence.JoinColumn; 20 | import jakarta.persistence.ManyToOne; 21 | import jakarta.persistence.OneToMany; 22 | import jakarta.persistence.OneToOne; 23 | import jakarta.persistence.Table; 24 | 25 | 26 | @Entity 27 | @Table(name = "ordenesServicios") 28 | @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "idOrdenServicio") 29 | public class OrdenServicio { 30 | @Id 31 | @GeneratedValue(strategy = GenerationType.IDENTITY) 32 | private long idOrdenServicio; 33 | private Date fechaOrden; 34 | private String falla; 35 | private String kilometraje; 36 | private String observaciones; 37 | @ManyToOne(fetch = FetchType.EAGER) 38 | @JoinColumn(name = "estatusServicioId") 39 | private EstatusServicio estatusServicio; 40 | @OneToOne(mappedBy = "ordenServicio") 41 | private Factura factura; 42 | 43 | @ManyToOne(cascade = CascadeType.MERGE) 44 | @JoinColumn(name = "vehiculoId") 45 | //@JsonBackReference 46 | private Vehiculo vehiculo; 47 | 48 | @OneToMany(mappedBy = "ordenServicio", cascade = CascadeType.ALL, orphanRemoval = true) 49 | private List detalleOrdenServicios = new ArrayList<>(); 50 | @Column(columnDefinition = "TEXT") // tipo text 51 | private String comentarios; 52 | 53 | @ManyToOne(cascade = CascadeType.MERGE) 54 | @JoinColumn(name = "empleadoId") 55 | private Empleado empleado; 56 | 57 | public OrdenServicio() { 58 | super(); 59 | } 60 | 61 | public OrdenServicio(long idOrdenServicio, Date fechaOrden, String falla, String kilometraje, String observaciones, 62 | EstatusServicio estatusServicio, Factura factura, Vehiculo vehiculo, 63 | List detalleOrdenServicios, String comentarios, Empleado empleado) { 64 | super(); 65 | this.idOrdenServicio = idOrdenServicio; 66 | this.fechaOrden = fechaOrden; 67 | this.falla = falla; 68 | this.kilometraje = kilometraje; 69 | this.observaciones = observaciones; 70 | this.estatusServicio = estatusServicio; 71 | this.factura = factura; 72 | this.vehiculo = vehiculo; 73 | this.detalleOrdenServicios = detalleOrdenServicios; 74 | this.comentarios = comentarios; 75 | this.empleado = empleado; 76 | } 77 | 78 | public long getIdOrdenServicio() { 79 | return idOrdenServicio; 80 | } 81 | 82 | public void setIdOrdenServicio(long idOrdenServicio) { 83 | this.idOrdenServicio = idOrdenServicio; 84 | } 85 | 86 | public Date getFechaOrden() { 87 | return fechaOrden; 88 | } 89 | 90 | public void setFechaOrden(Date fechaOrden) { 91 | this.fechaOrden = fechaOrden; 92 | } 93 | 94 | public String getFalla() { 95 | return falla; 96 | } 97 | 98 | public void setFalla(String falla) { 99 | this.falla = falla; 100 | } 101 | 102 | public String getKilometraje() { 103 | return kilometraje; 104 | } 105 | 106 | public void setKilometraje(String kilometraje) { 107 | this.kilometraje = kilometraje; 108 | } 109 | 110 | public String getObservaciones() { 111 | return observaciones; 112 | } 113 | 114 | public void setObservaciones(String observaciones) { 115 | this.observaciones = observaciones; 116 | } 117 | 118 | public EstatusServicio getEstatusServicio() { 119 | return estatusServicio; 120 | } 121 | 122 | public void setEstatusServicio(EstatusServicio estatusServicio) { 123 | this.estatusServicio = estatusServicio; 124 | } 125 | 126 | public Factura getFactura() { 127 | return factura; 128 | } 129 | 130 | public void setFactura(Factura factura) { 131 | this.factura = factura; 132 | } 133 | 134 | public Vehiculo getVehiculo() { 135 | return vehiculo; 136 | } 137 | 138 | public void setVehiculo(Vehiculo vehiculo) { 139 | this.vehiculo = vehiculo; 140 | } 141 | 142 | public List getDetalleOrdenServicios() { 143 | return detalleOrdenServicios; 144 | } 145 | 146 | public void setDetalleOrdenServicios(List detalleOrdenServicios) { 147 | this.detalleOrdenServicios = detalleOrdenServicios; 148 | } 149 | 150 | public String getComentarios() { 151 | return comentarios; 152 | } 153 | 154 | public void setComentarios(String comentarios) { 155 | this.comentarios = comentarios; 156 | } 157 | 158 | public Empleado getEmpleado() { 159 | return empleado; 160 | } 161 | 162 | public void setEmpleado(Empleado empleado) { 163 | this.empleado = empleado; 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/TallerMecanicoApplication.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.sql.Connection; 8 | import java.sql.SQLException; 9 | 10 | import javax.sql.DataSource; 11 | 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.ApplicationArguments; 14 | import org.springframework.boot.ApplicationRunner; 15 | import org.springframework.boot.SpringApplication; 16 | import org.springframework.boot.autoconfigure.SpringBootApplication; 17 | import org.springframework.core.io.Resource; 18 | import org.springframework.core.io.ResourceLoader; 19 | import org.springframework.jdbc.core.JdbcTemplate; 20 | 21 | 22 | @SpringBootApplication 23 | public class TallerMecanicoApplication implements ApplicationRunner{ 24 | 25 | 26 | private final DataSource dataSource; 27 | private final JdbcTemplate jdbcTemplate; 28 | 29 | 30 | @Autowired 31 | public TallerMecanicoApplication(DataSource dataSource, JdbcTemplate jdbcTemplate) { 32 | this.dataSource = dataSource; 33 | this.jdbcTemplate = jdbcTemplate; 34 | } 35 | 36 | @Autowired 37 | private ResourceLoader resourceLoader; 38 | 39 | public static void main(String[] args) { 40 | SpringApplication.run(TallerMecanicoApplication.class, args); 41 | } 42 | 43 | @Override 44 | public void run(ApplicationArguments args) throws Exception { 45 | // Ejecutar el script SQL 46 | executeSqlScript("data.sql"); 47 | loadCsvDataToMarcaTable("marcaAutos.csv"); 48 | loadCsvDataToModeloTable("modelosAutos.csv"); 49 | executeSqlScript("data2.sql"); 50 | 51 | } 52 | 53 | 54 | 55 | private void executeSqlScript(String scriptFileName) throws SQLException { 56 | try (Connection connection = dataSource.getConnection()) { 57 | // Leer el script SQL desde el archivo 58 | BufferedReader reader = new BufferedReader( 59 | new InputStreamReader(getClass().getClassLoader().getResourceAsStream(scriptFileName))); 60 | StringBuilder scriptContent = new StringBuilder(); 61 | String line; 62 | while ((line = reader.readLine()) != null) { 63 | scriptContent.append(line).append("\n"); 64 | } 65 | // Ejecutar el script SQL 66 | jdbcTemplate.execute(scriptContent.toString()); 67 | } catch (IOException e) { 68 | throw new RuntimeException("Error al leer el archivo " + scriptFileName, e); 69 | } 70 | } 71 | 72 | // Carga tabla de marcas por medio de archivo CSV 73 | private void loadCsvDataToMarcaTable(String csvFileName) throws SQLException { 74 | try { 75 | Resource resource = resourceLoader.getResource("classpath:" + csvFileName); 76 | InputStream inputStream = resource.getInputStream(); 77 | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); 78 | 79 | // Omitir la primera línea que contiene los encabezados 80 | String line = reader.readLine(); // Leer la primera línea y descartarla 81 | 82 | while ((line = reader.readLine()) != null) { 83 | String[] data = line.split(","); 84 | if (data.length == 2) { 85 | long idMarca = Long.parseLong(data[0].trim()); 86 | String marca = data[1].trim(); 87 | 88 | // Verificar si el registro ya existe en la tabla 89 | String searchQuery = "SELECT COUNT(*) FROM marcas WHERE id_marca = " + idMarca; 90 | int count = jdbcTemplate.queryForObject(searchQuery, Integer.class); 91 | 92 | // Si no existe, insertar el registro en la tabla 93 | if (count == 0) { 94 | String insertQuery = "INSERT INTO marcas (id_marca, marca) VALUES (" + idMarca + ", '" + marca 95 | + "')"; 96 | jdbcTemplate.update(insertQuery); 97 | } 98 | } 99 | } 100 | 101 | reader.close(); 102 | } catch (IOException e) { 103 | throw new RuntimeException("Error al cargar datos desde el archivo CSV a la tabla 'marcas'", e); 104 | } 105 | } 106 | 107 | // Carga tabla de modelos por medio de archivo CSV 108 | private void loadCsvDataToModeloTable(String csvFileName) throws SQLException { 109 | try { 110 | Resource resource = resourceLoader.getResource("classpath:" + csvFileName); 111 | InputStream inputStream = resource.getInputStream(); 112 | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); 113 | 114 | // Omitir la primera línea que contiene los encabezados 115 | String line = reader.readLine(); // Leer la primera línea y descartarla 116 | 117 | while ((line = reader.readLine()) != null) { 118 | String[] data = line.split(","); 119 | if (data.length == 3) { // Asegurarse que hay 3 elementos 120 | long idModelo = Long.parseLong(data[0].trim()); 121 | long marcaId = Long.parseLong(data[1].trim()); // Verificar que este sea el índice correcto 122 | String modelo = data[2].trim(); 123 | 124 | // Verificar si el registro ya existe en la tabla 125 | String searchQuery = "SELECT COUNT(*) FROM modelos WHERE id_modelo = " + idModelo; 126 | int count = jdbcTemplate.queryForObject(searchQuery, Integer.class); 127 | 128 | // Si no existe, insertar el registro en la tabla 129 | if (count == 0) { 130 | String insertQuery = "INSERT INTO modelos (id_modelo, marca_id, modelo) VALUES (" + idModelo 131 | + ", " + marcaId + ", '" + modelo + "')"; 132 | jdbcTemplate.update(insertQuery); 133 | } 134 | } 135 | } 136 | 137 | reader.close(); 138 | } catch (IOException e) { 139 | throw new RuntimeException("Error al cargar datos desde el archivo CSV a la tabla 'modelos'", e); 140 | } 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/controller/RolController.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.dao.DataAccessException; 9 | import org.springframework.data.domain.Page; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.data.domain.Pageable; 12 | import org.springframework.data.domain.Sort; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.web.bind.annotation.CrossOrigin; 16 | import org.springframework.web.bind.annotation.DeleteMapping; 17 | import org.springframework.web.bind.annotation.GetMapping; 18 | import org.springframework.web.bind.annotation.PathVariable; 19 | import org.springframework.web.bind.annotation.PostMapping; 20 | import org.springframework.web.bind.annotation.PutMapping; 21 | import org.springframework.web.bind.annotation.RequestBody; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RequestMethod; 24 | import org.springframework.web.bind.annotation.ResponseStatus; 25 | import org.springframework.web.bind.annotation.RestController; 26 | 27 | import com.tallerMecanico.dto.RolDto; 28 | import com.tallerMecanico.entity.Rol; 29 | import com.tallerMecanico.service.RolService; 30 | 31 | @RestController 32 | @CrossOrigin(origins = "http://localhost:4200", methods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, 33 | RequestMethod.DELETE }) 34 | @RequestMapping("/api") 35 | public class RolController { 36 | 37 | @Autowired 38 | private RolService rolService; 39 | 40 | // Consulta todos 41 | @GetMapping("/roles") 42 | @ResponseStatus(HttpStatus.OK) 43 | public List consulta() { 44 | return rolService.findAll(); 45 | } 46 | 47 | // Consulta paginación 48 | @GetMapping("/roles/page/{page}") 49 | public Page consultaPage(@PathVariable Integer page) { 50 | Pageable pageable = PageRequest.of(page, 10, Sort.by("idRol").ascending()); 51 | return rolService.findAllPage(pageable); 52 | } 53 | 54 | // Consulta por id 55 | @GetMapping("/roles/{id}") 56 | public ResponseEntity consultaPorID(@PathVariable Long id) { 57 | 58 | Rol rol = null; 59 | String response = ""; 60 | try { 61 | rol = rolService.findById(id); 62 | } catch (DataAccessException e) { 63 | response = "Error al realizar la consulta."; 64 | response = response.concat(e.getMessage().concat(e.getMostSpecificCause().toString())); 65 | return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); 66 | } 67 | 68 | if (rol == null) { 69 | response = "El Rol con el ID: ".concat(id.toString()).concat(" no existe en la base de datos"); 70 | return new ResponseEntity(response, HttpStatus.NOT_FOUND); 71 | } 72 | return new ResponseEntity(rol, HttpStatus.OK); 73 | } 74 | 75 | // Eliminar por id 76 | @DeleteMapping("/roles/{id}") 77 | public ResponseEntity delete(@PathVariable Long id) { 78 | 79 | Map response = new HashMap<>(); 80 | 81 | try { 82 | Rol rolDelete = this.rolService.findById(id); 83 | if (rolDelete == null) { 84 | response.put("mensaje", "Error al eliminar. La marca no existe en base de datos"); 85 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 86 | } 87 | 88 | rolService.deleteRol(id); 89 | } catch (DataAccessException e) { 90 | response.put("mensaje", "Error al eliminar en base de datos"); 91 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 92 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 93 | } 94 | response.put("mensaje", "Rol eliminado con éxito"); 95 | return new ResponseEntity>(response, HttpStatus.OK); 96 | } 97 | 98 | // Crear 99 | @PostMapping("/roles") 100 | public ResponseEntity create(@RequestBody RolDto rol) { 101 | Rol rolNew = null; 102 | Map response = new HashMap<>(); 103 | 104 | try { 105 | rolNew = this.rolService.createRol(rol); 106 | } catch (DataAccessException e) { 107 | response.put("mensaje", "Error al realizar el insert en base de datos"); 108 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 109 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 110 | } 111 | 112 | response.put("mensaje", "Rol creado con éxito, con el ID " + rolNew.getIdRol()); 113 | response.put("Rol", rolNew); 114 | return new ResponseEntity>(response, HttpStatus.CREATED); 115 | } 116 | 117 | // Modificar 118 | @PutMapping("/roles/{id}") 119 | public ResponseEntity modify(@PathVariable Long id, @RequestBody RolDto rol) { 120 | Rol rolNew = null; 121 | Map response = new HashMap<>(); 122 | 123 | try { 124 | rolNew = this.rolService.updateRol(id, rol); 125 | } catch (DataAccessException e) { 126 | response.put("mensaje", "Error al realizar el update en base de datos"); 127 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 128 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 129 | } 130 | 131 | response.put("mensaje", "Rol modificado con éxito, con el ID " + rolNew.getIdRol()); 132 | response.put("rol", rolNew); 133 | return new ResponseEntity>(response, HttpStatus.CREATED); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/controller/ModeloController.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.dao.DataAccessException; 9 | import org.springframework.data.domain.Page; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.data.domain.Pageable; 12 | import org.springframework.data.domain.Sort; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.web.bind.annotation.CrossOrigin; 16 | import org.springframework.web.bind.annotation.DeleteMapping; 17 | import org.springframework.web.bind.annotation.GetMapping; 18 | import org.springframework.web.bind.annotation.PathVariable; 19 | import org.springframework.web.bind.annotation.PostMapping; 20 | import org.springframework.web.bind.annotation.PutMapping; 21 | import org.springframework.web.bind.annotation.RequestBody; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RequestMethod; 24 | import org.springframework.web.bind.annotation.ResponseStatus; 25 | import org.springframework.web.bind.annotation.RestController; 26 | 27 | import com.tallerMecanico.dto.ModeloDto; 28 | import com.tallerMecanico.entity.Modelo; 29 | import com.tallerMecanico.service.ModeloService; 30 | 31 | @RestController 32 | @CrossOrigin(origins = "http://localhost:4200", methods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, 33 | RequestMethod.DELETE }) 34 | @RequestMapping("/api") 35 | public class ModeloController { 36 | 37 | @Autowired 38 | private ModeloService modeloService; 39 | 40 | // Consulta todos 41 | @GetMapping("/modelos") 42 | @ResponseStatus(HttpStatus.OK) 43 | public List consulta() { 44 | return modeloService.findAll(); 45 | } 46 | 47 | // Consulta paginación 48 | @GetMapping("/modelos/page/{page}") 49 | public Page consultaPage(@PathVariable Integer page) { 50 | Pageable pageable = PageRequest.of(page, 50, Sort.by("idModelo").ascending()); 51 | return modeloService.findAllPage(pageable); 52 | } 53 | 54 | // Consulta por id 55 | @GetMapping("/modelos/{id}") 56 | public ResponseEntity consultaPorID(@PathVariable Long id) { 57 | 58 | Modelo modelo = null; 59 | String response = ""; 60 | try { 61 | modelo = modeloService.findById(id); 62 | } catch (DataAccessException e) { 63 | response = "Error al realizar la consulta."; 64 | response = response.concat(e.getMessage().concat(e.getMostSpecificCause().toString())); 65 | return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); 66 | } 67 | 68 | if (modelo == null) { 69 | response = "El modelo con el ID: ".concat(id.toString()).concat(" no existe en la base de datos"); 70 | return new ResponseEntity(response, HttpStatus.NOT_FOUND); 71 | } 72 | return new ResponseEntity(modelo, HttpStatus.OK); 73 | } 74 | 75 | // Eliminar por id 76 | @DeleteMapping("/modelos/{id}") 77 | public ResponseEntity delete(@PathVariable Long id) { 78 | 79 | Map response = new HashMap<>(); 80 | 81 | try { 82 | Modelo modeloDelete = this.modeloService.findById(id); 83 | if (modeloDelete == null) { 84 | response.put("mensaje", "Error al eliminar. La marca no existe en base de datos"); 85 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 86 | } 87 | 88 | modeloService.deleteModelo(id); 89 | } catch (DataAccessException e) { 90 | response.put("mensaje", "Error al eliminar en base de datos"); 91 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 92 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 93 | } 94 | response.put("mensaje", "Modelo eliminado con éxito"); 95 | return new ResponseEntity>(response, HttpStatus.OK); 96 | } 97 | 98 | // Crear 99 | @PostMapping("/modelos") 100 | public ResponseEntity create(@RequestBody ModeloDto modelo) { 101 | Modelo modeloNew = null; 102 | Map response = new HashMap<>(); 103 | 104 | try { 105 | modeloNew = this.modeloService.createModelo(modelo); 106 | } catch (DataAccessException e) { 107 | response.put("mensaje", "Error al realizar el insert en base de datos"); 108 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 109 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 110 | } 111 | 112 | response.put("mensaje", "Modelo creada con éxito, con el ID " + modeloNew.getIdModelo()); 113 | response.put("Modelo", modeloNew); 114 | return new ResponseEntity>(response, HttpStatus.CREATED); 115 | } 116 | 117 | // Modificar 118 | @PutMapping("/modelos/{id}") 119 | public ResponseEntity modify(@PathVariable Long id, @RequestBody ModeloDto modelo) { 120 | Modelo modeloNew = null; 121 | Map response = new HashMap<>(); 122 | 123 | try { 124 | modeloNew = this.modeloService.updateModelo(id, modelo); 125 | } catch (DataAccessException e) { 126 | response.put("mensaje", "Error al realizar el update en base de datos"); 127 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 128 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 129 | } 130 | 131 | response.put("mensaje", "Marca modificada con éxito, con el ID " + modeloNew.getIdModelo()); 132 | response.put("modelo", modeloNew); 133 | return new ResponseEntity>(response, HttpStatus.CREATED); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/controller/VehiculoController.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.dao.DataAccessException; 9 | import org.springframework.data.domain.Page; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.data.domain.Pageable; 12 | import org.springframework.data.domain.Sort; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.web.bind.annotation.CrossOrigin; 16 | import org.springframework.web.bind.annotation.DeleteMapping; 17 | import org.springframework.web.bind.annotation.GetMapping; 18 | import org.springframework.web.bind.annotation.PathVariable; 19 | import org.springframework.web.bind.annotation.PostMapping; 20 | import org.springframework.web.bind.annotation.PutMapping; 21 | import org.springframework.web.bind.annotation.RequestBody; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RequestMethod; 24 | import org.springframework.web.bind.annotation.ResponseStatus; 25 | import org.springframework.web.bind.annotation.RestController; 26 | 27 | import com.tallerMecanico.dto.VehiculoDto; 28 | import com.tallerMecanico.entity.Vehiculo; 29 | import com.tallerMecanico.service.VehiculoService; 30 | 31 | @RestController 32 | @CrossOrigin(origins = "http://localhost:4200", methods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, 33 | RequestMethod.DELETE }) 34 | @RequestMapping("/api") 35 | public class VehiculoController { 36 | 37 | @Autowired 38 | private VehiculoService vehiculoService; 39 | 40 | // Consulta todos 41 | @GetMapping("/vehiculos") 42 | @ResponseStatus(HttpStatus.OK) 43 | public List consulta() { 44 | return vehiculoService.findAll(); 45 | } 46 | 47 | // Consulta paginación 48 | @GetMapping("/vehiculos/page/{page}") 49 | public Page consultaPage(@PathVariable Integer page) { 50 | Pageable pageable = PageRequest.of(page, 10, Sort.by("idVehiculo").ascending()); 51 | return vehiculoService.findAllPage(pageable); 52 | } 53 | 54 | // Consulta por id 55 | @GetMapping("/vehiculos/{id}") 56 | public ResponseEntity consultaPorID(@PathVariable Long id) { 57 | 58 | Vehiculo vehiculo = null; 59 | String response = ""; 60 | try { 61 | vehiculo = vehiculoService.findById(id); 62 | } catch (DataAccessException e) { 63 | response = "Error al realizar la consulta."; 64 | response = response.concat(e.getMessage().concat(e.getMostSpecificCause().toString())); 65 | return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); 66 | } 67 | 68 | if (vehiculo == null) { 69 | response = "el vehiculo con el ID: ".concat(id.toString()).concat(" no existe en la base de datos"); 70 | return new ResponseEntity(response, HttpStatus.NOT_FOUND); 71 | } 72 | return new ResponseEntity(vehiculo, HttpStatus.OK); 73 | } 74 | 75 | // Eliminar por id 76 | @DeleteMapping("/vehiculos/{id}") 77 | public ResponseEntity delete(@PathVariable Long id) { 78 | 79 | Map response = new HashMap<>(); 80 | 81 | try { 82 | Vehiculo vehiculoDelete = this.vehiculoService.findById(id); 83 | if (vehiculoDelete == null) { 84 | response.put("mensaje", "Error al eliminar. El vehiculo no existe en base de datos"); 85 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 86 | } 87 | 88 | vehiculoService.deleteVehiculo(id); 89 | } catch (DataAccessException e) { 90 | response.put("mensaje", "Error al eliminar en base de datos"); 91 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 92 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 93 | } 94 | response.put("mensaje", "Vehiculo eliminado con éxito"); 95 | return new ResponseEntity>(response, HttpStatus.OK); 96 | } 97 | 98 | // Crear 99 | @PostMapping("/vehiculos") 100 | public ResponseEntity create(@RequestBody VehiculoDto vehiculo) { 101 | Vehiculo vehiculoNew = null; 102 | Map response = new HashMap<>(); 103 | 104 | try { 105 | vehiculoNew = this.vehiculoService.createVehiculo(vehiculo); 106 | } catch (DataAccessException e) { 107 | response.put("mensaje", "Error al realizar el insert en base de datos"); 108 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 109 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 110 | } 111 | 112 | response.put("mensaje", "Vehiculo creado con éxito, con el ID " + vehiculoNew.getIdVehiculo()); 113 | response.put("Vehiculo", vehiculoNew); 114 | return new ResponseEntity>(response, HttpStatus.CREATED); 115 | } 116 | 117 | // Modificar 118 | @PutMapping("/vehiculos/{id}") 119 | public ResponseEntity modify(@PathVariable Long id, @RequestBody VehiculoDto vehiculo) { 120 | Vehiculo vehiculoNew = null; 121 | Map response = new HashMap<>(); 122 | 123 | try { 124 | vehiculoNew = this.vehiculoService.updateVehiculo(id, vehiculo); 125 | } catch (DataAccessException e) { 126 | response.put("mensaje", "Error al realizar el update en base de datos"); 127 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 128 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 129 | } 130 | 131 | response.put("mensaje", "Vehiculo modificado con éxito, con el ID " + vehiculoNew.getIdVehiculo()); 132 | response.put("vehiculo", vehiculoNew); 133 | return new ResponseEntity>(response, HttpStatus.CREATED); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/controller/TipoMotorController.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.dao.DataAccessException; 9 | import org.springframework.data.domain.Page; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.data.domain.Pageable; 12 | import org.springframework.data.domain.Sort; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.web.bind.annotation.CrossOrigin; 16 | import org.springframework.web.bind.annotation.DeleteMapping; 17 | import org.springframework.web.bind.annotation.GetMapping; 18 | import org.springframework.web.bind.annotation.PathVariable; 19 | import org.springframework.web.bind.annotation.PostMapping; 20 | import org.springframework.web.bind.annotation.PutMapping; 21 | import org.springframework.web.bind.annotation.RequestBody; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RequestMethod; 24 | import org.springframework.web.bind.annotation.ResponseStatus; 25 | import org.springframework.web.bind.annotation.RestController; 26 | 27 | import com.tallerMecanico.dto.TipoMotorDto; 28 | import com.tallerMecanico.entity.TipoMotor; 29 | import com.tallerMecanico.service.TipoMotorService; 30 | 31 | @RestController 32 | @CrossOrigin(origins = "http://localhost:4200", methods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, 33 | RequestMethod.DELETE }) 34 | @RequestMapping("/api") 35 | public class TipoMotorController { 36 | 37 | @Autowired 38 | private TipoMotorService tipoMotorService; 39 | 40 | // Consulta todos 41 | @GetMapping("/tiposMotor") 42 | @ResponseStatus(HttpStatus.OK) 43 | public List consulta() { 44 | return tipoMotorService.findAll(); 45 | } 46 | 47 | // Consulta paginación 48 | @GetMapping("/tiposMotor/page/{page}") 49 | public Page consultaPage(@PathVariable Integer page) { 50 | Pageable pageable = PageRequest.of(page, 10, Sort.by("idTipoMotor").ascending()); 51 | return tipoMotorService.findAllPage(pageable); 52 | } 53 | 54 | // Consulta por id 55 | @GetMapping("/tiposMotor/{id}") 56 | public ResponseEntity consultaPorID(@PathVariable Long id) { 57 | 58 | TipoMotor tipoMotor = null; 59 | String response = ""; 60 | try { 61 | tipoMotor = tipoMotorService.findById(id); 62 | } catch (DataAccessException e) { 63 | response = "Error al realizar la consulta."; 64 | response = response.concat(e.getMessage().concat(e.getMostSpecificCause().toString())); 65 | return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); 66 | } 67 | 68 | if (tipoMotor == null) { 69 | response = "el Tipo de Motor con el ID: ".concat(id.toString()).concat(" no existe en la base de datos"); 70 | return new ResponseEntity(response, HttpStatus.NOT_FOUND); 71 | } 72 | return new ResponseEntity(tipoMotor, HttpStatus.OK); 73 | } 74 | 75 | // Eliminar por id 76 | @DeleteMapping("/tiposMotor/{id}") 77 | public ResponseEntity delete(@PathVariable Long id) { 78 | 79 | Map response = new HashMap<>(); 80 | 81 | try { 82 | TipoMotor tipoMotorDelete = this.tipoMotorService.findById(id); 83 | if (tipoMotorDelete == null) { 84 | response.put("mensaje", "Error al eliminar. El tipo de motor no existe en base de datos"); 85 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 86 | } 87 | 88 | tipoMotorService.deleteTipoMotor(id); 89 | } catch (DataAccessException e) { 90 | response.put("mensaje", "Error al eliminar en base de datos"); 91 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 92 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 93 | } 94 | response.put("mensaje", "Tipo de Motor eliminado con éxito"); 95 | return new ResponseEntity>(response, HttpStatus.OK); 96 | } 97 | 98 | // Crear 99 | @PostMapping("/tiposMotor") 100 | public ResponseEntity create(@RequestBody TipoMotorDto tipoMotor) { 101 | TipoMotor tipoMotorNew = null; 102 | Map response = new HashMap<>(); 103 | 104 | try { 105 | tipoMotorNew = this.tipoMotorService.createTipoMotor(tipoMotor); 106 | } catch (DataAccessException e) { 107 | response.put("mensaje", "Error al realizar el insert en base de datos"); 108 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 109 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 110 | } 111 | 112 | response.put("mensaje", "Tipo de Motor creado con éxito, con el ID " + tipoMotorNew.getIdTipoMotor()); 113 | response.put("Tipo de motor", tipoMotorNew); 114 | return new ResponseEntity>(response, HttpStatus.CREATED); 115 | } 116 | 117 | // Modificar 118 | @PutMapping("/tiposMotor/{id}") 119 | public ResponseEntity modify(@PathVariable Long id, @RequestBody TipoMotorDto tipoMotor) { 120 | TipoMotor tipoMotorNew = null; 121 | Map response = new HashMap<>(); 122 | 123 | try { 124 | tipoMotorNew = this.tipoMotorService.updateTipoMotor(id, tipoMotor); 125 | } catch (DataAccessException e) { 126 | response.put("mensaje", "Error al realizar el update en base de datos"); 127 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 128 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 129 | } 130 | 131 | response.put("mensaje", "Tipo de Motor modificado con éxito, con el ID " + tipoMotorNew.getIdTipoMotor()); 132 | response.put("Tipo de motor", tipoMotorNew); 133 | return new ResponseEntity>(response, HttpStatus.CREATED); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/controller/MarcaController.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.dao.DataAccessException; 9 | import org.springframework.data.domain.Page; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.data.domain.Pageable; 12 | import org.springframework.data.domain.Sort; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.web.bind.annotation.CrossOrigin; 16 | import org.springframework.web.bind.annotation.DeleteMapping; 17 | import org.springframework.web.bind.annotation.GetMapping; 18 | import org.springframework.web.bind.annotation.PathVariable; 19 | import org.springframework.web.bind.annotation.PostMapping; 20 | import org.springframework.web.bind.annotation.PutMapping; 21 | import org.springframework.web.bind.annotation.RequestBody; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RequestMethod; 24 | import org.springframework.web.bind.annotation.ResponseStatus; 25 | import org.springframework.web.bind.annotation.RestController; 26 | 27 | import com.tallerMecanico.dto.MarcaDto; 28 | import com.tallerMecanico.entity.Marca; 29 | import com.tallerMecanico.entity.Modelo; 30 | import com.tallerMecanico.repository.IModeloRepository; 31 | import com.tallerMecanico.service.MarcaService; 32 | 33 | @RestController 34 | @CrossOrigin(origins = "http://localhost:4200", methods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, 35 | RequestMethod.DELETE }) 36 | @RequestMapping("/api") 37 | public class MarcaController { 38 | 39 | @Autowired 40 | private MarcaService marcaService; 41 | @Autowired 42 | private IModeloRepository modeloRepository; 43 | 44 | // Consulta todos 45 | @GetMapping("/marcas") 46 | @ResponseStatus(HttpStatus.OK) 47 | public List consulta() { 48 | return marcaService.findAll(); 49 | } 50 | 51 | // Consulta paginación 52 | @GetMapping("/marcas/page/{page}") 53 | public Page consultaPage(@PathVariable Integer page) { 54 | Pageable pageable = PageRequest.of(page, 10, Sort.by("idMarca").ascending()); 55 | return marcaService.findAllPage(pageable); 56 | } 57 | 58 | // Consulta por id 59 | @GetMapping("/marcas/{id}") 60 | public ResponseEntity consultaPorID(@PathVariable Long id) { 61 | 62 | Marca marca = null; 63 | String response = ""; 64 | try { 65 | marca = marcaService.findById(id); 66 | } catch (DataAccessException e) { 67 | response = "Error al realizar la consulta."; 68 | response = response.concat(e.getMessage().concat(e.getMostSpecificCause().toString())); 69 | return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); 70 | } 71 | 72 | if (marca == null) { 73 | response = "La marca con el ID: ".concat(id.toString()).concat(" no existe en la base de datos"); 74 | return new ResponseEntity(response, HttpStatus.NOT_FOUND); 75 | } 76 | return new ResponseEntity(marca, HttpStatus.OK); 77 | } 78 | 79 | // Consultar los modelos por marca 80 | @GetMapping("marcas/{idMarca}/modelos") 81 | public List getModelosByMarca(@PathVariable Long idMarca) { 82 | return modeloRepository.findByMarca_IdMarca(idMarca); 83 | } 84 | 85 | // Eliminar por id 86 | @DeleteMapping("/marcas/{id}") 87 | public ResponseEntity delete(@PathVariable Long id) { 88 | 89 | Map response = new HashMap<>(); 90 | 91 | try { 92 | Marca marcaDelete = this.marcaService.findById(id); 93 | if (marcaDelete == null) { 94 | response.put("mensaje", "Error al eliminar. La marca no existe en base de datos"); 95 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 96 | } 97 | 98 | marcaService.deleteMarca(id); 99 | } catch (DataAccessException e) { 100 | response.put("mensaje", "Error al eliminar en base de datos"); 101 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 102 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 103 | } 104 | response.put("mensaje", "Marca eliminada con éxito"); 105 | return new ResponseEntity>(response, HttpStatus.OK); 106 | } 107 | 108 | // Crear 109 | @PostMapping("/marcas") 110 | public ResponseEntity create(@RequestBody MarcaDto marca) { 111 | Marca marcaNew = null; 112 | Map response = new HashMap<>(); 113 | 114 | try { 115 | marcaNew = this.marcaService.createMarca(marca); 116 | } catch (DataAccessException e) { 117 | response.put("mensaje", "Error al realizar el insert en base de datos"); 118 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 119 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 120 | } 121 | 122 | response.put("mensaje", "Marca creada con éxito, con el ID " + marcaNew.getIdMarca()); 123 | response.put("Marca", marcaNew); 124 | return new ResponseEntity>(response, HttpStatus.CREATED); 125 | } 126 | 127 | // Modificar 128 | @PutMapping("/marcas/{id}") 129 | public ResponseEntity modify(@PathVariable Long id, @RequestBody MarcaDto marca) { 130 | Marca marcaNew = null; 131 | Map response = new HashMap<>(); 132 | 133 | try { 134 | marcaNew = this.marcaService.updateMarca(id, marca); 135 | } catch (DataAccessException e) { 136 | response.put("mensaje", "Error al realizar el update en base de datos"); 137 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 138 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 139 | } 140 | 141 | response.put("mensaje", "Marca modificada con éxito, con el ID " + marcaNew.getIdMarca()); 142 | response.put("marca", marcaNew); 143 | return new ResponseEntity>(response, HttpStatus.CREATED); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/controller/OrdenServicioController.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.dao.DataAccessException; 9 | import org.springframework.data.domain.Page; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.data.domain.Pageable; 12 | import org.springframework.data.domain.Sort; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.web.bind.annotation.CrossOrigin; 16 | import org.springframework.web.bind.annotation.DeleteMapping; 17 | import org.springframework.web.bind.annotation.GetMapping; 18 | import org.springframework.web.bind.annotation.PathVariable; 19 | import org.springframework.web.bind.annotation.PostMapping; 20 | import org.springframework.web.bind.annotation.PutMapping; 21 | import org.springframework.web.bind.annotation.RequestBody; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RequestMethod; 24 | import org.springframework.web.bind.annotation.ResponseStatus; 25 | import org.springframework.web.bind.annotation.RestController; 26 | 27 | import com.tallerMecanico.dto.OrdenServicioDto; 28 | import com.tallerMecanico.entity.OrdenServicio; 29 | import com.tallerMecanico.service.OrdenServicioService; 30 | 31 | @RestController 32 | @CrossOrigin(origins = "http://localhost:4200", methods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, 33 | RequestMethod.DELETE }) 34 | @RequestMapping("/api") 35 | public class OrdenServicioController { 36 | 37 | @Autowired 38 | private OrdenServicioService ordenServicioService; 39 | 40 | // Consulta todos 41 | @GetMapping("/ordenesServicio") 42 | @ResponseStatus(HttpStatus.OK) 43 | public List consulta() { 44 | return ordenServicioService.findAll(); 45 | } 46 | 47 | // Consulta paginación 48 | @GetMapping("/ordenesServicio/page/{page}") 49 | public Page consultaPage(@PathVariable Integer page) { 50 | Pageable pageable = PageRequest.of(page, 10, Sort.by("idOrdenServicio").ascending()); 51 | return ordenServicioService.findAllPage(pageable); 52 | } 53 | 54 | // Consulta por id 55 | @GetMapping("/ordenesServicio/{id}") 56 | public ResponseEntity consultaPorID(@PathVariable Long id) { 57 | 58 | OrdenServicio ordenServicio = null; 59 | String response = ""; 60 | try { 61 | ordenServicio = ordenServicioService.findById(id); 62 | } catch (DataAccessException e) { 63 | response = "Error al realizar la consulta."; 64 | response = response.concat(e.getMessage().concat(e.getMostSpecificCause().toString())); 65 | return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); 66 | } 67 | 68 | if (ordenServicio == null) { 69 | response = "La Orden de Servicio con el ID: ".concat(id.toString()) 70 | .concat(" no existe en la base de datos"); 71 | return new ResponseEntity(response, HttpStatus.NOT_FOUND); 72 | } 73 | return new ResponseEntity(ordenServicio, HttpStatus.OK); 74 | } 75 | 76 | // Eliminar por id 77 | @DeleteMapping("/ordenesServicio/{id}") 78 | public ResponseEntity delete(@PathVariable Long id) { 79 | 80 | Map response = new HashMap<>(); 81 | 82 | try { 83 | OrdenServicio ordenServicioDelete = this.ordenServicioService.findById(id); 84 | if (ordenServicioDelete == null) { 85 | response.put("mensaje", "Error al eliminar. La Orden de Servicio no existe en base de datos"); 86 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 87 | } 88 | 89 | ordenServicioService.deleteOrdenServicio(id); 90 | } catch (DataAccessException e) { 91 | response.put("mensaje", "Error al eliminar en base de datos"); 92 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 93 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 94 | } 95 | response.put("mensaje", "Orden de Servicio eliminada con éxito"); 96 | return new ResponseEntity>(response, HttpStatus.OK); 97 | } 98 | 99 | // Crear 100 | @PostMapping("/ordenesServicio") 101 | public ResponseEntity create(@RequestBody OrdenServicioDto ordenServicio) { 102 | OrdenServicio ordenServicioNew = null; 103 | Map response = new HashMap<>(); 104 | 105 | try { 106 | ordenServicioNew = this.ordenServicioService.createOrdenServicio(ordenServicio); 107 | } catch (DataAccessException e) { 108 | response.put("mensaje", "Error al realizar el insert en base de datos"); 109 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 110 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 111 | } 112 | 113 | response.put("mensaje", 114 | "Orden de Servicio creada con éxito, con el ID " + ordenServicioNew.getIdOrdenServicio()); 115 | response.put("Orden de Servicio", ordenServicioNew); 116 | return new ResponseEntity>(response, HttpStatus.CREATED); 117 | } 118 | 119 | // Modificar 120 | @PutMapping("/ordenesServicio/{id}") 121 | public ResponseEntity modify(@PathVariable Long id, @RequestBody OrdenServicioDto ordenServicio) { 122 | OrdenServicio ordenServicioNew = null; 123 | Map response = new HashMap<>(); 124 | 125 | try { 126 | ordenServicioNew = this.ordenServicioService.updateOrdenServicio(id, ordenServicio); 127 | } catch (DataAccessException e) { 128 | response.put("mensaje", "Error al realizar el update en base de datos"); 129 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 130 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 131 | } 132 | 133 | response.put("mensaje", 134 | "Orden de Servicio modificada con éxito, con el ID " + ordenServicioNew.getIdOrdenServicio()); 135 | response.put("Orden de Servicio", ordenServicioNew); 136 | return new ResponseEntity>(response, HttpStatus.CREATED); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/controller/UsuarioController.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.dao.DataAccessException; 9 | import org.springframework.data.domain.Page; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.data.domain.Pageable; 12 | import org.springframework.data.domain.Sort; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.web.bind.annotation.CrossOrigin; 16 | import org.springframework.web.bind.annotation.DeleteMapping; 17 | import org.springframework.web.bind.annotation.GetMapping; 18 | import org.springframework.web.bind.annotation.PathVariable; 19 | import org.springframework.web.bind.annotation.PostMapping; 20 | import org.springframework.web.bind.annotation.PutMapping; 21 | import org.springframework.web.bind.annotation.RequestBody; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RequestMethod; 24 | import org.springframework.web.bind.annotation.RequestParam; 25 | import org.springframework.web.bind.annotation.ResponseStatus; 26 | import org.springframework.web.bind.annotation.RestController; 27 | 28 | import com.tallerMecanico.dto.RegistroResponseDto; 29 | import com.tallerMecanico.dto.UsuarioDto; 30 | import com.tallerMecanico.entity.Usuario; 31 | import com.tallerMecanico.service.UsuarioService; 32 | 33 | @RestController 34 | @CrossOrigin(origins = "http://localhost:4200", methods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, 35 | RequestMethod.DELETE }) 36 | @RequestMapping("/api") 37 | public class UsuarioController { 38 | 39 | @Autowired 40 | private UsuarioService usuarioService; 41 | 42 | // Consulta todos 43 | @GetMapping("/usuarios") 44 | @ResponseStatus(HttpStatus.OK) 45 | public List consulta() { 46 | return usuarioService.findAll(); 47 | } 48 | 49 | // Consulta paginación 50 | @GetMapping("/usuarios/page/{page}") 51 | public Page consultaPage(@PathVariable Integer page) { 52 | Pageable pageable = PageRequest.of(page, 10, Sort.by("idUsuario").ascending()); 53 | return usuarioService.findAllPage(pageable); 54 | } 55 | 56 | // Consulta por id 57 | @GetMapping("/usuarios/{id}") 58 | public ResponseEntity consultaPorID(@PathVariable Long id) { 59 | 60 | Usuario usuario = null; 61 | String response = ""; 62 | try { 63 | usuario = usuarioService.findById(id); 64 | } catch (DataAccessException e) { 65 | response = "Error al realizar la consulta."; 66 | response = response.concat(e.getMessage().concat(e.getMostSpecificCause().toString())); 67 | return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); 68 | } 69 | 70 | if (usuario == null) { 71 | response = "El Usuario con el ID: ".concat(id.toString()).concat(" no existe en la base de datos"); 72 | return new ResponseEntity(response, HttpStatus.NOT_FOUND); 73 | } 74 | return new ResponseEntity(usuario, HttpStatus.OK); 75 | } 76 | 77 | // Eliminar por id 78 | @DeleteMapping("/usuarios/{id}") 79 | public ResponseEntity delete(@PathVariable Long id) { 80 | 81 | Map response = new HashMap<>(); 82 | 83 | try { 84 | Usuario usuarioDelete = this.usuarioService.findById(id); 85 | if (usuarioDelete == null) { 86 | response.put("mensaje", "Error al eliminar. La marca no existe en base de datos"); 87 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 88 | } 89 | 90 | usuarioService.deleteUsuario(id); 91 | } catch (DataAccessException e) { 92 | response.put("mensaje", "Error al eliminar en base de datos"); 93 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 94 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 95 | } 96 | response.put("mensaje", "Usuario eliminado con éxito"); 97 | return new ResponseEntity>(response, HttpStatus.OK); 98 | } 99 | 100 | /* 101 | * // Crear 102 | * 103 | * @PostMapping("/usuarios") public ResponseEntity create(@RequestBody 104 | * UsuarioDto usuario) { Usuario usuarioNew = null; Map response 105 | * = new HashMap<>(); 106 | * 107 | * try { usuarioNew = this.usuarioService.createUsuario(usuario); } catch 108 | * (DataAccessException e) { response.put("mensaje", 109 | * "Error al realizar el insert en base de datos"); response.put("error", 110 | * e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 111 | * return new ResponseEntity>(response, 112 | * HttpStatus.INTERNAL_SERVER_ERROR); } 113 | * 114 | * response.put("mensaje", "Usuario creado con éxito, con el ID " + 115 | * usuarioNew.getIdUsuario()); response.put("Usuario", usuarioNew); return new 116 | * ResponseEntity>(response, HttpStatus.CREATED); } 117 | */ 118 | 119 | // Método para poder registrar usuarios con role "user" 120 | @PostMapping("/auth/register") 121 | public ResponseEntity registrarUsuario(@RequestBody UsuarioDto dtoRegistro, 122 | @RequestParam String role) { 123 | return usuarioService.registrarUsuario(dtoRegistro, role); 124 | } 125 | 126 | // Modificar 127 | @PutMapping("/usuarios/{id}") 128 | public ResponseEntity modify(@PathVariable Long id, @RequestBody UsuarioDto usuario) { 129 | Usuario usuarioNew = null; 130 | Map response = new HashMap<>(); 131 | 132 | try { 133 | usuarioNew = this.usuarioService.updateUsuario(id, usuario); 134 | } catch (DataAccessException e) { 135 | response.put("mensaje", "Error al realizar el update en base de datos"); 136 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 137 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 138 | } 139 | 140 | response.put("mensaje", "Usuario modificado con éxito, con el ID " + usuarioNew.getIdUsuario()); 141 | response.put("usuario", usuarioNew); 142 | return new ResponseEntity>(response, HttpStatus.CREATED); 143 | } 144 | } -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/controller/EstatusServicioController.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.dao.DataAccessException; 9 | import org.springframework.data.domain.Page; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.data.domain.Pageable; 12 | import org.springframework.data.domain.Sort; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.web.bind.annotation.CrossOrigin; 16 | import org.springframework.web.bind.annotation.DeleteMapping; 17 | import org.springframework.web.bind.annotation.GetMapping; 18 | import org.springframework.web.bind.annotation.PathVariable; 19 | import org.springframework.web.bind.annotation.PostMapping; 20 | import org.springframework.web.bind.annotation.PutMapping; 21 | import org.springframework.web.bind.annotation.RequestBody; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RequestMethod; 24 | import org.springframework.web.bind.annotation.ResponseStatus; 25 | import org.springframework.web.bind.annotation.RestController; 26 | 27 | import com.tallerMecanico.dto.EstatusServicioDto; 28 | import com.tallerMecanico.entity.EstatusServicio; 29 | import com.tallerMecanico.service.EstatusServicioService; 30 | 31 | @RestController 32 | @CrossOrigin(origins = "http://localhost:4200", methods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, 33 | RequestMethod.DELETE }) 34 | @RequestMapping("/api") 35 | public class EstatusServicioController { 36 | 37 | @Autowired 38 | private EstatusServicioService estatusServicioService; 39 | 40 | // Consulta todos 41 | @GetMapping("/estatusServicios") 42 | @ResponseStatus(HttpStatus.OK) 43 | public List consulta() { 44 | return estatusServicioService.findAll(); 45 | } 46 | 47 | // Consulta paginación 48 | @GetMapping("/estatusServicios/page/{page}") 49 | public Page consultaPage(@PathVariable Integer page) { 50 | Pageable pageable = PageRequest.of(page, 10, Sort.by("idEstatusServicio").ascending()); 51 | return estatusServicioService.findAllPage(pageable); 52 | } 53 | 54 | // Consulta por id 55 | @GetMapping("/estatusServicios/{id}") 56 | public ResponseEntity consultaPorID(@PathVariable Long id) { 57 | 58 | EstatusServicio estatusServicio = null; 59 | String response = ""; 60 | try { 61 | estatusServicio = estatusServicioService.findById(id); 62 | } catch (DataAccessException e) { 63 | response = "Error al realizar la consulta."; 64 | response = response.concat(e.getMessage().concat(e.getMostSpecificCause().toString())); 65 | return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); 66 | } 67 | 68 | if (estatusServicio == null) { 69 | response = "el Estatus Servicio con el ID: ".concat(id.toString()).concat(" no existe en la base de datos"); 70 | return new ResponseEntity(response, HttpStatus.NOT_FOUND); 71 | } 72 | return new ResponseEntity(estatusServicio, HttpStatus.OK); 73 | } 74 | 75 | // Eliminar por id 76 | @DeleteMapping("/estatusServicios/{id}") 77 | public ResponseEntity delete(@PathVariable Long id) { 78 | 79 | Map response = new HashMap<>(); 80 | 81 | try { 82 | EstatusServicio estatusServicioDelete = this.estatusServicioService.findById(id); 83 | if (estatusServicioDelete == null) { 84 | response.put("mensaje", "Error al eliminar. La marca no existe en base de datos"); 85 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 86 | } 87 | 88 | estatusServicioService.deleteEstatusServicio(id); 89 | } catch (DataAccessException e) { 90 | response.put("mensaje", "Error al eliminar en base de datos"); 91 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 92 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 93 | } 94 | response.put("mensaje", "Estatus Servicio eliminado con éxito"); 95 | return new ResponseEntity>(response, HttpStatus.OK); 96 | } 97 | 98 | // Crear 99 | @PostMapping("/estatusServicios") 100 | public ResponseEntity create(@RequestBody EstatusServicioDto estatusServicio) { 101 | EstatusServicio estatusServicioNew = null; 102 | Map response = new HashMap<>(); 103 | 104 | try { 105 | estatusServicioNew = this.estatusServicioService.createEstatusServicio(estatusServicio); 106 | } catch (DataAccessException e) { 107 | response.put("mensaje", "Error al realizar el insert en base de datos"); 108 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 109 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 110 | } 111 | 112 | response.put("mensaje", 113 | "Estatus Servicio creado con éxito, con el ID " + estatusServicioNew.getIdEstatusServicio()); 114 | response.put("Estatus Servicio", estatusServicioNew); 115 | return new ResponseEntity>(response, HttpStatus.CREATED); 116 | } 117 | 118 | // Modificar 119 | @PutMapping("/estatusServicios/{id}") 120 | public ResponseEntity modify(@PathVariable Long id, @RequestBody EstatusServicioDto estatusServicio) { 121 | EstatusServicio estatusServicioNew = null; 122 | Map response = new HashMap<>(); 123 | 124 | try { 125 | estatusServicioNew = this.estatusServicioService.updateEstatusServicio(id, estatusServicio); 126 | } catch (DataAccessException e) { 127 | response.put("mensaje", "Error al realizar el update en base de datos"); 128 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 129 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 130 | } 131 | 132 | response.put("mensaje", 133 | "Estatus Servicio modificado con éxito, con el ID " + estatusServicioNew.getIdEstatusServicio()); 134 | response.put("Estatus Servicio", estatusServicioNew); 135 | return new ResponseEntity>(response, HttpStatus.CREATED); 136 | } 137 | } -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/controller/EmpleadoController.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.dao.DataAccessException; 9 | import org.springframework.data.domain.Page; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.data.domain.Pageable; 12 | import org.springframework.data.domain.Sort; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.web.bind.annotation.CrossOrigin; 16 | import org.springframework.web.bind.annotation.DeleteMapping; 17 | import org.springframework.web.bind.annotation.GetMapping; 18 | import org.springframework.web.bind.annotation.PathVariable; 19 | import org.springframework.web.bind.annotation.PostMapping; 20 | import org.springframework.web.bind.annotation.PutMapping; 21 | import org.springframework.web.bind.annotation.RequestBody; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RequestMethod; 24 | import org.springframework.web.bind.annotation.ResponseStatus; 25 | import org.springframework.web.bind.annotation.RestController; 26 | 27 | import com.tallerMecanico.dto.EmpleadoDto; 28 | import com.tallerMecanico.dto.RegistroResponseDto; 29 | import com.tallerMecanico.dto.RegistroUsuarioEmpleadoDto; 30 | import com.tallerMecanico.entity.Empleado; 31 | import com.tallerMecanico.service.EmpleadoService; 32 | import com.tallerMecanico.service.IUsuarioService; 33 | 34 | @RestController 35 | @CrossOrigin(origins = "http://localhost:4200", methods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, 36 | RequestMethod.DELETE }) 37 | @RequestMapping("/api") 38 | public class EmpleadoController { 39 | 40 | @Autowired 41 | private EmpleadoService empleadoService; 42 | @Autowired 43 | private IUsuarioService usuarioService; 44 | 45 | // Consulta todos 46 | @GetMapping("/empleados") 47 | @ResponseStatus(HttpStatus.OK) 48 | public List consulta() { 49 | return empleadoService.findAll(); 50 | } 51 | 52 | // Consulta paginación 53 | @GetMapping("/empleados/page/{page}") 54 | public Page consultaPage(@PathVariable Integer page) { 55 | Pageable pageable = PageRequest.of(page, 10, Sort.by("idEmpleado").ascending()); 56 | return empleadoService.findAllPage(pageable); 57 | } 58 | 59 | // Consulta por id 60 | @GetMapping("/empleados/{id}") 61 | public ResponseEntity consultaPorID(@PathVariable Long id) { 62 | 63 | Empleado empleado = null; 64 | String response = ""; 65 | try { 66 | empleado = empleadoService.findById(id); 67 | } catch (DataAccessException e) { 68 | response = "Error al realizar la consulta."; 69 | response = response.concat(e.getMessage().concat(e.getMostSpecificCause().toString())); 70 | return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); 71 | } 72 | 73 | if (empleado == null) { 74 | response = "el Empleado con el ID: ".concat(id.toString()).concat(" no existe en la base de datos"); 75 | return new ResponseEntity(response, HttpStatus.NOT_FOUND); 76 | } 77 | return new ResponseEntity(empleado, HttpStatus.OK); 78 | } 79 | 80 | // Modificar 81 | @PutMapping("/empleados/{id}") 82 | public ResponseEntity modify(@PathVariable Long id, @RequestBody EmpleadoDto empleado) { 83 | Empleado empleadoNew = null; 84 | Map response = new HashMap<>(); 85 | 86 | try { 87 | empleadoNew = this.empleadoService.updateEmpleado(id, empleado); 88 | } catch (DataAccessException e) { 89 | response.put("mensaje", "Error al realizar el update en base de datos"); 90 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 91 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 92 | } 93 | 94 | response.put("mensaje", "Empleado modificado con éxito, con el ID " + empleadoNew.getIdEmpleado()); 95 | response.put("empleado", empleadoNew); 96 | return new ResponseEntity>(response, HttpStatus.CREATED); 97 | } 98 | 99 | // registrar usuario empleado 100 | @PostMapping("/empleados") 101 | public ResponseEntity registrarUsuarioYEmpleado(@RequestBody RegistroUsuarioEmpleadoDto registroDto) { 102 | Map response = new HashMap<>(); 103 | 104 | try { 105 | ResponseEntity registroUsuarioResponse = usuarioService 106 | .registrarUsuario(registroDto.getUsuario(), "EMPLEADO"); 107 | RegistroResponseDto usuarioResponse = registroUsuarioResponse.getBody(); 108 | 109 | // Verificar si el ID de usuario no es nulo 110 | if (usuarioResponse != null && usuarioResponse.getIdUsuario() != null) { 111 | // Crear el empleado y asociarle el ID del usuario 112 | Long idUsuario = usuarioResponse.getIdUsuario(); 113 | Empleado nuevoEmpleado = empleadoService.createEmpleado(registroDto.getEmpleado(), idUsuario); 114 | 115 | response.put("mensaje", "Usuario y empleado creados con éxito"); 116 | response.put("Usuario", usuarioResponse); 117 | response.put("Empleado", nuevoEmpleado); 118 | return new ResponseEntity>(response, HttpStatus.CREATED); 119 | } else { 120 | response.put("mensaje", "Error al obtener el ID de usuario desde la respuesta"); 121 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 122 | } 123 | } catch (DataAccessException e) { 124 | response.put("mensaje", "Error al realizar la operación en la base de datos"); 125 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 126 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 127 | } 128 | } 129 | 130 | // Eliminar empleado 131 | @DeleteMapping("/empleados/{id}") 132 | public ResponseEntity eliminarEmpleado(@PathVariable Long id) { 133 | Map response = new HashMap<>(); 134 | 135 | try { 136 | empleadoService.deleteEmpleado(id); 137 | response.put("mensaje", "Registro Eliminado"); 138 | return new ResponseEntity>(response, HttpStatus.OK); 139 | } catch (Error e) { 140 | response.put("mensaje", "Error al realizar la operación en la base de datos"); 141 | return new ResponseEntity>(response, HttpStatus.NOT_FOUND); 142 | } 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/controller/DetalleOrdenServicioController.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.dao.DataAccessException; 9 | import org.springframework.data.domain.Page; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.data.domain.Pageable; 12 | import org.springframework.data.domain.Sort; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.web.bind.annotation.CrossOrigin; 16 | import org.springframework.web.bind.annotation.DeleteMapping; 17 | import org.springframework.web.bind.annotation.GetMapping; 18 | import org.springframework.web.bind.annotation.PathVariable; 19 | import org.springframework.web.bind.annotation.PostMapping; 20 | import org.springframework.web.bind.annotation.PutMapping; 21 | import org.springframework.web.bind.annotation.RequestBody; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RequestMethod; 24 | import org.springframework.web.bind.annotation.ResponseStatus; 25 | import org.springframework.web.bind.annotation.RestController; 26 | 27 | import com.tallerMecanico.dto.DetalleOrdenServicioDto; 28 | import com.tallerMecanico.entity.DetalleOrdenServicio; 29 | import com.tallerMecanico.service.DetalleOrdenServicioService; 30 | 31 | @RestController 32 | @CrossOrigin(origins = "http://localhost:4200", methods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, 33 | RequestMethod.DELETE }) 34 | @RequestMapping("/api") 35 | public class DetalleOrdenServicioController { 36 | 37 | @Autowired 38 | private DetalleOrdenServicioService detalleOrdenServicioService; 39 | 40 | // Consulta todos 41 | @GetMapping("/detalleOrdenServicio") 42 | @ResponseStatus(HttpStatus.OK) 43 | public List consulta() { 44 | return detalleOrdenServicioService.findAll(); 45 | } 46 | 47 | // Consulta paginación 48 | @GetMapping("/detalleOrdenServicio/page/{page}") 49 | public Page consultaPage(@PathVariable Integer page) { 50 | Pageable pageable = PageRequest.of(page, 10, Sort.by("idDetalleOrdenServicio").ascending()); 51 | return detalleOrdenServicioService.findAllPage(pageable); 52 | } 53 | 54 | // Consulta por id 55 | @GetMapping("/detalleOrdenServicio/{id}") 56 | public ResponseEntity consultaPorID(@PathVariable Long id) { 57 | 58 | DetalleOrdenServicio detalleOrdenServicio = null; 59 | String response = ""; 60 | try { 61 | detalleOrdenServicio = detalleOrdenServicioService.findById(id); 62 | } catch (DataAccessException e) { 63 | response = "Error al realizar la consulta."; 64 | response = response.concat(e.getMessage().concat(e.getMostSpecificCause().toString())); 65 | return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); 66 | } 67 | 68 | if (detalleOrdenServicio == null) { 69 | response = "El Detalle de la Orden de Servicio con el ID: ".concat(id.toString()) 70 | .concat(" no existe en la base de datos"); 71 | return new ResponseEntity(response, HttpStatus.NOT_FOUND); 72 | } 73 | return new ResponseEntity(detalleOrdenServicio, HttpStatus.OK); 74 | } 75 | 76 | // Eliminar por id 77 | @DeleteMapping("/detalleOrdenServicio/{id}") 78 | public ResponseEntity delete(@PathVariable Long id) { 79 | 80 | Map response = new HashMap<>(); 81 | 82 | try { 83 | DetalleOrdenServicio detalleOrdenServicioDelete = this.detalleOrdenServicioService.findById(id); 84 | if (detalleOrdenServicioDelete == null) { 85 | response.put("mensaje", "Error al eliminar. El Detalle de la Orden de Servicio no existe en base de datos"); 86 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 87 | } 88 | 89 | detalleOrdenServicioService.deleteDetalleOrdenServicio(id); 90 | } catch (DataAccessException e) { 91 | response.put("mensaje", "Error al eliminar en base de datos"); 92 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 93 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 94 | } 95 | response.put("mensaje", "Detalle de la Orden de Servicio eliminada con éxito"); 96 | return new ResponseEntity>(response, HttpStatus.OK); 97 | } 98 | 99 | // Crear 100 | @PostMapping("/detalleOrdenServicio") 101 | public ResponseEntity create(@RequestBody DetalleOrdenServicioDto detalleOrdenServicio) { 102 | DetalleOrdenServicio detalleOrdenServicioNew = null; 103 | Map response = new HashMap<>(); 104 | 105 | try { 106 | detalleOrdenServicioNew = this.detalleOrdenServicioService.createDetalleOrdenServicio(detalleOrdenServicio); 107 | } catch (DataAccessException e) { 108 | response.put("mensaje", "Error al realizar el insert en base de datos"); 109 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 110 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 111 | } 112 | 113 | response.put("mensaje", 114 | "Orden de Servicio creada con éxito, con el ID " + detalleOrdenServicioNew.getIdDetalleOrdenServicio()); 115 | response.put("Detalle de la Orden de Servicio", detalleOrdenServicioNew); 116 | return new ResponseEntity>(response, HttpStatus.CREATED); 117 | } 118 | 119 | // Modificar 120 | @PutMapping("/detalleOrdenServicio/{id}") 121 | public ResponseEntity modify(@PathVariable Long id, @RequestBody DetalleOrdenServicioDto detalleOrdenServicio) { 122 | DetalleOrdenServicio detalleOrdenServicioNew = null; 123 | Map response = new HashMap<>(); 124 | 125 | try { 126 | detalleOrdenServicioNew = this.detalleOrdenServicioService.updateDetalleOrdenServicio(id, detalleOrdenServicio); 127 | } catch (DataAccessException e) { 128 | response.put("mensaje", "Error al realizar el update en base de datos"); 129 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 130 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 131 | } 132 | 133 | response.put("mensaje", 134 | "Detalle de Orden de Servicio modificada con éxito, con el ID " + detalleOrdenServicioNew.getIdDetalleOrdenServicio()); 135 | response.put("Detalle de Orden de Servicio", detalleOrdenServicioNew); 136 | return new ResponseEntity>(response, HttpStatus.CREATED); 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Apache Maven Wrapper startup batch script, version 3.2.0 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 28 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 29 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 30 | @REM e.g. to debug Maven itself, use 31 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 32 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 33 | @REM ---------------------------------------------------------------------------- 34 | 35 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 36 | @echo off 37 | @REM set title of command window 38 | title %0 39 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 40 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 41 | 42 | @REM set %HOME% to equivalent of $HOME 43 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 44 | 45 | @REM Execute a user defined script before this one 46 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 47 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 48 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 49 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 50 | :skipRcPre 51 | 52 | @setlocal 53 | 54 | set ERROR_CODE=0 55 | 56 | @REM To isolate internal variables from possible post scripts, we use another setlocal 57 | @setlocal 58 | 59 | @REM ==== START VALIDATION ==== 60 | if not "%JAVA_HOME%" == "" goto OkJHome 61 | 62 | echo. 63 | echo Error: JAVA_HOME not found in your environment. >&2 64 | echo Please set the JAVA_HOME variable in your environment to match the >&2 65 | echo location of your Java installation. >&2 66 | echo. 67 | goto error 68 | 69 | :OkJHome 70 | if exist "%JAVA_HOME%\bin\java.exe" goto init 71 | 72 | echo. 73 | echo Error: JAVA_HOME is set to an invalid directory. >&2 74 | echo JAVA_HOME = "%JAVA_HOME%" >&2 75 | echo Please set the JAVA_HOME variable in your environment to match the >&2 76 | echo location of your Java installation. >&2 77 | echo. 78 | goto error 79 | 80 | @REM ==== END VALIDATION ==== 81 | 82 | :init 83 | 84 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 85 | @REM Fallback to current working directory if not found. 86 | 87 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 88 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 89 | 90 | set EXEC_DIR=%CD% 91 | set WDIR=%EXEC_DIR% 92 | :findBaseDir 93 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 94 | cd .. 95 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 96 | set WDIR=%CD% 97 | goto findBaseDir 98 | 99 | :baseDirFound 100 | set MAVEN_PROJECTBASEDIR=%WDIR% 101 | cd "%EXEC_DIR%" 102 | goto endDetectBaseDir 103 | 104 | :baseDirNotFound 105 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 106 | cd "%EXEC_DIR%" 107 | 108 | :endDetectBaseDir 109 | 110 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 111 | 112 | @setlocal EnableExtensions EnableDelayedExpansion 113 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 114 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 115 | 116 | :endReadAdditionalConfig 117 | 118 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" 123 | 124 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 125 | IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | if "%MVNW_VERBOSE%" == "true" ( 132 | echo Found %WRAPPER_JAR% 133 | ) 134 | ) else ( 135 | if not "%MVNW_REPOURL%" == "" ( 136 | SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" 137 | ) 138 | if "%MVNW_VERBOSE%" == "true" ( 139 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 140 | echo Downloading from: %WRAPPER_URL% 141 | ) 142 | 143 | powershell -Command "&{"^ 144 | "$webclient = new-object System.Net.WebClient;"^ 145 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 146 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 147 | "}"^ 148 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ 149 | "}" 150 | if "%MVNW_VERBOSE%" == "true" ( 151 | echo Finished downloading %WRAPPER_JAR% 152 | ) 153 | ) 154 | @REM End of extension 155 | 156 | @REM If specified, validate the SHA-256 sum of the Maven wrapper jar file 157 | SET WRAPPER_SHA_256_SUM="" 158 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 159 | IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B 160 | ) 161 | IF NOT %WRAPPER_SHA_256_SUM%=="" ( 162 | powershell -Command "&{"^ 163 | "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ 164 | "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ 165 | " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ 166 | " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ 167 | " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ 168 | " exit 1;"^ 169 | "}"^ 170 | "}" 171 | if ERRORLEVEL 1 goto error 172 | ) 173 | 174 | @REM Provide a "standardized" way to retrieve the CLI args that will 175 | @REM work with both Windows and non-Windows executions. 176 | set MAVEN_CMD_LINE_ARGS=%* 177 | 178 | %MAVEN_JAVA_EXE% ^ 179 | %JVM_CONFIG_MAVEN_PROPS% ^ 180 | %MAVEN_OPTS% ^ 181 | %MAVEN_DEBUG_OPTS% ^ 182 | -classpath %WRAPPER_JAR% ^ 183 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 184 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 185 | if ERRORLEVEL 1 goto error 186 | goto end 187 | 188 | :error 189 | set ERROR_CODE=1 190 | 191 | :end 192 | @endlocal & set ERROR_CODE=%ERROR_CODE% 193 | 194 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 195 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 196 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 197 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 198 | :skipRcPost 199 | 200 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 201 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 202 | 203 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 204 | 205 | cmd /C exit /B %ERROR_CODE% 206 | -------------------------------------------------------------------------------- /src/main/java/com/tallerMecanico/controller/ClienteController.java: -------------------------------------------------------------------------------- 1 | package com.tallerMecanico.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.dao.DataAccessException; 9 | import org.springframework.data.domain.Page; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.data.domain.Pageable; 12 | import org.springframework.data.domain.Sort; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.web.bind.annotation.CrossOrigin; 16 | import org.springframework.web.bind.annotation.DeleteMapping; 17 | import org.springframework.web.bind.annotation.GetMapping; 18 | import org.springframework.web.bind.annotation.PathVariable; 19 | import org.springframework.web.bind.annotation.PostMapping; 20 | import org.springframework.web.bind.annotation.PutMapping; 21 | import org.springframework.web.bind.annotation.RequestBody; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RequestMethod; 24 | import org.springframework.web.bind.annotation.RequestParam; 25 | import org.springframework.web.bind.annotation.ResponseStatus; 26 | import org.springframework.web.bind.annotation.RestController; 27 | 28 | import com.tallerMecanico.dto.ClienteDto; 29 | import com.tallerMecanico.dto.RegistroResponseDto; 30 | import com.tallerMecanico.dto.RegistroUsuarioClienteDto; 31 | import com.tallerMecanico.entity.Cliente; 32 | import com.tallerMecanico.entity.Vehiculo; 33 | import com.tallerMecanico.repository.IVehiculoRepository; 34 | import com.tallerMecanico.service.ClienteService; 35 | import com.tallerMecanico.service.IUsuarioService; 36 | 37 | @RestController 38 | @CrossOrigin(origins = "http://localhost:4200", methods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, 39 | RequestMethod.DELETE }) 40 | @RequestMapping("/api") 41 | public class ClienteController { 42 | 43 | @Autowired 44 | private ClienteService clienteService; 45 | @Autowired 46 | private IUsuarioService usuarioService; 47 | 48 | @Autowired 49 | private IVehiculoRepository vehiculoRepository; 50 | 51 | // Consulta todos 52 | @GetMapping("/clientes") 53 | @ResponseStatus(HttpStatus.OK) 54 | public List consulta() { 55 | return clienteService.findAll(); 56 | } 57 | 58 | // Consulta paginación 59 | @GetMapping("/clientes/page/{page}") 60 | public Page consultaPage(@PathVariable Integer page) { 61 | Pageable pageable = PageRequest.of(page, 10, Sort.by("idCliente").ascending()); 62 | return clienteService.findAllPage(pageable); 63 | } 64 | 65 | // Consulta por id 66 | @GetMapping("/clientes/{id}") 67 | public ResponseEntity consultaPorID(@PathVariable Long id) { 68 | 69 | Cliente cliente = null; 70 | String response = ""; 71 | try { 72 | cliente = clienteService.findById(id); 73 | } catch (DataAccessException e) { 74 | response = "Error al realizar la consulta."; 75 | response = response.concat(e.getMessage().concat(e.getMostSpecificCause().toString())); 76 | return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); 77 | } 78 | 79 | if (cliente == null) { 80 | response = "el Cliente con el ID: ".concat(id.toString()).concat(" no existe en la base de datos"); 81 | return new ResponseEntity(response, HttpStatus.NOT_FOUND); 82 | } 83 | return new ResponseEntity(cliente, HttpStatus.OK); 84 | } 85 | 86 | // Consultar los vehiculos por cliente 87 | @GetMapping("clientes/{idCliente}/vehiculos") 88 | public List getVehiculosByCliente(@PathVariable Long idCliente) { 89 | return vehiculoRepository.findByCliente_IdCliente(idCliente); 90 | } 91 | 92 | // Eliminar por id 93 | /* 94 | * @DeleteMapping("/clientes/{id}") public ResponseEntity 95 | * delete(@PathVariable Long id) { 96 | * 97 | * Map response = new HashMap<>(); 98 | * 99 | * try { Cliente clienteDelete = this.clienteService.findById(id); if 100 | * (clienteDelete == null) { response.put("mensaje", 101 | * "Error al eliminar. La marca no existe en base de datos"); return new 102 | * ResponseEntity>(response, 103 | * HttpStatus.INTERNAL_SERVER_ERROR); } 104 | * 105 | * clienteService.deleteCliente(id); } catch (DataAccessException e) { 106 | * response.put("mensaje", "Error al eliminar en base de datos"); 107 | * response.put("error", 108 | * e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 109 | * return new ResponseEntity>(response, 110 | * HttpStatus.INTERNAL_SERVER_ERROR); } response.put("mensaje", 111 | * "Cliente eliminado con éxito"); return new ResponseEntity>(response, HttpStatus.OK); } 113 | */ 114 | 115 | // Crear 116 | /* 117 | * @PostMapping("/clientes") public ResponseEntity create(@RequestBody 118 | * ClienteDto cliente) { Cliente clienteNew = null; Map response 119 | * = new HashMap<>(); 120 | * 121 | * try { // Asegúrate de obtener el idUsuario necesario aquí (puedes obtenerlo 122 | * de donde proceda) Long idUsuario = cliente.usuario() != null ? 123 | * cliente.usuario().getIdUsuario() : null; 124 | * 125 | * // Verifica si se obtuvo correctamente el idUsuario antes de llamar al 126 | * servicio if (idUsuario != null) { clienteNew = 127 | * this.clienteService.createCliente(cliente, idUsuario); 128 | * 129 | * response.put("mensaje", "Cliente creado con éxito, con el ID " + 130 | * clienteNew.getIdCliente()); response.put("Cliente", clienteNew); return new 131 | * ResponseEntity>(response, HttpStatus.CREATED); } else { 132 | * response.put("mensaje", 133 | * "Error: Falta el ID de usuario en el clienteDto enviado"); return new 134 | * ResponseEntity>(response, HttpStatus.BAD_REQUEST); } } 135 | * catch (DataAccessException e) { response.put("mensaje", 136 | * "Error al realizar el insert en la base de datos"); response.put("error", 137 | * e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 138 | * return new ResponseEntity>(response, 139 | * HttpStatus.INTERNAL_SERVER_ERROR); } } 140 | */ 141 | 142 | // Modificar 143 | @PutMapping("/clientes/{id}") 144 | public ResponseEntity modify(@PathVariable Long id, @RequestBody ClienteDto cliente) { 145 | Cliente clienteNew = null; 146 | Map response = new HashMap<>(); 147 | 148 | try { 149 | clienteNew = this.clienteService.updateCliente(id, cliente); 150 | } catch (DataAccessException e) { 151 | response.put("mensaje", "Error al realizar el update en base de datos"); 152 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 153 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 154 | } 155 | 156 | response.put("mensaje", "Cliente modificado con éxito, con el ID " + clienteNew.getIdCliente()); 157 | response.put("cliente", clienteNew); 158 | return new ResponseEntity>(response, HttpStatus.CREATED); 159 | } 160 | 161 | // crear Cliente 162 | // registrar usuario cliente 163 | // @PostMapping("/registroUsuarioCliente") 164 | @PostMapping("/clientes") 165 | public ResponseEntity registrarUsuarioYCliente(@RequestBody RegistroUsuarioClienteDto registroDto) { 166 | Map response = new HashMap<>(); 167 | 168 | try { 169 | ResponseEntity registroUsuarioResponse = usuarioService 170 | .registrarUsuario(registroDto.getUsuario(), "CLIENTE"); 171 | RegistroResponseDto usuarioResponse = registroUsuarioResponse.getBody(); 172 | 173 | // Verificar si el ID de usuario no es nulo 174 | if (usuarioResponse != null && usuarioResponse.getIdUsuario() != null) { 175 | // Crear el cliente y asociarle el ID del usuario 176 | Long idUsuario = usuarioResponse.getIdUsuario(); 177 | Cliente nuevoCliente = clienteService.createCliente(registroDto.getCliente(), idUsuario); 178 | 179 | response.put("mensaje", "Usuario y cliente creados con éxito"); 180 | response.put("Usuario", usuarioResponse); 181 | response.put("Cliente", nuevoCliente); 182 | return new ResponseEntity>(response, HttpStatus.CREATED); 183 | } else { 184 | response.put("mensaje", "Error al obtener el ID de usuario desde la respuesta"); 185 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 186 | } 187 | } catch (DataAccessException e) { 188 | response.put("mensaje", "Error al realizar la operación en la base de datos"); 189 | response.put("error", e.getMessage().concat(e.getMostSpecificCause().getLocalizedMessage())); 190 | return new ResponseEntity>(response, HttpStatus.INTERNAL_SERVER_ERROR); 191 | } 192 | } 193 | 194 | // Eliminar cliente 195 | @DeleteMapping("/clientes/{id}") 196 | public ResponseEntity eliminarCliente(@PathVariable Long id) { 197 | try { 198 | clienteService.deleteCliente(id); 199 | return new ResponseEntity<>("Cliente eliminado exitosamente", HttpStatus.OK); 200 | } catch (Error e) { 201 | return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND); 202 | } 203 | } 204 | 205 | // Endpoint para buscar clientes por nombre, apellido paterno, apellido materno o teléfono 206 | @GetMapping("/clientes/buscar") 207 | public List buscarClientes(@RequestParam String searchTerm) { 208 | return clienteService.buscarClientesPorNombreApellidoPaternoApellidoMaternoTelefono(searchTerm); 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /src/main/resources/modelosAutos.csv: -------------------------------------------------------------------------------- 1 | id_modelo,marca_id,modelo 2 | 1,1,INTEGRA 3 | 2,1,Mdx 4 | 3,1,NSX 5 | 4,1,Rdx 6 | 5,1,TLX 7 | 6,2,Giulia 8 | 7,2,Stelvio 9 | 8,2,TONALE 10 | 9,3,A1* 11 | 10,3,A3- 12 | 11,3,A4 13 | 12,3,A5 Coupe 14 | 13,3,A5 Sportback 15 | 14,3,A6 16 | 15,3,A7 17 | 16,3,A8 18 | 17,3,e-tron 19 | 18,3,Q 3 20 | 19,3,Q2 21 | 20,3,Q3 SB 22 | 21,3,Q5 23 | 22,3,Q7- 24 | 23,3,Q8 25 | 24,3,R8 26 | 25,4,Bentayga 27 | 26,5,iX 28 | 27,5,iX1 29 | 28,5,iX3 30 | 29,5,i4 31 | 30,5,i5 32 | 31,5,Serie 1 Hatch 33 | 32,5,Serie 2 34 | 33,5,Serie 3 35 | 34,5,Serie 4 36 | 35,5,Serie 5 37 | 36,5,Serie 7 38 | 37,5,Serie 8 39 | 38,5,XM 40 | 39,5,X1 41 | 40,5,X2 42 | 41,5,X3 43 | 42,5,X4 44 | 43,5,X5 45 | 44,5,X6 46 | 45,5,X7 47 | 46,5,Z4- 48 | 47,6,Arrizo 8 49 | 48,6,Tiggo 2 50 | 49,6,Tiggo 4 51 | 50,6,Tiggo 7 52 | 51,6,Tiggo 8 53 | 52,6,Tiggo 8 Pro e+ 54 | 53,7,Attitude 55 | 54,7,Challenger 56 | 55,7,Charger 57 | 56,7,Crew Cab- 58 | 57,7,Durango 59 | 58,7,Grand Cherokee 60 | 59,7,Jeep Compass 61 | 60,7,Jeep Compass- 62 | 61,7,Journey 63 | 62,7,JT 64 | 63,7,Promaster 65 | 64,7,Promaster Rapid 66 | 65,7,RAM 4000 67 | 66,7,RAM 700 68 | 67,7,Renegade 69 | 68,7,Wagoneer 70 | 69,7,Wrangler 71 | 70,8,Argo 72 | 71,8,Ducato 73 | 72,8,FASTBACK 74 | 73,8,Mobi 75 | 74,8,Pulse 76 | 75,9,Bronco 77 | 76,9,Bronco Sport 78 | 77,9,Edge 79 | 78,9,Escape HEV 80 | 79,9,E-Transit 81 | 80,9,Expedition 82 | 81,9,Explorer 83 | 82,9,F 250 Super Duty 84 | 83,9,F-350 85 | 84,9,F-450 86 | 85,9,F-550 87 | 86,9,Lobo Crew Cab 88 | 87,9,Maverick 89 | 88,9,Mustang 90 | 89,9,Mustang Mach-E 91 | 90,9,New F150 / F-150 92 | 91,9,Ranger 93 | 92,9,Territory 94 | 93,9,Transit 95 | 94,9,Transit Courier 96 | 95,10,Acadia 97 | 96,10,Ats 4p 98 | 97,10,Avalanche UUV 99 | 98,10,Aveo 100 | 99,10,Aveo- 101 | 100,10,Aveo HB 102 | 101,10,Beat 103 | 102,10,Beat 4 PTAS. 104 | 103,10,Blazer 105 | 104,10,Bolt 106 | 105,10,Bolt EUV 107 | 106,10,Camaro 108 | 107,10,Camaro Convertible 109 | 108,10,Canyon Crew Cab 4x4 110 | 109,10,Captiva Sport 111 | 110,10,Captiva SUV 112 | 111,10,Cavalier 4 Ptas 113 | 112,10,Chevrolet Express Cargo Van 114 | 113,10,Chevrolet Express Cutaway 115 | 114,10,Chevrolet Express Passenger Van 116 | 115,10,Chevy 3 Ptas 117 | 116,10,Chevy 4 PTAS 118 | 117,10,Cheyenne Doble Cabina 119 | 118,10,Cheyenne Cabina Regular 120 | 119,10,Cheyenne Doble Cabina 121 | 120,10,Colorado Doble Cabina 122 | 121,10,Corvette 123 | 122,10,Corvette 2 Pts. Convertible 124 | 123,10,Cruze 4 PTAS- 125 | 124,10,Cruze 4 Ptas 126 | 125,10,Cruze 5 Ptas 127 | 126,10,Cts 2 Ptas 128 | 127,10,Cts 4 Ptas 129 | 128,10,Enclave 130 | 129,10,Encore 131 | 130,10,Envision SUV 132 | 131,10,Envista SUV 133 | 132,10,Epica 134 | 133,10,Equinox EV 135 | 134,10,Equinox SUV- 136 | 135,10,Equinox Suv 137 | 136,10,Escalade ESV SUV AWD 138 | 137,10,Escalade ESV SUV AWD 139 | 138,10,Escalade EXT UUV 4X4 140 | 139,10,Escalade Suv 141 | 140,10,GMC Sierra Cabina Regular 142 | 141,10,GMC Sierra Doble Cabina 143 | 142,10,Groove SUV 144 | 143,10,"Kodiak Chassis Cab Class 7 PBV33,000" 145 | 144,10,Lacrosse 146 | 145,10,Lyriq SUV 147 | 146,10,Malibu 4 Ptas 148 | 147,10,Matiz 5 Ptas 149 | 148,10,Montana Crew Cab 150 | 149,10,Onix 151 | 150,10,Onix 152 | 151,10,Regal 153 | 152,10,Sierra Cabina Regular 154 | 153,10,Sierra Doble Cabina 155 | 154,10,Sierra Doble Cabina 156 | 155,10,Silverado Cabina Regular 157 | 156,10,Silverado Cabina Regular 158 | 157,10,Silverado Doble Cabina 159 | 158,10,Silverado 1500 Cabina Regular 160 | 159,10,Silverado 1500 Cabina Regular- 161 | 160,10,Silverado 2500 Cabina Extendida 162 | 161,10,Silverado 2500 Cabina Regular 163 | 162,10,Silverado 2500 Cabina Regular- 164 | 163,10,Silverado 2500 Doble Cabina- 165 | 164,10,Silverado 3500 Chassis Cab 166 | 165,10,Silverado 3500 HD Chassis Cab Heavy Duty 167 | 166,10,Sonic- 168 | 167,10,Sonic 5 PTS 169 | 168,10,Sonic 5 PTS- 170 | 169,10,Spark 171 | 170,10,Spark EV 5 Ptas. 172 | 171,10,Spark NG 173 | 172,10,SRX SUV- 174 | 173,10,Suburban Suv 175 | 174,10,S10 176 | 175,10,S10 Max Cabina Regular 177 | 176,10,S10 Max Chassis 178 | 177,10,S10 Max Doble Cabina 179 | 178,10,Tahoe 180 | 179,10,Terrain SUV- 181 | 180,10,Terrain Suv 182 | 181,10,Tornado Pickup 183 | 182,10,Tornado Van 184 | 183,10,Tracker 185 | 184,10,Traverse Suv 186 | 185,10,Trax 187 | 186,10,Verano 188 | 187,10,Volt 4 Ptas. 189 | 188,10,Xt4 Suv 190 | 189,10,XT5 SUV 191 | 190,10,Yukon Suv 192 | 191,10,Yukon XL 193 | 192,11,Accord- 194 | 193,11,BR-V 195 | 194,11,Civic 196 | 195,11,CR-V 197 | 196,11,Honda City 198 | 197,11,Honda Pilot 199 | 198,11,HR-V- 200 | 199,11,Insight Hybrid 201 | 200,11,Odyssey 202 | 201,12,Accent Hatchback 203 | 202,12,Accent Sedan 204 | 203,12,Creta 205 | 204,12,Elantra 206 | 205,12,Genesis 207 | 206,12,Grand I10 208 | 207,12,Grand I10 Sedán 209 | 208,12,HB20 HATCHBACK 210 | 209,12,HB20 SEDAN 211 | 210,12,Ioniq 212 | 211,12,IX35 213 | 212,12,Palisade 214 | 213,12,Santa Fe 215 | 214,12,Santa FE 7 P 216 | 215,12,Sonata 217 | 216,12,Starex 218 | 217,12,Tucson 219 | 218,12,Veloster 220 | 219,13,Infiniti 221 | 220,13,QX30 222 | 221,13,QX50 223 | 222,13,QX55 224 | 223,13,QX60 225 | 224,13,QX70 226 | 225,13,QX80 227 | 226,13,Q50 228 | 227,13,Q60 229 | 228,13,Q70 230 | 229,14,ELF 200 231 | 230,14,ELF 300 232 | 231,14,ELF100 233 | 232,15,E J7 234 | 233,15,E SUNRAY 235 | 234,15,E Sunray City 236 | 235,15,E X350 237 | 236,15,E 10X 238 | 237,15,ESei4 Pro 239 | 238,15,Frison 240 | 239,15,J7 241 | 240,15,Sei2 242 | 241,15,Sei4 Pro 243 | 242,15,Sei6 Pro 244 | 243,15,SEI7 PRO 245 | 244,15,SUNRAY 246 | 245,15,X 200 247 | 246,15,X250 248 | 247,15,X350 249 | 248,16,F-Pace 250 | 249,16,F-Type 251 | 250,17,EV6 252 | 251,17,Forte 253 | 252,17,Forte- 254 | 253,17,Forte Hatchback 255 | 254,17,KIA K3 Hatchback 256 | 255,17,KIA K3 Sedán 257 | 256,17,KIA Niro 258 | 257,17,Kia Río Hatchback- 259 | 258,17,KIA Río Sedan- 260 | 259,17,Seltos 261 | 260,17,Seltos- 262 | 261,17,Sorento 263 | 262,17,Soul 264 | 263,17,SPORTAGE 265 | 264,17,Stinger 266 | 265,18,Defender 267 | 266,18,Discovery Sport 268 | 267,18,Range Rover 269 | 268,18,Range Rover Evoque 270 | 269,18,Range Rover Sport 271 | 270,18,Range Rover Velar 272 | 271,19,ES 273 | 272,19,IS 274 | 273,19,LC 275 | 274,19,LS 276 | 275,19,LX 277 | 276,19,NX 278 | 277,19,RX 279 | 278,19,TX 280 | 279,19,UX 281 | 280,20,AVIATOR 282 | 281,20,Aviator Grand Touring 283 | 282,20,Corsair 284 | 283,20,NAUTILUS 285 | 284,20,Navigator 286 | 285,21,CX-3 287 | 286,21,CX-3 288 | 287,21,CX-30 289 | 288,21,CX-5 290 | 289,21,CX-50 291 | 290,21,Cx-7 292 | 291,21,CX-9 293 | 292,21,CX-90 294 | 293,21,Mazda 2 295 | 294,21,Mazda 2 Hatchback 296 | 295,21,Mazda 2 Sedán 297 | 296,21,Mazda 3 Hatchback 298 | 297,21,Mazda 3 Hatchback 299 | 298,21,Mazda 3 Sedán 300 | 299,21,Mazda 3 Sedán- 301 | 300,21,Mazda 5 302 | 301,21,Mazda 6 303 | 302,21,Mx-5 304 | 303,22,AMG GT 305 | 304,22,CLA 306 | 305,22,Clase A hatchback 307 | 306,22,Clase A Sedan 308 | 307,22,Clase C coupe 309 | 308,22,Clase C Sedan 310 | 309,22,Clase E coupe 311 | 310,22,Clase E sedan 312 | 311,22,Clase G 313 | 312,22,Clase GLE 314 | 313,22,Clase GLS 315 | 314,22,Clase S coupe 316 | 315,22,Clase S sedan 317 | 316,22,Clase SL 318 | 317,22,Clase V 319 | 318,22,CLS 320 | 319,22,EQA 321 | 320,22,EQB 322 | 321,22,EQC 323 | 322,22,EQE 324 | 323,22,EQE SUV 325 | 324,22,EQS 326 | 325,22,EQS SUV 327 | 326,22,GLA 328 | 327,22,GLB 329 | 328,22,GLC 330 | 329,22,SLC 331 | 330,22,Sprinter 332 | 331,23,eHS 333 | 332,23,GT 334 | 333,23,HS 335 | 334,23,MG One 336 | 335,23,MG5 337 | 336,23,RX5 338 | 337,23,RX8 339 | 338,23,ZS 340 | 339,23,ZSEV 341 | 340,24,MINI CLUBMAN 342 | 341,24,MINI CONVERTIBLE 343 | 342,24,MINI COUNTRYMAN 344 | 343,24,MINI E 345 | 344,24,MINI 3 PTAS 346 | 345,24,MINI 5 PTAS 347 | 346,25,L200 348 | 347,25,Mirage G4 349 | 348,25,Montero Sport 350 | 349,25,Outlander PHEV 351 | 350,25,Xpander 352 | 351,26,BAIC BJ40 353 | 352,26,BAIC D20 354 | 353,26,BAIC X35 355 | 354,26,BAIC X55 356 | 355,26,CHANGAN ALSVIN 357 | 356,26,CHANGAN CS35PLUS 358 | 357,26,CHANGAN CS55PLUS 359 | 358,26,CHANGAN UNI-K 360 | 359,26,DFSK E5 361 | 360,26,DFSK 500 362 | 361,26,DFSK 600 363 | 362,26,JMC VIGUS 364 | 363,27,Altima 365 | 364,27,Armada 366 | 365,27,Cabstar Mediano 367 | 366,27,Frontier V6 368 | 367,27,GT-R 369 | 368,27,Juke 370 | 369,27,Kicks 371 | 370,27,Leaf 372 | 371,27,March 373 | 372,27,Maxima 374 | 373,27,Murano 375 | 374,27,Note 376 | 375,27,NP300 377 | 376,27,NV 200 Cargo 378 | 377,27,NV 200 NY TAXI 379 | 378,27,NV2500 V6 Toldo Alto 380 | 379,27,Pathfinder 381 | 380,27,Sentra 382 | 381,27,Tiida Sedan 383 | 382,27,Titan 384 | 383,27,Urvan Panel 385 | 384,27,Urvan Pasajeros 386 | 385,27,Versa 387 | 386,27,Xtrail 388 | 387,27,Z 389 | 388,27,370 Z 390 | 389,28,C5 391 | 390,28,O5 392 | 391,29,E-Partner 393 | 392,29,Expert Cargo Van 394 | 393,29,LANDTREK 395 | 394,29,Manager Hdi 396 | 395,29,Partner 397 | 396,29,RIFTER 398 | 397,29,2008 399 | 398,29,3008 400 | 399,30,Cayenne 401 | 400,30,Cayman 402 | 401,30,Macan 403 | 402,30,Panamera 404 | 403,30,Taycan 405 | 404,30,718 Boxster 406 | 405,30,911 Carrera / Turbo / GT 407 | 406,31,Duster 408 | 407,31,Kangoo 409 | 408,31,Koleos 410 | 409,31,Kwid 411 | 410,31,Kwid e-Tech 412 | 411,31,Logan 413 | 412,31,Oroch 414 | 413,31,Stepway 415 | 414,32,Arona 416 | 415,32,Ateca 417 | 416,32,CUPRA Formentor 418 | 417,32,Ibiza 4 Ptas 419 | 418,32,Leon 420 | 419,32,Tarraco 421 | 420,33,Crosstrek 422 | 421,33,Crosstrek MHEV 423 | 422,33,Forester 424 | 423,33,Outback 425 | 424,33,Subaru BRZ 426 | 425,33,WRX 427 | 426,33,WRX STI 428 | 427,33,XV 429 | 428,34,Baleno 430 | 429,34,Ciaz 431 | 430,34,Ertiga 432 | 431,34,FRONX 433 | 432,34,Grand Vitara 434 | 433,34,Ignis 435 | 434,34,JIMNY 436 | 435,34,S Cross 437 | 436,34,Swift 438 | 437,35,Avanza 439 | 438,35,Camry 440 | 439,35,C-HR 441 | 440,35,Corolla 442 | 441,35,Corolla Cross 443 | 442,35,GR Supra 444 | 443,35,GR Yaris 445 | 444,35,Hiace P 446 | 445,35,Hiace V 447 | 446,35,Highlander 448 | 447,35,Hilux Dc 449 | 448,35,Lcruiser 450 | 449,35,Prius 451 | 450,35,Prius-C 452 | 451,35,RAIZE 453 | 452,35,Rav4 454 | 453,35,Sequoia 455 | 454,35,Sienna 456 | 455,35,Tacoma 457 | 456,35,Tacoma- 458 | 457,35,Tundra 459 | 458,35,Yaris Hatchback 460 | 459,35,Yaris Sedan 461 | 460,35,Yaris-R 462 | 461,36,Amarok 463 | 462,36,Beetle 464 | 463,36,Beetle Cabrio 465 | 464,36,Crafter 466 | 465,36,Crafter chasis 467 | 466,36,Cross Sport 468 | 467,36,Crossfox 469 | 468,36,e-Crafter 470 | 469,36,Gol 471 | 470,36,Gol Sedan 472 | 471,36,Golf 473 | 472,36,Golf- 474 | 473,36,Golf Variant-/Crossgolf 475 | 474,36,GTI 476 | 475,36,Jetta 477 | 476,36,Nivus 478 | 477,36,Nuevo Jetta 479 | 478,36,Nuevo Jetta TDI 480 | 479,36,Passat 481 | 480,36,Polo 4 Ptas 482 | 481,36,Polo 4 Ptas 483 | 482,36,Saveiro 484 | 483,36,Taigun 485 | 484,36,Taos 486 | 485,36,T-Cross 487 | 486,36,Teramont 488 | 487,36,Tiguan- 489 | 488,36,Touareg 490 | 489,36,Transporter Carga 491 | 490,36,Transporter Pasajeros 492 | 491,36,UP! 493 | 492,36,Vento 494 | 493,36,Virtus 495 | 494,36,Volkswagen Caddy 496 | 495,37,C40 497 | 496,37,XC40 498 | 497,37,XC60 II 499 | 498,37,XC90 II 500 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Apache Maven Wrapper startup batch script, version 3.2.0 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | # e.g. to debug Maven itself, use 32 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | # ---------------------------------------------------------------------------- 35 | 36 | if [ -z "$MAVEN_SKIP_RC" ] ; then 37 | 38 | if [ -f /usr/local/etc/mavenrc ] ; then 39 | . /usr/local/etc/mavenrc 40 | fi 41 | 42 | if [ -f /etc/mavenrc ] ; then 43 | . /etc/mavenrc 44 | fi 45 | 46 | if [ -f "$HOME/.mavenrc" ] ; then 47 | . "$HOME/.mavenrc" 48 | fi 49 | 50 | fi 51 | 52 | # OS specific support. $var _must_ be set to either true or false. 53 | cygwin=false; 54 | darwin=false; 55 | mingw=false 56 | case "$(uname)" in 57 | CYGWIN*) cygwin=true ;; 58 | MINGW*) mingw=true;; 59 | Darwin*) darwin=true 60 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 61 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 62 | if [ -z "$JAVA_HOME" ]; then 63 | if [ -x "/usr/libexec/java_home" ]; then 64 | JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME 65 | else 66 | JAVA_HOME="/Library/Java/Home"; export JAVA_HOME 67 | fi 68 | fi 69 | ;; 70 | esac 71 | 72 | if [ -z "$JAVA_HOME" ] ; then 73 | if [ -r /etc/gentoo-release ] ; then 74 | JAVA_HOME=$(java-config --jre-home) 75 | fi 76 | fi 77 | 78 | # For Cygwin, ensure paths are in UNIX format before anything is touched 79 | if $cygwin ; then 80 | [ -n "$JAVA_HOME" ] && 81 | JAVA_HOME=$(cygpath --unix "$JAVA_HOME") 82 | [ -n "$CLASSPATH" ] && 83 | CLASSPATH=$(cygpath --path --unix "$CLASSPATH") 84 | fi 85 | 86 | # For Mingw, ensure paths are in UNIX format before anything is touched 87 | if $mingw ; then 88 | [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] && 89 | JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)" 90 | fi 91 | 92 | if [ -z "$JAVA_HOME" ]; then 93 | javaExecutable="$(which javac)" 94 | if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then 95 | # readlink(1) is not available as standard on Solaris 10. 96 | readLink=$(which readlink) 97 | if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then 98 | if $darwin ; then 99 | javaHome="$(dirname "\"$javaExecutable\"")" 100 | javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac" 101 | else 102 | javaExecutable="$(readlink -f "\"$javaExecutable\"")" 103 | fi 104 | javaHome="$(dirname "\"$javaExecutable\"")" 105 | javaHome=$(expr "$javaHome" : '\(.*\)/bin') 106 | JAVA_HOME="$javaHome" 107 | export JAVA_HOME 108 | fi 109 | fi 110 | fi 111 | 112 | if [ -z "$JAVACMD" ] ; then 113 | if [ -n "$JAVA_HOME" ] ; then 114 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 115 | # IBM's JDK on AIX uses strange locations for the executables 116 | JAVACMD="$JAVA_HOME/jre/sh/java" 117 | else 118 | JAVACMD="$JAVA_HOME/bin/java" 119 | fi 120 | else 121 | JAVACMD="$(\unset -f command 2>/dev/null; \command -v java)" 122 | fi 123 | fi 124 | 125 | if [ ! -x "$JAVACMD" ] ; then 126 | echo "Error: JAVA_HOME is not defined correctly." >&2 127 | echo " We cannot execute $JAVACMD" >&2 128 | exit 1 129 | fi 130 | 131 | if [ -z "$JAVA_HOME" ] ; then 132 | echo "Warning: JAVA_HOME environment variable is not set." 133 | fi 134 | 135 | # traverses directory structure from process work directory to filesystem root 136 | # first directory with .mvn subdirectory is considered project base directory 137 | find_maven_basedir() { 138 | if [ -z "$1" ] 139 | then 140 | echo "Path not specified to find_maven_basedir" 141 | return 1 142 | fi 143 | 144 | basedir="$1" 145 | wdir="$1" 146 | while [ "$wdir" != '/' ] ; do 147 | if [ -d "$wdir"/.mvn ] ; then 148 | basedir=$wdir 149 | break 150 | fi 151 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 152 | if [ -d "${wdir}" ]; then 153 | wdir=$(cd "$wdir/.." || exit 1; pwd) 154 | fi 155 | # end of workaround 156 | done 157 | printf '%s' "$(cd "$basedir" || exit 1; pwd)" 158 | } 159 | 160 | # concatenates all lines of a file 161 | concat_lines() { 162 | if [ -f "$1" ]; then 163 | # Remove \r in case we run on Windows within Git Bash 164 | # and check out the repository with auto CRLF management 165 | # enabled. Otherwise, we may read lines that are delimited with 166 | # \r\n and produce $'-Xarg\r' rather than -Xarg due to word 167 | # splitting rules. 168 | tr -s '\r\n' ' ' < "$1" 169 | fi 170 | } 171 | 172 | log() { 173 | if [ "$MVNW_VERBOSE" = true ]; then 174 | printf '%s\n' "$1" 175 | fi 176 | } 177 | 178 | BASE_DIR=$(find_maven_basedir "$(dirname "$0")") 179 | if [ -z "$BASE_DIR" ]; then 180 | exit 1; 181 | fi 182 | 183 | MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR 184 | log "$MAVEN_PROJECTBASEDIR" 185 | 186 | ########################################################################################## 187 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 188 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 189 | ########################################################################################## 190 | wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" 191 | if [ -r "$wrapperJarPath" ]; then 192 | log "Found $wrapperJarPath" 193 | else 194 | log "Couldn't find $wrapperJarPath, downloading it ..." 195 | 196 | if [ -n "$MVNW_REPOURL" ]; then 197 | wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" 198 | else 199 | wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" 200 | fi 201 | while IFS="=" read -r key value; do 202 | # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' ) 203 | safeValue=$(echo "$value" | tr -d '\r') 204 | case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;; 205 | esac 206 | done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" 207 | log "Downloading from: $wrapperUrl" 208 | 209 | if $cygwin; then 210 | wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") 211 | fi 212 | 213 | if command -v wget > /dev/null; then 214 | log "Found wget ... using wget" 215 | [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" 216 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 217 | wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 218 | else 219 | wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 220 | fi 221 | elif command -v curl > /dev/null; then 222 | log "Found curl ... using curl" 223 | [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" 224 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 225 | curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" 226 | else 227 | curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" 228 | fi 229 | else 230 | log "Falling back to using Java to download" 231 | javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" 232 | javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" 233 | # For Cygwin, switch paths to Windows format before running javac 234 | if $cygwin; then 235 | javaSource=$(cygpath --path --windows "$javaSource") 236 | javaClass=$(cygpath --path --windows "$javaClass") 237 | fi 238 | if [ -e "$javaSource" ]; then 239 | if [ ! -e "$javaClass" ]; then 240 | log " - Compiling MavenWrapperDownloader.java ..." 241 | ("$JAVA_HOME/bin/javac" "$javaSource") 242 | fi 243 | if [ -e "$javaClass" ]; then 244 | log " - Running MavenWrapperDownloader.java ..." 245 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" 246 | fi 247 | fi 248 | fi 249 | fi 250 | ########################################################################################## 251 | # End of extension 252 | ########################################################################################## 253 | 254 | # If specified, validate the SHA-256 sum of the Maven wrapper jar file 255 | wrapperSha256Sum="" 256 | while IFS="=" read -r key value; do 257 | case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;; 258 | esac 259 | done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" 260 | if [ -n "$wrapperSha256Sum" ]; then 261 | wrapperSha256Result=false 262 | if command -v sha256sum > /dev/null; then 263 | if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then 264 | wrapperSha256Result=true 265 | fi 266 | elif command -v shasum > /dev/null; then 267 | if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then 268 | wrapperSha256Result=true 269 | fi 270 | else 271 | echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." 272 | echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." 273 | exit 1 274 | fi 275 | if [ $wrapperSha256Result = false ]; then 276 | echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 277 | echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 278 | echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 279 | exit 1 280 | fi 281 | fi 282 | 283 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 284 | 285 | # For Cygwin, switch paths to Windows format before running java 286 | if $cygwin; then 287 | [ -n "$JAVA_HOME" ] && 288 | JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") 289 | [ -n "$CLASSPATH" ] && 290 | CLASSPATH=$(cygpath --path --windows "$CLASSPATH") 291 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 292 | MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") 293 | fi 294 | 295 | # Provide a "standardized" way to retrieve the CLI args that will 296 | # work with both Windows and non-Windows executions. 297 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*" 298 | export MAVEN_CMD_LINE_ARGS 299 | 300 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 301 | 302 | # shellcheck disable=SC2086 # safe args 303 | exec "$JAVACMD" \ 304 | $MAVEN_OPTS \ 305 | $MAVEN_DEBUG_OPTS \ 306 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 307 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 308 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 309 | --------------------------------------------------------------------------------