├── Biblioteca_V1 ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── egg │ │ │ └── biblioteca │ │ │ ├── BibliotecaApplication.java │ │ │ ├── entidades │ │ │ ├── Autor.java │ │ │ ├── Editorial.java │ │ │ └── Libro.java │ │ │ ├── excepciones │ │ │ └── MiException.java │ │ │ ├── repositorios │ │ │ ├── AutorRepositorio.java │ │ │ ├── EditorialRepositorio.java │ │ │ └── LibroRepositorio.java │ │ │ └── servicios │ │ │ ├── AutorServicio.java │ │ │ ├── EditorialServicio.java │ │ │ └── LibroServicio.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── egg │ └── biblioteca │ └── BibliotecaApplicationTests.java ├── Biblioteca_V2 ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── egg │ │ │ └── biblioteca │ │ │ ├── BibliotecaApplication.java │ │ │ ├── controladores │ │ │ ├── AutorControlador.java │ │ │ ├── EditorialControlador.java │ │ │ ├── LibroControlador.java │ │ │ └── PortalControlador.java │ │ │ ├── entidades │ │ │ ├── Autor.java │ │ │ ├── Editorial.java │ │ │ └── Libro.java │ │ │ ├── excepciones │ │ │ └── MiException.java │ │ │ ├── repositorios │ │ │ ├── AutorRepositorio.java │ │ │ ├── EditorialRepositorio.java │ │ │ └── LibroRepositorio.java │ │ │ └── servicios │ │ │ ├── AutorServicio.java │ │ │ ├── EditorialServicio.java │ │ │ └── LibroServicio.java │ └── resources │ │ ├── application.properties │ │ ├── static │ │ ├── css │ │ │ ├── formulario.css │ │ │ ├── index.css │ │ │ └── inicio.css │ │ └── img │ │ │ ├── Egg.png │ │ │ ├── FondoZoom.jpg │ │ │ ├── FondoZoom_1.jpg │ │ │ ├── FondoZoom_2.jpg │ │ │ ├── imgEgg.png │ │ │ └── imgEggBlanco.jpg │ │ └── templates │ │ ├── autor_form.html │ │ ├── autor_list.html │ │ ├── autor_modificar.html │ │ ├── editorial_form.html │ │ ├── editorial_list.html │ │ ├── index.html │ │ ├── libro_form.html │ │ ├── libro_list.html │ │ └── libro_modificar.html │ └── test │ └── java │ └── com │ └── egg │ └── biblioteca │ └── BibliotecaApplicationTests.java ├── Biblioteca_V3 ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── egg │ │ │ └── biblioteca │ │ │ ├── BibliotecaApplication.java │ │ │ ├── SeguridadWeb.java │ │ │ ├── controladores │ │ │ ├── AdminControlador.java │ │ │ ├── AutorControlador.java │ │ │ ├── EditorialControlador.java │ │ │ ├── LibroControlador.java │ │ │ └── PortalControlador.java │ │ │ ├── entidades │ │ │ ├── Autor.java │ │ │ ├── Editorial.java │ │ │ ├── Libro.java │ │ │ └── Usuario.java │ │ │ ├── enumeraciones │ │ │ └── Rol.java │ │ │ ├── excepciones │ │ │ └── MiException.java │ │ │ ├── repositorios │ │ │ ├── AutorRepositorio.java │ │ │ ├── EditorialRepositorio.java │ │ │ ├── LibroRepositorio.java │ │ │ └── UsuarioRepositorio.java │ │ │ └── servicios │ │ │ ├── AutorServicio.java │ │ │ ├── EditorialServicio.java │ │ │ ├── LibroServicio.java │ │ │ └── UsuarioServicio.java │ └── resources │ │ ├── application.properties │ │ ├── static │ │ ├── css │ │ │ ├── formulario.css │ │ │ ├── index.css │ │ │ └── inicio.css │ │ └── img │ │ │ ├── Egg.png │ │ │ ├── FondoZoom.jpg │ │ │ ├── FondoZoom_1.jpg │ │ │ ├── FondoZoom_2.jpg │ │ │ ├── imgEgg.png │ │ │ └── imgEggBlanco.jpg │ │ └── templates │ │ ├── autor_form.html │ │ ├── autor_list.html │ │ ├── autor_modificar.html │ │ ├── editorial_form.html │ │ ├── fragments │ │ ├── head.html │ │ └── navbar.html │ │ ├── index.html │ │ ├── inicio.html │ │ ├── libro_form.html │ │ ├── libro_list.html │ │ ├── libro_modificar.html │ │ ├── login.html │ │ └── registro.html │ └── test │ └── java │ └── com │ └── egg │ └── biblioteca │ └── BibliotecaApplicationTests.java ├── Biblioteca_V4 ├── .gitignore ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── egg │ │ │ └── biblioteca │ │ │ ├── BibliotecaApplication.java │ │ │ ├── SeguridadWeb.java │ │ │ ├── controladores │ │ │ ├── AdminControlador.java │ │ │ ├── AutorControlador.java │ │ │ ├── EditorialControlador.java │ │ │ ├── ErroresControlador.java │ │ │ ├── ImagenControlador.java │ │ │ ├── LibroControlador.java │ │ │ └── PortalControlador.java │ │ │ ├── entidades │ │ │ ├── Autor.java │ │ │ ├── Editorial.java │ │ │ ├── Imagen.java │ │ │ ├── Libro.java │ │ │ └── Usuario.java │ │ │ ├── enumeraciones │ │ │ └── Rol.java │ │ │ ├── excepciones │ │ │ └── MiException.java │ │ │ ├── repositorios │ │ │ ├── AutorRepositorio.java │ │ │ ├── EditorialRepositorio.java │ │ │ ├── ImagenRepositorio.java │ │ │ ├── LibroRepositorio.java │ │ │ └── UsuarioRepositorio.java │ │ │ └── servicios │ │ │ ├── AutorServicio.java │ │ │ ├── EditorialServicio.java │ │ │ ├── ImagenServicio.java │ │ │ ├── LibroServicio.java │ │ │ └── UsuarioServicio.java │ └── resources │ │ ├── application.properties │ │ ├── static │ │ ├── css │ │ │ ├── formulario.css │ │ │ ├── index.css │ │ │ └── inicio.css │ │ └── img │ │ │ ├── Egg.png │ │ │ ├── FondoZoom.jpg │ │ │ ├── FondoZoom_1.jpg │ │ │ ├── FondoZoom_2.jpg │ │ │ ├── imgEgg.png │ │ │ └── imgEggBlanco.jpg │ │ └── templates │ │ ├── autor_form.html │ │ ├── autor_list.html │ │ ├── autor_modificar.html │ │ ├── editorial_form.html │ │ ├── error.html │ │ ├── fragments │ │ ├── head.html │ │ └── navbar.html │ │ ├── index.html │ │ ├── inicio.html │ │ ├── libro_form.html │ │ ├── libro_list.html │ │ ├── libro_modificar.html │ │ ├── login.html │ │ ├── panel.html │ │ ├── registro.html │ │ ├── usuario_list.html │ │ └── usuario_modificar.html │ └── test │ └── java │ └── com │ └── egg │ └── biblioteca │ └── BibliotecaApplicationTests.java └── readme.md /Biblioteca_V1/.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 | -------------------------------------------------------------------------------- /Biblioteca_V1/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V1/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Biblioteca_V1/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /Biblioteca_V1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.7 9 | 10 | 11 | com.egg 12 | biblioteca 13 | 0.0.1-SNAPSHOT 14 | Biblioteca_V1 15 | Proyecto de Biblioteca para Egg - Version 1. 16 | 17 | 1.8 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-data-jpa 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-thymeleaf 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | mysql 35 | mysql-connector-java 36 | runtime 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-maven-plugin 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /Biblioteca_V1/src/main/java/com/egg/biblioteca/BibliotecaApplication.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BibliotecaApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BibliotecaApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Biblioteca_V1/src/main/java/com/egg/biblioteca/entidades/Autor.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.entidades; 3 | 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | import org.hibernate.annotations.GenericGenerator; 8 | 9 | @Entity 10 | public class Autor { 11 | 12 | @Id 13 | @GeneratedValue(generator = "uuid") 14 | @GenericGenerator(name = "uuid", strategy = "uuid2") 15 | private String id; 16 | private String nombre; 17 | 18 | public Autor() { 19 | } 20 | 21 | public String getId() { 22 | return id; 23 | } 24 | 25 | public void setId(String id) { 26 | this.id = id; 27 | } 28 | 29 | public String getNombre() { 30 | return nombre; 31 | } 32 | 33 | public void setNombre(String nombre) { 34 | this.nombre = nombre; 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Biblioteca_V1/src/main/java/com/egg/biblioteca/entidades/Editorial.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.entidades; 3 | 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | import org.hibernate.annotations.GenericGenerator; 8 | 9 | @Entity 10 | public class Editorial { 11 | @Id 12 | @GeneratedValue(generator = "uuid") 13 | @GenericGenerator(name = "uuid", strategy = "uuid2") 14 | private String id; 15 | private String nombre; 16 | 17 | public Editorial() { 18 | } 19 | 20 | public String getId() { 21 | return id; 22 | } 23 | 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | 28 | public String getNombre() { 29 | return nombre; 30 | } 31 | 32 | public void setNombre(String nombre) { 33 | this.nombre = nombre; 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Biblioteca_V1/src/main/java/com/egg/biblioteca/entidades/Libro.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.entidades; 3 | 4 | import java.util.Date; 5 | import javax.persistence.Entity; 6 | import javax.persistence.Id; 7 | import javax.persistence.ManyToOne; 8 | import javax.persistence.Temporal; 9 | import javax.persistence.TemporalType; 10 | 11 | @Entity 12 | public class Libro { 13 | @Id 14 | private Long isbn; 15 | private String titulo; 16 | private Integer ejemplares; 17 | 18 | @Temporal(TemporalType.DATE) 19 | private Date alta; 20 | 21 | @ManyToOne 22 | private Autor autor; 23 | 24 | @ManyToOne 25 | private Editorial editorial; 26 | 27 | public Libro() { 28 | } 29 | 30 | public Long getIsbn() { 31 | return isbn; 32 | } 33 | 34 | public void setIsbn(Long isbn) { 35 | this.isbn = isbn; 36 | } 37 | 38 | public String getTitulo() { 39 | return titulo; 40 | } 41 | 42 | public void setTitulo(String titulo) { 43 | this.titulo = titulo; 44 | } 45 | 46 | public Integer getEjemplares() { 47 | return ejemplares; 48 | } 49 | 50 | public void setEjemplares(Integer ejemplares) { 51 | this.ejemplares = ejemplares; 52 | } 53 | 54 | public Date getAlta() { 55 | return alta; 56 | } 57 | 58 | public void setAlta(Date alta) { 59 | this.alta = alta; 60 | } 61 | 62 | public Autor getAutor() { 63 | return autor; 64 | } 65 | 66 | public void setAutor(Autor autor) { 67 | this.autor = autor; 68 | } 69 | 70 | public Editorial getEditorial() { 71 | return editorial; 72 | } 73 | 74 | public void setEditorial(Editorial editorial) { 75 | this.editorial = editorial; 76 | } 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /Biblioteca_V1/src/main/java/com/egg/biblioteca/excepciones/MiException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.excepciones; 3 | 4 | 5 | public class MiException extends Exception{ 6 | 7 | public MiException(String msg) { 8 | super(msg); 9 | } 10 | 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Biblioteca_V1/src/main/java/com/egg/biblioteca/repositorios/AutorRepositorio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.repositorios; 3 | 4 | import com.egg.biblioteca.entidades.Autor; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | @Repository 9 | public interface AutorRepositorio extends JpaRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Biblioteca_V1/src/main/java/com/egg/biblioteca/repositorios/EditorialRepositorio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.repositorios; 3 | 4 | import com.egg.biblioteca.entidades.Editorial; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | @Repository 9 | public interface EditorialRepositorio extends JpaRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Biblioteca_V1/src/main/java/com/egg/biblioteca/repositorios/LibroRepositorio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.repositorios; 3 | 4 | import com.egg.biblioteca.entidades.Libro; 5 | import java.util.List; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.data.repository.query.Param; 9 | import org.springframework.stereotype.Repository; 10 | 11 | @Repository 12 | public interface LibroRepositorio extends JpaRepository{ 13 | 14 | @Query("SELECT l FROM Libro l WHERE l.titulo = :titulo") 15 | public Libro buscarPorTitulo(@Param("titulo") String titulo); 16 | 17 | @Query("SELECT l FROM Libro l WHERE l.autor.nombre = :nombre") 18 | public List buscarPorAutor(@Param ("nombre") String nombre); 19 | } 20 | -------------------------------------------------------------------------------- /Biblioteca_V1/src/main/java/com/egg/biblioteca/servicios/AutorServicio.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.servicios; 2 | 3 | import com.egg.biblioteca.entidades.Autor; 4 | import com.egg.biblioteca.excepciones.MiException; 5 | import com.egg.biblioteca.repositorios.AutorRepositorio; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Optional; 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Transactional; 13 | 14 | @Service 15 | public class AutorServicio { 16 | 17 | @Autowired 18 | AutorRepositorio autorRepositorio; 19 | 20 | @Transactional 21 | public void crearAutor(String nombre) throws MiException{ 22 | 23 | validar(nombre); 24 | 25 | Autor autor = new Autor(); 26 | 27 | autor.setNombre(nombre); 28 | 29 | autorRepositorio.save(autor); 30 | 31 | } 32 | 33 | @Transactional(readOnly = true) 34 | public List listarAutores() { 35 | 36 | List autores = new ArrayList(); 37 | 38 | autores = autorRepositorio.findAll(); 39 | 40 | return autores; 41 | } 42 | 43 | @Transactional 44 | public void modificarAutor(String nombre, String id) throws MiException{ 45 | 46 | validar(nombre); 47 | 48 | Optional respuesta = autorRepositorio.findById(id); 49 | 50 | if (respuesta.isPresent()) { 51 | Autor autor = respuesta.get(); 52 | 53 | autor.setNombre(nombre); 54 | 55 | autorRepositorio.save(autor); 56 | 57 | } 58 | } 59 | 60 | @Transactional 61 | public void eliminar(String id) throws MiException{ 62 | 63 | Autor autor = autorRepositorio.getById(id); 64 | 65 | autorRepositorio.delete(autor); 66 | 67 | } 68 | 69 | private void validar(String nombre) throws MiException { 70 | 71 | if (nombre.isEmpty() || nombre == null) { 72 | throw new MiException("el nombre no puede ser nulo o estar vacio"); 73 | } 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /Biblioteca_V1/src/main/java/com/egg/biblioteca/servicios/EditorialServicio.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.servicios; 2 | 3 | import com.egg.biblioteca.entidades.Editorial; 4 | import com.egg.biblioteca.excepciones.MiException; 5 | import com.egg.biblioteca.repositorios.EditorialRepositorio; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Optional; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | @Service 14 | public class EditorialServicio { 15 | 16 | @Autowired 17 | EditorialRepositorio editorialRepositorio; 18 | 19 | @Transactional 20 | public void crearEditorial(String nombre) throws MiException{ 21 | 22 | validar(nombre); 23 | 24 | Editorial editorial = new Editorial(); 25 | 26 | editorial.setNombre(nombre); 27 | 28 | editorialRepositorio.save(editorial); 29 | } 30 | 31 | @Transactional(readOnly = true) 32 | public List listarEditoriales() { 33 | 34 | List editoriales = new ArrayList(); 35 | 36 | editoriales = editorialRepositorio.findAll(); 37 | 38 | return editoriales; 39 | } 40 | 41 | @Transactional 42 | public void modificarEditorial(String id, String nombre) throws MiException{ 43 | validar(nombre); 44 | 45 | Optional respuesta = editorialRepositorio.findById(id); 46 | 47 | if (respuesta.isPresent()) { 48 | 49 | Editorial editorial = respuesta.get(); 50 | 51 | editorial.setNombre(nombre); 52 | 53 | editorialRepositorio.save(editorial); 54 | } 55 | } 56 | 57 | @Transactional 58 | public void eliminar(String id) throws MiException{ 59 | 60 | Editorial editorial = editorialRepositorio.getById(id); 61 | 62 | editorialRepositorio.delete(editorial); 63 | 64 | } 65 | 66 | private void validar(String nombre) throws MiException { 67 | 68 | if (nombre.isEmpty() || nombre == null) { 69 | throw new MiException("el nombre de la editorial no puede ser nulo o estar vacio"); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Biblioteca_V1/src/main/java/com/egg/biblioteca/servicios/LibroServicio.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.servicios; 2 | 3 | import com.egg.biblioteca.entidades.Autor; 4 | import com.egg.biblioteca.entidades.Editorial; 5 | import com.egg.biblioteca.entidades.Libro; 6 | import com.egg.biblioteca.excepciones.MiException; 7 | import com.egg.biblioteca.repositorios.AutorRepositorio; 8 | import com.egg.biblioteca.repositorios.EditorialRepositorio; 9 | import com.egg.biblioteca.repositorios.LibroRepositorio; 10 | import java.util.ArrayList; 11 | import java.util.Date; 12 | import java.util.List; 13 | import java.util.Optional; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Service; 16 | import org.springframework.transaction.annotation.Transactional; 17 | 18 | @Service 19 | public class LibroServicio { 20 | 21 | @Autowired 22 | private LibroRepositorio libroRepositorio; 23 | @Autowired 24 | private AutorRepositorio autorRepositorio; 25 | @Autowired 26 | private EditorialRepositorio editorialRepositorio; 27 | 28 | @Transactional 29 | public void crearLibro(Long isbn, String titulo, Integer ejemplares, String idAutor, String idEditorial) throws MiException { 30 | 31 | validar(isbn, titulo, ejemplares, idAutor, idEditorial); 32 | 33 | Optional respuesta = libroRepositorio.findById(isbn); 34 | Optional respuestaAutor = autorRepositorio.findById(idAutor); 35 | Optional respuestaEditorial = editorialRepositorio.findById(idEditorial); 36 | 37 | Autor autor = new Autor(); 38 | Editorial editorial = new Editorial(); 39 | 40 | if (respuestaAutor.isPresent()) { 41 | 42 | autor = respuestaAutor.get(); 43 | } 44 | 45 | if (respuestaEditorial.isPresent()) { 46 | 47 | editorial = respuestaEditorial.get(); 48 | } 49 | 50 | Libro libro = new Libro(); 51 | 52 | libro.setIsbn(isbn); 53 | libro.setTitulo(titulo); 54 | libro.setEjemplares(ejemplares); 55 | libro.setAlta(new Date()); 56 | libro.setAutor(autor); 57 | libro.setEditorial(editorial); 58 | 59 | libroRepositorio.save(libro); 60 | } 61 | 62 | @Transactional(readOnly = true) 63 | public List listarLibros() { 64 | 65 | List libros = new ArrayList(); 66 | 67 | libros = libroRepositorio.findAll(); 68 | 69 | return libros; 70 | } 71 | 72 | @Transactional 73 | public void modificarLibro(Long isbn, String titulo, Integer ejemplares, String idAutor, String idEditorial) throws MiException { 74 | 75 | validar(isbn, titulo, ejemplares, idAutor, idEditorial); 76 | 77 | Optional respuesta = libroRepositorio.findById(isbn); 78 | Optional respuestaAutor = autorRepositorio.findById(idAutor); 79 | Optional respuestaEditorial = editorialRepositorio.findById(idEditorial); 80 | 81 | Autor autor = new Autor(); 82 | Editorial editorial = new Editorial(); 83 | 84 | if (respuestaAutor.isPresent()) { 85 | 86 | autor = respuestaAutor.get(); 87 | } 88 | 89 | if (respuestaEditorial.isPresent()) { 90 | 91 | editorial = respuestaEditorial.get(); 92 | } 93 | 94 | if (respuesta.isPresent()) { 95 | 96 | Libro libro = respuesta.get(); 97 | 98 | libro.setTitulo(titulo); 99 | 100 | libro.setEjemplares(ejemplares); 101 | 102 | libro.setAutor(autor); 103 | 104 | libro.setEditorial(editorial); 105 | 106 | } 107 | } 108 | 109 | private void validar(Long isbn, String titulo, Integer ejemplares, String idAutor, String idEditorial) throws MiException { 110 | 111 | if (isbn == null) { 112 | throw new MiException("el isbn no puede ser nulo"); // 113 | } 114 | if (titulo.isEmpty() || titulo == null) { 115 | throw new MiException("el titulo no puede ser nulo o estar vacio"); 116 | } 117 | if (ejemplares == null) { 118 | throw new MiException("ejemplares no puede ser nulo"); 119 | } 120 | if (idAutor.isEmpty() || idAutor == null) { 121 | throw new MiException("el Autor no puede ser nulo o estar vacio"); 122 | } 123 | 124 | if (idEditorial.isEmpty() || idEditorial == null) { 125 | throw new MiException("La Editorial no puede ser nula o estar vacia"); 126 | } 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /Biblioteca_V1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url: jdbc:mysql://localhost:3306/biblioteca?allowPublicKeyRetrieval=true&useSSL=false&useTimezone=true&serverTimezone=GMT&characterEncoding=UTF-8 2 | spring.datasource.username: root 3 | spring.datasource.password: root 4 | spring.datasource.driver-class-name: com.mysql.cj.jdbc.Driver 5 | spring.jpa.show-sql: true 6 | spring.jpa.hibernate.ddl-auto: update 7 | spring.jpa.properties.hibernate.dialect: org.hibernate.dialect.MySQL5InnoDBDialect 8 | spring.thymeleaf.cache: false 9 | 10 | -------------------------------------------------------------------------------- /Biblioteca_V1/src/test/java/com/egg/biblioteca/BibliotecaApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class BibliotecaApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Biblioteca_V2/.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 | -------------------------------------------------------------------------------- /Biblioteca_V2/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V2/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Biblioteca_V2/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /Biblioteca_V2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.7 9 | 10 | 11 | com.egg 12 | biblioteca 13 | 0.0.1-SNAPSHOT 14 | Biblioteca_V2 15 | Proyecto de Biblioteca para Egg. 16 | 17 | 1.8 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-data-jpa 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-thymeleaf 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | mysql 35 | mysql-connector-java 36 | runtime 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-maven-plugin 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/java/com/egg/biblioteca/BibliotecaApplication.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BibliotecaApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BibliotecaApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/java/com/egg/biblioteca/controladores/AutorControlador.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.controladores; 3 | 4 | import com.egg.biblioteca.entidades.Autor; 5 | import com.egg.biblioteca.excepciones.MiException; 6 | import com.egg.biblioteca.servicios.AutorServicio; 7 | import java.util.List; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.ui.ModelMap; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.PathVariable; 13 | import org.springframework.web.bind.annotation.PostMapping; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RequestParam; 16 | 17 | @Controller 18 | @RequestMapping("/autor") //localhost:8080/autor 19 | public class AutorControlador { 20 | 21 | @Autowired 22 | private AutorServicio autorServicio; 23 | 24 | @GetMapping("/registrar") //localhost:8080/autor/registrar 25 | public String registrar(){ 26 | return "autor_form.html"; 27 | } 28 | 29 | 30 | @PostMapping("/registro") 31 | public String registro(@RequestParam String nombre, ModelMap modelo){ 32 | 33 | try { 34 | autorServicio.crearAutor(nombre); 35 | 36 | modelo.put("exito", "El Autor fue registrado correctamente!"); 37 | } catch (MiException ex) { 38 | 39 | modelo.put("error", ex.getMessage()); 40 | return "autor_form.html"; 41 | } 42 | 43 | return "index.html"; 44 | } 45 | 46 | @GetMapping("/lista") 47 | public String listar(ModelMap modelo){ 48 | 49 | List autores = autorServicio.listarAutores(); 50 | 51 | modelo.addAttribute("autores", autores); 52 | 53 | return "autor_list.html"; 54 | } 55 | 56 | @GetMapping("/modificar/{id}") 57 | public String modificar(@PathVariable String id, ModelMap modelo){ 58 | modelo.put("autor", autorServicio.getOne(id)); 59 | 60 | return "autor_modificar.html"; 61 | } 62 | 63 | @PostMapping("{id}") 64 | public String modificar(@PathVariable String id, String nombre, ModelMap modelo){ 65 | try { 66 | autorServicio.modificarAutor(nombre, id); 67 | 68 | return "redirect:../lista"; 69 | } catch (MiException ex) { 70 | modelo.put("error", ex.getMessage()); 71 | return "autor_modificar.html"; 72 | } 73 | 74 | } 75 | 76 | // @GetMapping("{id}") 77 | public String eliminar(@PathVariable String id, ModelMap modelo) throws MiException{ 78 | autorServicio.eliminar(id); 79 | 80 | return "autor_modificar.html"; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/java/com/egg/biblioteca/controladores/EditorialControlador.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.controladores; 3 | 4 | import com.egg.biblioteca.entidades.Editorial; 5 | import com.egg.biblioteca.excepciones.MiException; 6 | import com.egg.biblioteca.servicios.EditorialServicio; 7 | import java.util.List; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.ui.ModelMap; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.PathVariable; 13 | import org.springframework.web.bind.annotation.PostMapping; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RequestParam; 16 | 17 | @Controller 18 | @RequestMapping("/editorial") 19 | public class EditorialControlador { 20 | @Autowired 21 | private EditorialServicio editorialServicio; 22 | 23 | @GetMapping("/registrar") //localhost:8080/autor/registrar 24 | public String registrar(){ 25 | return "editorial_form.html"; 26 | } 27 | 28 | 29 | @PostMapping("/registro") 30 | public String registro(@RequestParam String nombre, ModelMap modelo){ 31 | 32 | try { 33 | editorialServicio.crearEditorial(nombre); 34 | 35 | modelo.put("exito", "La Editorial fue registrada correctamente!"); 36 | } catch (MiException ex) { 37 | 38 | modelo.put("error", ex.getMessage()); 39 | return "editorial_form.html"; 40 | } 41 | 42 | return "index.html"; 43 | } 44 | 45 | @GetMapping("/lista") 46 | public String listar(ModelMap modelo){ 47 | 48 | List editoriales = editorialServicio.listarEditoriales(); 49 | 50 | modelo.addAttribute("editoriales", editoriales); 51 | 52 | return "editorial_list.html"; 53 | } 54 | 55 | @GetMapping("/modificar/{id}") 56 | public String modificar(@PathVariable String id, ModelMap modelo){ 57 | modelo.put("editorial", editorialServicio.getOne(id)); 58 | 59 | return "editorial_modificar.html"; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/java/com/egg/biblioteca/controladores/LibroControlador.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.controladores; 2 | 3 | import com.egg.biblioteca.entidades.Autor; 4 | import com.egg.biblioteca.entidades.Editorial; 5 | import com.egg.biblioteca.entidades.Libro; 6 | import com.egg.biblioteca.excepciones.MiException; 7 | import com.egg.biblioteca.servicios.AutorServicio; 8 | import com.egg.biblioteca.servicios.EditorialServicio; 9 | import com.egg.biblioteca.servicios.LibroServicio; 10 | import java.util.List; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Controller; 13 | import org.springframework.ui.ModelMap; 14 | import org.springframework.web.bind.annotation.GetMapping; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.PostMapping; 17 | import org.springframework.web.bind.annotation.RequestMapping; 18 | import org.springframework.web.bind.annotation.RequestParam; 19 | 20 | @Controller 21 | @RequestMapping("/libro") 22 | public class LibroControlador { 23 | 24 | @Autowired 25 | private LibroServicio libroServicio; 26 | @Autowired 27 | private AutorServicio autorServicio; 28 | @Autowired 29 | private EditorialServicio editorialServicio; 30 | 31 | 32 | @GetMapping("/registrar") //localhost:8080/libro/registrar 33 | public String registrar(ModelMap modelo) { 34 | List autores = autorServicio.listarAutores(); 35 | List editoriales = editorialServicio.listarEditoriales(); 36 | 37 | modelo.addAttribute("autores", autores); 38 | modelo.addAttribute("editoriales", editoriales); 39 | 40 | return "libro_form.html"; 41 | } 42 | 43 | @PostMapping("/registro") 44 | public String registro(@RequestParam(required = false) Long isbn, @RequestParam String titulo, 45 | @RequestParam(required = false) Integer ejemplares, @RequestParam String idAutor, 46 | @RequestParam String idEditorial, ModelMap modelo) { 47 | try { 48 | 49 | libroServicio.crearLibro(isbn, titulo, ejemplares, idAutor, idEditorial); 50 | 51 | modelo.put("exito", "El Libro fue cargado correctamente!"); 52 | 53 | } catch (MiException ex) { 54 | List autores = autorServicio.listarAutores(); 55 | List editoriales = editorialServicio.listarEditoriales(); 56 | 57 | modelo.addAttribute("autores", autores); 58 | modelo.addAttribute("editoriales", editoriales); 59 | modelo.put("error", ex.getMessage()); 60 | 61 | return "libro_form.html"; // volvemos a cargar el formulario. 62 | } 63 | return "index.html"; 64 | } 65 | 66 | @GetMapping("/lista") 67 | public String listar(ModelMap modelo) { 68 | List libros = libroServicio.listarLibros(); 69 | modelo.addAttribute("libros", libros); 70 | 71 | return "libro_list"; 72 | } 73 | 74 | 75 | @GetMapping("/modificar/{isbn}") 76 | public String modificar(@PathVariable Long isbn, ModelMap modelo) { 77 | 78 | modelo.put("libro", libroServicio.getOne(isbn)); 79 | 80 | List autores = autorServicio.listarAutores(); 81 | List editoriales = editorialServicio.listarEditoriales(); 82 | 83 | modelo.addAttribute("autores", autores); 84 | modelo.addAttribute("editoriales", editoriales); 85 | 86 | return "libro_modificar.html"; 87 | } 88 | 89 | @PostMapping("/modificar/{isbn}") 90 | public String modificar(@PathVariable Long isbn, String titulo, Integer ejemplares, String idAutor, String idEditorial, ModelMap modelo) { 91 | try { 92 | List autores = autorServicio.listarAutores(); 93 | List editoriales = editorialServicio.listarEditoriales(); 94 | 95 | modelo.addAttribute("autores", autores); 96 | modelo.addAttribute("editoriales", editoriales); 97 | 98 | libroServicio.modificarLibro(isbn, titulo, ejemplares, idAutor, idEditorial); 99 | 100 | 101 | return "redirect:../lista"; 102 | 103 | } catch (MiException ex) { 104 | List autores = autorServicio.listarAutores(); 105 | List editoriales = editorialServicio.listarEditoriales(); 106 | 107 | modelo.put("error", ex.getMessage()); 108 | 109 | modelo.addAttribute("autores", autores); 110 | modelo.addAttribute("editoriales", editoriales); 111 | 112 | return "libro_modificar.html"; 113 | } 114 | 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/java/com/egg/biblioteca/controladores/PortalControlador.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.controladores; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | @Controller 8 | @RequestMapping("/") 9 | public class PortalControlador { 10 | 11 | 12 | @GetMapping("/") 13 | public String index() { 14 | 15 | return "index.html"; 16 | } 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/java/com/egg/biblioteca/entidades/Autor.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.entidades; 3 | 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | import org.hibernate.annotations.GenericGenerator; 8 | 9 | @Entity 10 | public class Autor { 11 | 12 | @Id 13 | @GeneratedValue(generator = "uuid") 14 | @GenericGenerator(name = "uuid", strategy = "uuid2") 15 | private String id; 16 | private String nombre; 17 | 18 | public Autor() { 19 | } 20 | 21 | public String getId() { 22 | return id; 23 | } 24 | 25 | public void setId(String id) { 26 | this.id = id; 27 | } 28 | 29 | public String getNombre() { 30 | return nombre; 31 | } 32 | 33 | public void setNombre(String nombre) { 34 | this.nombre = nombre; 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/java/com/egg/biblioteca/entidades/Editorial.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.entidades; 3 | 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | import org.hibernate.annotations.GenericGenerator; 8 | 9 | @Entity 10 | public class Editorial { 11 | @Id 12 | @GeneratedValue(generator = "uuid") 13 | @GenericGenerator(name = "uuid", strategy = "uuid2") 14 | private String id; 15 | private String nombre; 16 | 17 | public Editorial() { 18 | } 19 | 20 | public String getId() { 21 | return id; 22 | } 23 | 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | 28 | public String getNombre() { 29 | return nombre; 30 | } 31 | 32 | public void setNombre(String nombre) { 33 | this.nombre = nombre; 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/java/com/egg/biblioteca/entidades/Libro.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.entidades; 3 | 4 | import java.util.Date; 5 | import javax.persistence.Entity; 6 | import javax.persistence.Id; 7 | import javax.persistence.ManyToOne; 8 | import javax.persistence.Temporal; 9 | import javax.persistence.TemporalType; 10 | 11 | @Entity 12 | public class Libro { 13 | @Id 14 | private Long isbn; 15 | private String titulo; 16 | private Integer ejemplares; 17 | 18 | @Temporal(TemporalType.DATE) 19 | private Date alta; 20 | 21 | @ManyToOne 22 | private Autor autor; 23 | 24 | @ManyToOne 25 | private Editorial editorial; 26 | 27 | public Libro() { 28 | } 29 | 30 | public Long getIsbn() { 31 | return isbn; 32 | } 33 | 34 | public void setIsbn(Long isbn) { 35 | this.isbn = isbn; 36 | } 37 | 38 | public String getTitulo() { 39 | return titulo; 40 | } 41 | 42 | public void setTitulo(String titulo) { 43 | this.titulo = titulo; 44 | } 45 | 46 | public Integer getEjemplares() { 47 | return ejemplares; 48 | } 49 | 50 | public void setEjemplares(Integer ejemplares) { 51 | this.ejemplares = ejemplares; 52 | } 53 | 54 | public Date getAlta() { 55 | return alta; 56 | } 57 | 58 | public void setAlta(Date alta) { 59 | this.alta = alta; 60 | } 61 | 62 | public Autor getAutor() { 63 | return autor; 64 | } 65 | 66 | public void setAutor(Autor autor) { 67 | this.autor = autor; 68 | } 69 | 70 | public Editorial getEditorial() { 71 | return editorial; 72 | } 73 | 74 | public void setEditorial(Editorial editorial) { 75 | this.editorial = editorial; 76 | } 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/java/com/egg/biblioteca/excepciones/MiException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.excepciones; 3 | 4 | 5 | public class MiException extends Exception{ 6 | 7 | public MiException(String msg) { 8 | super(msg); 9 | } 10 | 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/java/com/egg/biblioteca/repositorios/AutorRepositorio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.repositorios; 3 | 4 | import com.egg.biblioteca.entidades.Autor; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | @Repository 9 | public interface AutorRepositorio extends JpaRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/java/com/egg/biblioteca/repositorios/EditorialRepositorio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.repositorios; 3 | 4 | import com.egg.biblioteca.entidades.Editorial; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | @Repository 9 | public interface EditorialRepositorio extends JpaRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/java/com/egg/biblioteca/repositorios/LibroRepositorio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.repositorios; 3 | 4 | import com.egg.biblioteca.entidades.Libro; 5 | import java.util.List; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.data.repository.query.Param; 9 | import org.springframework.stereotype.Repository; 10 | 11 | @Repository 12 | public interface LibroRepositorio extends JpaRepository{ 13 | 14 | @Query("SELECT l FROM Libro l WHERE l.titulo = :titulo") 15 | public Libro buscarPorTitulo(@Param("titulo") String titulo); 16 | 17 | @Query("SELECT l FROM Libro l WHERE l.autor.nombre = :nombre") 18 | public List buscarPorAutor(@Param ("nombre") String nombre); 19 | } 20 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/java/com/egg/biblioteca/servicios/AutorServicio.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.servicios; 2 | 3 | import com.egg.biblioteca.entidades.Autor; 4 | import com.egg.biblioteca.excepciones.MiException; 5 | import com.egg.biblioteca.repositorios.AutorRepositorio; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Optional; 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Transactional; 13 | 14 | @Service 15 | public class AutorServicio { 16 | 17 | @Autowired 18 | AutorRepositorio autorRepositorio; 19 | 20 | @Transactional 21 | public void crearAutor(String nombre) throws MiException{ 22 | 23 | validar(nombre); 24 | 25 | Autor autor = new Autor(); 26 | 27 | autor.setNombre(nombre); 28 | 29 | autorRepositorio.save(autor); 30 | 31 | } 32 | 33 | @Transactional(readOnly = true) 34 | public List listarAutores() { 35 | 36 | List autores = new ArrayList(); 37 | 38 | autores = autorRepositorio.findAll(); 39 | 40 | return autores; 41 | } 42 | 43 | @Transactional 44 | public void modificarAutor(String nombre, String id) throws MiException{ 45 | 46 | validar(nombre); 47 | 48 | Optional respuesta = autorRepositorio.findById(id); 49 | 50 | if (respuesta.isPresent()) { 51 | Autor autor = respuesta.get(); 52 | 53 | autor.setNombre(nombre); 54 | 55 | autorRepositorio.save(autor); 56 | 57 | } 58 | } 59 | 60 | @Transactional(readOnly = true) 61 | public Autor getOne(String id){ 62 | return autorRepositorio.getOne(id); 63 | } 64 | 65 | 66 | @Transactional 67 | public void eliminar(String id) throws MiException{ 68 | 69 | Autor autor = autorRepositorio.getById(id); 70 | 71 | autorRepositorio.delete(autor); 72 | 73 | } 74 | 75 | private void validar(String nombre) throws MiException { 76 | 77 | if (nombre.isEmpty() || nombre == null) { 78 | throw new MiException("el nombre no puede ser nulo o estar vacio"); 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/java/com/egg/biblioteca/servicios/EditorialServicio.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.servicios; 2 | 3 | import com.egg.biblioteca.entidades.Editorial; 4 | import com.egg.biblioteca.excepciones.MiException; 5 | import com.egg.biblioteca.repositorios.EditorialRepositorio; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Optional; 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Transactional; 13 | 14 | @Service 15 | public class EditorialServicio { 16 | 17 | @Autowired 18 | EditorialRepositorio editorialRepositorio; 19 | 20 | @Transactional 21 | public void crearEditorial(String nombre) throws MiException{ 22 | 23 | validar(nombre); 24 | 25 | Editorial editorial = new Editorial(); 26 | 27 | editorial.setNombre(nombre); 28 | 29 | editorialRepositorio.save(editorial); 30 | } 31 | 32 | @Transactional(readOnly = true) 33 | public List listarEditoriales() { 34 | 35 | List editoriales = new ArrayList(); 36 | 37 | editoriales = editorialRepositorio.findAll(); 38 | 39 | return editoriales; 40 | } 41 | 42 | @Transactional 43 | public void modificarEditorial(String id, String nombre) throws MiException{ 44 | validar(nombre); 45 | 46 | Optional respuesta = editorialRepositorio.findById(id); 47 | 48 | if (respuesta.isPresent()) { 49 | 50 | Editorial editorial = respuesta.get(); 51 | 52 | editorial.setNombre(nombre); 53 | 54 | editorialRepositorio.save(editorial); 55 | } 56 | } 57 | 58 | @Transactional(readOnly = true) 59 | public Editorial getOne(String id){ 60 | return editorialRepositorio.getOne(id); 61 | } 62 | 63 | private void validar(String nombre) throws MiException { 64 | 65 | if (nombre.isEmpty() || nombre == null) { 66 | throw new MiException("el nombre de la editorial no puede ser nulo o estar vacio"); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/java/com/egg/biblioteca/servicios/LibroServicio.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.servicios; 2 | 3 | import com.egg.biblioteca.entidades.Autor; 4 | import com.egg.biblioteca.entidades.Editorial; 5 | import com.egg.biblioteca.entidades.Libro; 6 | import com.egg.biblioteca.excepciones.MiException; 7 | import com.egg.biblioteca.repositorios.AutorRepositorio; 8 | import com.egg.biblioteca.repositorios.EditorialRepositorio; 9 | import com.egg.biblioteca.repositorios.LibroRepositorio; 10 | import java.util.ArrayList; 11 | import java.util.Date; 12 | import java.util.List; 13 | import java.util.Optional; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Service; 16 | import org.springframework.transaction.annotation.Transactional; 17 | 18 | @Service 19 | public class LibroServicio { 20 | 21 | @Autowired 22 | private LibroRepositorio libroRepositorio; 23 | @Autowired 24 | private AutorRepositorio autorRepositorio; 25 | @Autowired 26 | private EditorialRepositorio editorialRepositorio; 27 | 28 | @Transactional 29 | public void crearLibro(Long isbn, String titulo, Integer ejemplares, String idAutor, String idEditorial) throws MiException{ 30 | 31 | validar(isbn, titulo, ejemplares, idAutor, idEditorial); 32 | 33 | Optional respuesta = libroRepositorio.findById(isbn); 34 | Optional respuestaAutor = autorRepositorio.findById(idAutor); 35 | Optional respuestaEditorial = editorialRepositorio.findById(idEditorial); 36 | 37 | Autor autor = new Autor(); 38 | Editorial editorial= new Editorial(); 39 | 40 | if(respuestaAutor.isPresent()){ 41 | 42 | autor = respuestaAutor.get(); 43 | } 44 | 45 | if(respuestaEditorial.isPresent()){ 46 | 47 | editorial = respuestaEditorial.get(); 48 | } 49 | 50 | Libro libro = new Libro(); 51 | 52 | libro.setIsbn(isbn); 53 | libro.setTitulo(titulo); 54 | libro.setEjemplares(ejemplares); 55 | libro.setAlta(new Date()); 56 | libro.setAutor(autor); 57 | libro.setEditorial(editorial); 58 | 59 | libroRepositorio.save(libro); 60 | } 61 | 62 | @Transactional(readOnly = true) 63 | public List listarLibros() { 64 | 65 | List libros = new ArrayList(); 66 | 67 | libros = libroRepositorio.findAll(); 68 | 69 | return libros; 70 | } 71 | 72 | @Transactional 73 | public void modificarLibro(Long isbn, String titulo, Integer ejemplares, String idAutor, String idEditorial) throws MiException{ 74 | 75 | validar(isbn, titulo, ejemplares, idAutor, idEditorial); 76 | 77 | Optional respuesta = libroRepositorio.findById(isbn); 78 | Optional respuestaAutor = autorRepositorio.findById(idAutor); 79 | Optional respuestaEditorial = editorialRepositorio.findById(idEditorial); 80 | 81 | Autor autor = new Autor(); 82 | Editorial editorial= new Editorial(); 83 | 84 | if(respuestaAutor.isPresent()){ 85 | 86 | autor = respuestaAutor.get(); 87 | } 88 | 89 | if(respuestaEditorial.isPresent()){ 90 | 91 | editorial = respuestaEditorial.get(); 92 | } 93 | 94 | if(respuesta.isPresent()){ 95 | 96 | Libro libro = respuesta.get(); 97 | 98 | 99 | libro.setTitulo(titulo); 100 | 101 | libro.setEjemplares(ejemplares); 102 | 103 | libro.setAutor(autor); 104 | 105 | libro.setEditorial(editorial); 106 | 107 | 108 | libroRepositorio.save(libro); 109 | 110 | } 111 | } 112 | 113 | @Transactional(readOnly = true) 114 | public Libro getOne(Long isbn){ 115 | return libroRepositorio.getOne(isbn); 116 | } 117 | 118 | private void validar(Long isbn, String titulo, Integer ejemplares, String idAutor, String idEditorial) throws MiException{ 119 | 120 | if(isbn == null){ 121 | throw new MiException("el isbn no puede ser nulo"); // 122 | } 123 | if(titulo.isEmpty() || titulo == null){ 124 | throw new MiException("el titulo no puede ser nulo o estar vacio"); 125 | } 126 | if(ejemplares == null){ 127 | throw new MiException("ejemplares no puede ser nulo"); 128 | } 129 | if(idAutor.isEmpty() || idAutor == null){ 130 | throw new MiException("el Autor no puede ser nulo o estar vacio"); 131 | } 132 | 133 | if(idEditorial.isEmpty() || idEditorial == null){ 134 | throw new MiException("La Editorial no puede ser nula o estar vacia"); 135 | } 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url: jdbc:mysql://localhost:3306/biblioteca?allowPublicKeyRetrieval=true&useSSL=false&useTimezone=true&serverTimezone=GMT&characterEncoding=UTF-8 2 | spring.datasource.username: root 3 | spring.datasource.password: root 4 | spring.datasource.driver-class-name: com.mysql.cj.jdbc.Driver 5 | spring.jpa.show-sql: true 6 | spring.jpa.hibernate.ddl-auto: update 7 | spring.jpa.properties.hibernate.dialect: org.hibernate.dialect.MySQL5InnoDBDialect 8 | spring.thymeleaf.cache: false 9 | 10 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/resources/static/css/formulario.css: -------------------------------------------------------------------------------- 1 | .navBar{ 2 | background-color: #fff !important; 3 | } 4 | 5 | .elementosNav{ 6 | display: flex; 7 | width: 30%; 8 | justify-content: space-around; 9 | color: #37474f; 10 | font-weight: 700; 11 | } 12 | 13 | .elementos{ 14 | margin-right: 50px; 15 | } 16 | 17 | .containerImg{ 18 | width: 20%; 19 | } 20 | 21 | .logo{ 22 | width: 40%; 23 | margin: auto; 24 | } 25 | 26 | 27 | .mensajeExito{ 28 | width: 20%; 29 | margin: auto; 30 | text-align: center; 31 | } 32 | 33 | .mensajeError{ 34 | width: 20%; 35 | margin: auto; 36 | text-align: center; 37 | } 38 | 39 | .formulario{ 40 | width: 50%; 41 | margin: auto; 42 | display: flex; 43 | flex-direction: column; 44 | } 45 | 46 | .divVolver{ 47 | width: 50%; 48 | display: flex; 49 | justify-content: center; 50 | align-items: center; 51 | margin: auto; 52 | } 53 | 54 | .botonVolver{ 55 | width: 70%; 56 | } 57 | 58 | .botones{ 59 | box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 60 | -webkit-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 61 | -moz-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 62 | } 63 | 64 | .botones:active{ 65 | box-shadow: none; 66 | } 67 | 68 | .containerFooter{ 69 | display: flex; 70 | justify-content: space-around; 71 | align-items: center; 72 | } -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/resources/static/css/index.css: -------------------------------------------------------------------------------- 1 | .navBar{ 2 | background-color: #fff !important; 3 | } 4 | 5 | .elementosNav{ 6 | display: flex; 7 | width: 30%; 8 | justify-content: space-around; 9 | color: #37474f; 10 | font-weight: 700; 11 | } 12 | 13 | .elementos{ 14 | margin-right: 50px; 15 | } 16 | 17 | .containerImg{ 18 | width: 20%; 19 | } 20 | 21 | .logo{ 22 | width: 40%; 23 | margin: auto; 24 | } 25 | 26 | .tituloBiblioteca{ 27 | width: 80%; 28 | text-align: center; 29 | font-size: 40px; 30 | margin-top: 80px; 31 | font-weight: 500; 32 | } 33 | 34 | .header{ 35 | background-image: url(../img/FondoZoom_2.jpg); 36 | background-size: cover; 37 | height: 550px; 38 | display: flex; 39 | justify-content: end; 40 | } 41 | 42 | .contenedorLibros{ 43 | margin-top: 80px; 44 | display: flex; 45 | flex-direction: column; 46 | justify-content: center; 47 | align-items: center; 48 | } 49 | 50 | .tituloLibros{ 51 | font-size: 22px; 52 | font-weight: 500; 53 | } 54 | 55 | .contenedorMain{ 56 | width: 50%; 57 | display: flex; 58 | flex-direction: column; 59 | align-items: center; 60 | } 61 | 62 | .containerFooter{ 63 | display: flex; 64 | justify-content: space-around; 65 | align-items: center; 66 | } 67 | 68 | .boton{ 69 | background-color: #ffcb00; 70 | box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 71 | -webkit-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 72 | -moz-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 73 | } 74 | 75 | .boton:hover{ 76 | background-color: #ffcb00; 77 | } 78 | .boton:active{ 79 | box-shadow: none; 80 | } -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/resources/static/css/inicio.css: -------------------------------------------------------------------------------- 1 | .navBar{ 2 | background-color: #fff !important; 3 | } 4 | 5 | .elementosNav{ 6 | display: flex; 7 | width: 30%; 8 | justify-content: space-around; 9 | color: #37474f; 10 | font-weight: 700; 11 | } 12 | 13 | .containerImg{ 14 | width: 20%; 15 | } 16 | 17 | .logo{ 18 | width: 40%; 19 | margin: auto; 20 | } 21 | 22 | .main{ 23 | background-image: url(../img/FondoZoom.jpg); 24 | background-size: cover; 25 | height: 400px; 26 | display: flex; 27 | align-items: center; 28 | } 29 | 30 | .containerFooter{ 31 | display: flex; 32 | justify-content: space-around; 33 | align-items: center; 34 | } 35 | 36 | .boton{ 37 | background-color: #ffcb00; 38 | box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 39 | -webkit-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 40 | -moz-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 41 | margin-right: 10px; 42 | margin-left: -10px; 43 | } 44 | 45 | .botonCargar{ 46 | box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 47 | -webkit-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 48 | -moz-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 49 | } 50 | 51 | .boton:active{ 52 | box-shadow: none; 53 | } 54 | .botonCargar:active{ 55 | box-shadow: none; 56 | } -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/resources/static/img/Egg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V2/src/main/resources/static/img/Egg.png -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/resources/static/img/FondoZoom.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V2/src/main/resources/static/img/FondoZoom.jpg -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/resources/static/img/FondoZoom_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V2/src/main/resources/static/img/FondoZoom_1.jpg -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/resources/static/img/FondoZoom_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V2/src/main/resources/static/img/FondoZoom_2.jpg -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/resources/static/img/imgEgg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V2/src/main/resources/static/img/imgEgg.png -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/resources/static/img/imgEggBlanco.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V2/src/main/resources/static/img/imgEggBlanco.jpg -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/resources/templates/autor_form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Registro de Autores 6 | 7 | 8 | 9 | 10 | 11 | 66 |
67 | 68 |
69 |
70 | 71 | 72 |
73 | 74 | 75 |
76 | 77 |
78 |
79 |
Exito!
80 |

81 |
82 |
83 |
84 |
85 |
Error 👎
86 |

87 |
88 |
89 |
90 |
91 |
92 | Volver 93 |
94 |
95 |
96 |
97 | 98 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Biblioteca Egg 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 68 | 69 |
70 |
71 |
Exito
72 |

73 |
74 |
75 |
76 |
77 |
Error 👎
78 |

79 |
80 |
81 |
82 |
83 |
84 | BIBLIOTECA EGG 85 |
86 |
87 |

Encontrá todos los Libros Aquí!

88 | 89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 | 97 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /Biblioteca_V2/src/test/java/com/egg/biblioteca/BibliotecaApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class BibliotecaApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Biblioteca_V3/.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 | -------------------------------------------------------------------------------- /Biblioteca_V3/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V3/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Biblioteca_V3/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /Biblioteca_V3/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.7 9 | 10 | 11 | com.egg 12 | biblioteca 13 | 0.0.1-SNAPSHOT 14 | Biblioteca_V3 15 | Proyecto de Biblioteca para Egg. 16 | 17 | 1.8 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-data-jpa 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-thymeleaf 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | mysql 35 | mysql-connector-java 36 | runtime 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-security 46 | 47 | 48 | org.thymeleaf.extras 49 | thymeleaf-extras-springsecurity5 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-maven-plugin 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/BibliotecaApplication.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BibliotecaApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BibliotecaApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/SeguridadWeb.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca; 2 | 3 | import com.egg.biblioteca.servicios.UsuarioServicio; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 7 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 9 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 10 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 11 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 12 | 13 | @Configuration 14 | @EnableWebSecurity 15 | @EnableGlobalMethodSecurity(prePostEnabled = true) 16 | public class SeguridadWeb extends WebSecurityConfigurerAdapter { 17 | 18 | @Autowired 19 | public UsuarioServicio usuarioServicio; 20 | 21 | @Autowired 22 | public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{ 23 | auth.userDetailsService(usuarioServicio) 24 | .passwordEncoder(new BCryptPasswordEncoder()); 25 | } 26 | 27 | @Override 28 | protected void configure(HttpSecurity http) throws Exception { 29 | http 30 | .authorizeRequests() 31 | .antMatchers("/admin/*").hasRole("ADMIN") 32 | .antMatchers("/css/*", "/js/*", "/img/*", "/**") 33 | .permitAll() 34 | .and().formLogin() 35 | .loginPage("/login") 36 | .loginProcessingUrl("/logincheck") 37 | .usernameParameter("email") 38 | .passwordParameter("password") 39 | .defaultSuccessUrl("/inicio") 40 | .permitAll() 41 | .and().logout() 42 | .logoutUrl("/logout") 43 | .logoutSuccessUrl("/login") 44 | .permitAll() 45 | .and().csrf() 46 | .disable(); 47 | 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/controladores/AdminControlador.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.controladores; 3 | 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | 8 | @Controller 9 | @RequestMapping("/admin") 10 | public class AdminControlador { 11 | 12 | @GetMapping("/dashboard") 13 | public String panelAdministrativo(){ 14 | return "panel.html"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/controladores/AutorControlador.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.controladores; 3 | 4 | import com.egg.biblioteca.entidades.Autor; 5 | import com.egg.biblioteca.excepciones.MiException; 6 | import com.egg.biblioteca.repositorios.AutorRepositorio; 7 | import com.egg.biblioteca.servicios.AutorServicio; 8 | import java.util.List; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Controller; 11 | import org.springframework.ui.ModelMap; 12 | import org.springframework.web.bind.annotation.DeleteMapping; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.PatchMapping; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.PostMapping; 17 | import org.springframework.web.bind.annotation.RequestMapping; 18 | import org.springframework.web.bind.annotation.RequestParam; 19 | 20 | @Controller 21 | @RequestMapping("/autor") //localhost:8080/autor 22 | public class AutorControlador { 23 | 24 | @Autowired 25 | private AutorServicio autorServicio; 26 | 27 | @GetMapping("") //localhost:8080/autor/registrar 28 | public String registrar(){ 29 | return "autor_form.html"; 30 | } 31 | 32 | 33 | @PostMapping("") 34 | public String registro(@RequestParam String nombre, ModelMap modelo){ 35 | 36 | try { 37 | autorServicio.crearAutor(nombre); 38 | 39 | modelo.put("exito", "El Autor fue registrado correctamente!"); 40 | } catch (MiException ex) { 41 | 42 | modelo.put("error", ex.getMessage()); 43 | return "autor_form.html"; 44 | } 45 | 46 | return "index.html"; 47 | } 48 | 49 | @GetMapping("/autores") 50 | public String listar(ModelMap modelo){ 51 | 52 | List autores = autorServicio.listarAutores(); 53 | 54 | modelo.addAttribute("autores", autores); 55 | 56 | return "autor_list.html"; 57 | } 58 | 59 | @GetMapping("{id}") 60 | public String modificar(@PathVariable String id, ModelMap modelo){ 61 | modelo.put("autor", autorServicio.getOne(id)); 62 | 63 | return "autor_modificar.html"; 64 | } 65 | 66 | @PatchMapping("{id}") 67 | public String modificar(@PathVariable String id, String nombre, ModelMap modelo){ 68 | try { 69 | autorServicio.modificarAutor(nombre, id); 70 | 71 | return "redirect:../lista"; 72 | } catch (MiException ex) { 73 | modelo.put("error", ex.getMessage()); 74 | return "autor_modificar.html"; 75 | } 76 | 77 | } 78 | 79 | @DeleteMapping("{id}") 80 | public String eliminar(@PathVariable String id, ModelMap modelo) throws MiException{ 81 | autorServicio.eliminar(id); 82 | 83 | return "autor_modificar.html"; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/controladores/EditorialControlador.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.controladores; 3 | 4 | import com.egg.biblioteca.excepciones.MiException; 5 | import com.egg.biblioteca.servicios.EditorialServicio; 6 | import java.util.logging.Level; 7 | import java.util.logging.Logger; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.ui.ModelMap; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RequestParam; 15 | 16 | @Controller 17 | @RequestMapping("/editorial") 18 | public class EditorialControlador { 19 | @Autowired 20 | private EditorialServicio editorialServicio; 21 | 22 | @GetMapping("/registrar") //localhost:8080/autor/registrar 23 | public String registrar(){ 24 | return "editorial_form.html"; 25 | } 26 | 27 | 28 | @PostMapping("/registro") 29 | public String registro(@RequestParam String nombre, ModelMap modelo){ 30 | 31 | try { 32 | editorialServicio.crearEditorial(nombre); 33 | 34 | modelo.put("exito", "La Editorial fue registrada correctamente!"); 35 | } catch (MiException ex) { 36 | 37 | modelo.put("error", ex.getMessage()); 38 | return "editorial_form.html"; 39 | } 40 | 41 | return "index.html"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/controladores/LibroControlador.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.controladores; 2 | 3 | import com.egg.biblioteca.entidades.Autor; 4 | import com.egg.biblioteca.entidades.Editorial; 5 | import com.egg.biblioteca.entidades.Libro; 6 | import com.egg.biblioteca.excepciones.MiException; 7 | import com.egg.biblioteca.servicios.AutorServicio; 8 | import com.egg.biblioteca.servicios.EditorialServicio; 9 | import com.egg.biblioteca.servicios.LibroServicio; 10 | import java.util.List; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Controller; 13 | import org.springframework.ui.ModelMap; 14 | import org.springframework.web.bind.annotation.GetMapping; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.PostMapping; 17 | import org.springframework.web.bind.annotation.RequestMapping; 18 | import org.springframework.web.bind.annotation.RequestParam; 19 | 20 | @Controller 21 | @RequestMapping("/libro") 22 | public class LibroControlador { 23 | 24 | @Autowired 25 | private LibroServicio libroServicio; 26 | @Autowired 27 | private AutorServicio autorServicio; 28 | @Autowired 29 | private EditorialServicio editorialServicio; 30 | 31 | 32 | @GetMapping("/registrar") //localhost:8080/libro/registrar 33 | public String registrar(ModelMap modelo) { 34 | List autores = autorServicio.listarAutores(); 35 | List editoriales = editorialServicio.listarEditoriales(); 36 | 37 | modelo.addAttribute("autores", autores); 38 | modelo.addAttribute("editoriales", editoriales); 39 | 40 | return "libro_form.html"; 41 | } 42 | 43 | @PostMapping("/registro") 44 | public String registro(@RequestParam(required = false) Long isbn, @RequestParam String titulo, 45 | @RequestParam(required = false) Integer ejemplares, @RequestParam String idAutor, 46 | @RequestParam String idEditorial, ModelMap modelo) { 47 | try { 48 | 49 | libroServicio.crearLibro(isbn, titulo, ejemplares, idAutor, idEditorial); 50 | 51 | modelo.put("exito", "El Libro fue cargado correctamente!"); 52 | 53 | } catch (MiException ex) { 54 | List autores = autorServicio.listarAutores(); 55 | List editoriales = editorialServicio.listarEditoriales(); 56 | 57 | modelo.addAttribute("autores", autores); 58 | modelo.addAttribute("editoriales", editoriales); 59 | modelo.put("error", ex.getMessage()); 60 | 61 | return "libro_form.html"; // volvemos a cargar el formulario. 62 | } 63 | return "index.html"; 64 | } 65 | 66 | @GetMapping("/lista") 67 | public String listar(ModelMap modelo) { 68 | List libros = libroServicio.listarLibros(); 69 | modelo.addAttribute("libros", libros); 70 | 71 | return "libro_list"; 72 | } 73 | 74 | 75 | @GetMapping("/modificar/{isbn}") 76 | public String modificar(@PathVariable Long isbn, ModelMap modelo) { 77 | 78 | modelo.put("libro", libroServicio.getOne(isbn)); 79 | 80 | List autores = autorServicio.listarAutores(); 81 | List editoriales = editorialServicio.listarEditoriales(); 82 | 83 | modelo.addAttribute("autores", autores); 84 | modelo.addAttribute("editoriales", editoriales); 85 | 86 | return "libro_modificar.html"; 87 | } 88 | 89 | @PostMapping("/modificar/{isbn}") 90 | public String modificar(@PathVariable Long isbn, String titulo, Integer ejemplares, String idAutor, String idEditorial, ModelMap modelo) { 91 | try { 92 | List autores = autorServicio.listarAutores(); 93 | List editoriales = editorialServicio.listarEditoriales(); 94 | 95 | modelo.addAttribute("autores", autores); 96 | modelo.addAttribute("editoriales", editoriales); 97 | 98 | libroServicio.modificarLibro(isbn, titulo, ejemplares, idAutor, idEditorial); 99 | 100 | 101 | return "redirect:../lista"; 102 | 103 | } catch (MiException ex) { 104 | List autores = autorServicio.listarAutores(); 105 | List editoriales = editorialServicio.listarEditoriales(); 106 | 107 | modelo.put("error", ex.getMessage()); 108 | 109 | modelo.addAttribute("autores", autores); 110 | modelo.addAttribute("editoriales", editoriales); 111 | 112 | return "libro_modificar.html"; 113 | } 114 | 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/controladores/PortalControlador.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.controladores; 2 | 3 | import com.egg.biblioteca.entidades.Usuario; 4 | import com.egg.biblioteca.excepciones.MiException; 5 | import com.egg.biblioteca.servicios.UsuarioServicio; 6 | import javax.servlet.http.HttpSession; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.security.access.prepost.PreAuthorize; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.ui.ModelMap; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RequestParam; 15 | import org.springframework.web.multipart.MultipartFile; 16 | 17 | @Controller 18 | @RequestMapping("/") 19 | public class PortalControlador { 20 | 21 | @Autowired 22 | private UsuarioServicio usuarioServicio; 23 | 24 | @GetMapping("/") 25 | public String index() { 26 | 27 | return "index.html"; 28 | } 29 | 30 | @GetMapping("/registrar") 31 | public String registrar() { 32 | return "registro.html"; 33 | } 34 | 35 | @PostMapping("/registro") 36 | public String registro(@RequestParam String nombre, @RequestParam String email, @RequestParam String password, 37 | String password2, ModelMap modelo, MultipartFile archivo) { 38 | 39 | try { 40 | usuarioServicio.registrar(archivo,nombre, email, password, password2); 41 | 42 | modelo.put("exito", "Usuario registrado correctamente!"); 43 | 44 | return "index.html"; 45 | } catch (MiException ex) { 46 | 47 | modelo.put("error", ex.getMessage()); 48 | modelo.put("nombre", nombre); 49 | modelo.put("email", email); 50 | 51 | return "registro.html"; 52 | } 53 | 54 | } 55 | 56 | @GetMapping("/login") 57 | public String login(@RequestParam(required = false) String error, ModelMap modelo ) { 58 | 59 | if (error != null) { 60 | modelo.put("error", "Usuario o Contraseña invalidos!"); 61 | } 62 | 63 | return "login.html"; 64 | } 65 | 66 | @PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')") 67 | @GetMapping("/inicio") 68 | public String inicio(HttpSession session) { 69 | 70 | Usuario logueado = (Usuario) session.getAttribute("usuariosession"); 71 | 72 | if (logueado.getRol().toString().equals("ADMIN")) { 73 | return "redirect:/admin/dashboard"; 74 | } 75 | 76 | return "inicio.html"; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/entidades/Autor.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.entidades; 3 | 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | import org.hibernate.annotations.GenericGenerator; 8 | 9 | @Entity 10 | public class Autor { 11 | 12 | @Id 13 | @GeneratedValue(generator = "uuid") 14 | @GenericGenerator(name = "uuid", strategy = "uuid2") 15 | private String id; 16 | private String nombre; 17 | 18 | public Autor() { 19 | } 20 | 21 | public String getId() { 22 | return id; 23 | } 24 | 25 | public void setId(String id) { 26 | this.id = id; 27 | } 28 | 29 | public String getNombre() { 30 | return nombre; 31 | } 32 | 33 | public void setNombre(String nombre) { 34 | this.nombre = nombre; 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/entidades/Editorial.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.entidades; 3 | 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | import org.hibernate.annotations.GenericGenerator; 8 | 9 | @Entity 10 | public class Editorial { 11 | @Id 12 | @GeneratedValue(generator = "uuid") 13 | @GenericGenerator(name = "uuid", strategy = "uuid2") 14 | private String id; 15 | private String nombre; 16 | 17 | public Editorial() { 18 | } 19 | 20 | public String getId() { 21 | return id; 22 | } 23 | 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | 28 | public String getNombre() { 29 | return nombre; 30 | } 31 | 32 | public void setNombre(String nombre) { 33 | this.nombre = nombre; 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/entidades/Libro.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.entidades; 3 | 4 | import java.util.Date; 5 | import javax.persistence.Entity; 6 | import javax.persistence.Id; 7 | import javax.persistence.ManyToOne; 8 | import javax.persistence.OneToOne; 9 | import javax.persistence.Temporal; 10 | import javax.persistence.TemporalType; 11 | 12 | @Entity 13 | public class Libro { 14 | @Id 15 | private Long isbn; 16 | private String titulo; 17 | private Integer ejemplares; 18 | 19 | @Temporal(TemporalType.DATE) 20 | private Date alta; 21 | 22 | @ManyToOne 23 | private Autor autor; 24 | 25 | @ManyToOne 26 | private Editorial editorial; 27 | 28 | 29 | public Libro() { 30 | } 31 | 32 | public Long getIsbn() { 33 | return isbn; 34 | } 35 | 36 | public void setIsbn(Long isbn) { 37 | this.isbn = isbn; 38 | } 39 | 40 | public String getTitulo() { 41 | return titulo; 42 | } 43 | 44 | public void setTitulo(String titulo) { 45 | this.titulo = titulo; 46 | } 47 | 48 | public Integer getEjemplares() { 49 | return ejemplares; 50 | } 51 | 52 | public void setEjemplares(Integer ejemplares) { 53 | this.ejemplares = ejemplares; 54 | } 55 | 56 | public Date getAlta() { 57 | return alta; 58 | } 59 | 60 | public void setAlta(Date alta) { 61 | this.alta = alta; 62 | } 63 | 64 | public Autor getAutor() { 65 | return autor; 66 | } 67 | 68 | public void setAutor(Autor autor) { 69 | this.autor = autor; 70 | } 71 | 72 | public Editorial getEditorial() { 73 | return editorial; 74 | } 75 | 76 | public void setEditorial(Editorial editorial) { 77 | this.editorial = editorial; 78 | } 79 | 80 | 81 | } 82 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/entidades/Usuario.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.entidades; 3 | 4 | import com.egg.biblioteca.enumeraciones.Rol; 5 | import javax.persistence.Entity; 6 | import javax.persistence.EnumType; 7 | import javax.persistence.Enumerated; 8 | import javax.persistence.GeneratedValue; 9 | import javax.persistence.Id; 10 | import javax.persistence.OneToOne; 11 | import org.hibernate.annotations.GenericGenerator; 12 | 13 | @Entity 14 | public class Usuario { 15 | @Id 16 | @GeneratedValue(generator = "uuid") 17 | @GenericGenerator(name = "uuid", strategy = "uuid2") 18 | private String id; 19 | 20 | private String nombre; 21 | private String email; 22 | private String password; 23 | 24 | @Enumerated(EnumType.STRING) 25 | private Rol rol; 26 | 27 | 28 | public Usuario() { 29 | } 30 | public String getId() { 31 | return id; 32 | } 33 | 34 | public void setId(String id) { 35 | this.id = id; 36 | } 37 | 38 | public String getNombre() { 39 | return nombre; 40 | } 41 | 42 | public void setNombre(String nombre) { 43 | this.nombre = nombre; 44 | } 45 | 46 | public String getEmail() { 47 | return email; 48 | } 49 | 50 | public void setEmail(String email) { 51 | this.email = email; 52 | } 53 | 54 | public String getPassword() { 55 | return password; 56 | } 57 | 58 | public void setPassword(String password) { 59 | this.password = password; 60 | } 61 | 62 | public Rol getRol() { 63 | return rol; 64 | } 65 | 66 | public void setRol(Rol rol) { 67 | this.rol = rol; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/enumeraciones/Rol.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.enumeraciones; 3 | 4 | 5 | public enum Rol { 6 | USER, 7 | ADMIN; 8 | } 9 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/excepciones/MiException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.excepciones; 3 | 4 | 5 | public class MiException extends Exception{ 6 | 7 | public MiException(String msg) { 8 | super(msg); 9 | } 10 | 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/repositorios/AutorRepositorio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.repositorios; 3 | 4 | import com.egg.biblioteca.entidades.Autor; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | @Repository 9 | public interface AutorRepositorio extends JpaRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/repositorios/EditorialRepositorio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.repositorios; 3 | 4 | import com.egg.biblioteca.entidades.Editorial; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | @Repository 9 | public interface EditorialRepositorio extends JpaRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/repositorios/LibroRepositorio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.repositorios; 3 | 4 | import com.egg.biblioteca.entidades.Libro; 5 | import java.util.List; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.data.repository.query.Param; 9 | import org.springframework.stereotype.Repository; 10 | 11 | @Repository 12 | public interface LibroRepositorio extends JpaRepository{ 13 | 14 | @Query("SELECT l FROM Libro l WHERE l.titulo = :titulo") 15 | public Libro buscarPorTitulo(@Param("titulo") String titulo); 16 | 17 | @Query("SELECT l FROM Libro l WHERE l.autor.nombre = :nombre") 18 | public List buscarPorAutor(@Param ("nombre") String nombre); 19 | } 20 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/repositorios/UsuarioRepositorio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.repositorios; 3 | 4 | import com.egg.biblioteca.entidades.Usuario; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.data.jpa.repository.Query; 7 | import org.springframework.data.repository.query.Param; 8 | import org.springframework.stereotype.Repository; 9 | 10 | @Repository 11 | public interface UsuarioRepositorio extends JpaRepository { 12 | 13 | @Query("SELECT u FROM Usuario u WHERE u.email = :email") 14 | public Usuario buscarPorEmail(@Param("email")String email); 15 | } 16 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/servicios/AutorServicio.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.servicios; 2 | 3 | import com.egg.biblioteca.entidades.Autor; 4 | import com.egg.biblioteca.excepciones.MiException; 5 | import com.egg.biblioteca.repositorios.AutorRepositorio; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Optional; 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Transactional; 13 | 14 | @Service 15 | public class AutorServicio { 16 | 17 | @Autowired 18 | AutorRepositorio autorRepositorio; 19 | 20 | @Transactional 21 | public void crearAutor(String nombre) throws MiException{ 22 | 23 | validar(nombre); 24 | 25 | Autor autor = new Autor(); 26 | 27 | autor.setNombre(nombre); 28 | 29 | autorRepositorio.save(autor); 30 | 31 | } 32 | 33 | @Transactional(readOnly = true) 34 | public List listarAutores() { 35 | 36 | List autores = new ArrayList(); 37 | 38 | autores = autorRepositorio.findAll(); 39 | 40 | return autores; 41 | } 42 | 43 | @Transactional 44 | public void modificarAutor(String nombre, String id) throws MiException{ 45 | 46 | validar(nombre); 47 | 48 | Optional respuesta = autorRepositorio.findById(id); 49 | 50 | if (respuesta.isPresent()) { 51 | Autor autor = respuesta.get(); 52 | 53 | autor.setNombre(nombre); 54 | 55 | autorRepositorio.save(autor); 56 | 57 | } 58 | } 59 | 60 | @Transactional(readOnly = true) 61 | public Autor getOne(String id){ 62 | return autorRepositorio.getOne(id); 63 | } 64 | 65 | 66 | @Transactional 67 | public void eliminar(String id) throws MiException{ 68 | 69 | Autor autor = autorRepositorio.getById(id); 70 | 71 | autorRepositorio.delete(autor); 72 | 73 | } 74 | 75 | private void validar(String nombre) throws MiException { 76 | 77 | if (nombre.isEmpty() || nombre == null) { 78 | throw new MiException("el nombre no puede ser nulo o estar vacio"); 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/servicios/EditorialServicio.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.servicios; 2 | 3 | import com.egg.biblioteca.entidades.Editorial; 4 | import com.egg.biblioteca.excepciones.MiException; 5 | import com.egg.biblioteca.repositorios.EditorialRepositorio; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Optional; 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Transactional; 13 | 14 | @Service 15 | public class EditorialServicio { 16 | 17 | @Autowired 18 | EditorialRepositorio editorialRepositorio; 19 | 20 | @Transactional 21 | public void crearEditorial(String nombre) throws MiException{ 22 | 23 | validar(nombre); 24 | 25 | Editorial editorial = new Editorial(); 26 | 27 | editorial.setNombre(nombre); 28 | 29 | editorialRepositorio.save(editorial); 30 | } 31 | 32 | @Transactional(readOnly = true) 33 | public List listarEditoriales() { 34 | 35 | List editoriales = new ArrayList(); 36 | 37 | editoriales = editorialRepositorio.findAll(); 38 | 39 | return editoriales; 40 | } 41 | 42 | @Transactional 43 | public void modificarEditorial(String id, String nombre) throws MiException{ 44 | validar(nombre); 45 | 46 | Optional respuesta = editorialRepositorio.findById(id); 47 | 48 | if (respuesta.isPresent()) { 49 | 50 | Editorial editorial = respuesta.get(); 51 | 52 | editorial.setNombre(nombre); 53 | 54 | editorialRepositorio.save(editorial); 55 | } 56 | } 57 | 58 | private void validar(String nombre) throws MiException { 59 | 60 | if (nombre.isEmpty() || nombre == null) { 61 | throw new MiException("el nombre de la editorial no puede ser nulo o estar vacio"); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/servicios/LibroServicio.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.servicios; 2 | 3 | import com.egg.biblioteca.entidades.Autor; 4 | import com.egg.biblioteca.entidades.Editorial; 5 | import com.egg.biblioteca.entidades.Libro; 6 | import com.egg.biblioteca.excepciones.MiException; 7 | import com.egg.biblioteca.repositorios.AutorRepositorio; 8 | import com.egg.biblioteca.repositorios.EditorialRepositorio; 9 | import com.egg.biblioteca.repositorios.LibroRepositorio; 10 | import java.util.ArrayList; 11 | import java.util.Date; 12 | import java.util.List; 13 | import java.util.Optional; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Service; 16 | import org.springframework.transaction.annotation.Transactional; 17 | 18 | 19 | @Service 20 | public class LibroServicio { 21 | 22 | @Autowired 23 | private LibroRepositorio libroRepositorio; 24 | @Autowired 25 | private AutorRepositorio autorRepositorio; 26 | @Autowired 27 | private EditorialRepositorio editorialRepositorio; 28 | 29 | @Transactional 30 | public void crearLibro(Long isbn, String titulo, Integer ejemplares, String idAutor, String idEditorial) throws MiException{ 31 | 32 | validar(isbn, titulo, ejemplares, idAutor, idEditorial); 33 | 34 | Optional respuesta = libroRepositorio.findById(isbn); 35 | Optional respuestaAutor = autorRepositorio.findById(idAutor); 36 | Optional respuestaEditorial = editorialRepositorio.findById(idEditorial); 37 | 38 | Autor autor = new Autor(); 39 | Editorial editorial= new Editorial(); 40 | 41 | if(respuestaAutor.isPresent()){ 42 | 43 | autor = respuestaAutor.get(); 44 | } 45 | 46 | if(respuestaEditorial.isPresent()){ 47 | 48 | editorial = respuestaEditorial.get(); 49 | } 50 | 51 | Libro libro = new Libro(); 52 | 53 | libro.setIsbn(isbn); 54 | libro.setTitulo(titulo); 55 | libro.setEjemplares(ejemplares); 56 | libro.setAlta(new Date()); 57 | libro.setAutor(autor); 58 | libro.setEditorial(editorial); 59 | 60 | libroRepositorio.save(libro); 61 | } 62 | 63 | @Transactional(readOnly = true) 64 | public List listarLibros() { 65 | 66 | List libros = new ArrayList(); 67 | 68 | libros = libroRepositorio.findAll(); 69 | 70 | return libros; 71 | } 72 | 73 | @Transactional 74 | public void modificarLibro(Long isbn, String titulo, Integer ejemplares, String idAutor, String idEditorial) throws MiException{ 75 | 76 | validar(isbn, titulo, ejemplares, idAutor, idEditorial); 77 | 78 | Optional respuesta = libroRepositorio.findById(isbn); 79 | Optional respuestaAutor = autorRepositorio.findById(idAutor); 80 | Optional respuestaEditorial = editorialRepositorio.findById(idEditorial); 81 | 82 | Autor autor = new Autor(); 83 | Editorial editorial= new Editorial(); 84 | 85 | if(respuestaAutor.isPresent()){ 86 | 87 | autor = respuestaAutor.get(); 88 | } 89 | 90 | if(respuestaEditorial.isPresent()){ 91 | 92 | editorial = respuestaEditorial.get(); 93 | } 94 | 95 | if(respuesta.isPresent()){ 96 | 97 | Libro libro = respuesta.get(); 98 | 99 | 100 | libro.setTitulo(titulo); 101 | 102 | libro.setEjemplares(ejemplares); 103 | 104 | libro.setAutor(autor); 105 | 106 | libro.setEditorial(editorial); 107 | 108 | 109 | libroRepositorio.save(libro); 110 | 111 | } 112 | } 113 | 114 | @Transactional(readOnly = true) 115 | public Libro getOne(Long isbn){ 116 | return libroRepositorio.getOne(isbn); 117 | } 118 | 119 | private void validar(Long isbn, String titulo, Integer ejemplares, String idAutor, String idEditorial) throws MiException{ 120 | 121 | if(isbn == null){ 122 | throw new MiException("el isbn no puede ser nulo"); // 123 | } 124 | if(titulo.isEmpty() || titulo == null){ 125 | throw new MiException("el titulo no puede ser nulo o estar vacio"); 126 | } 127 | if(ejemplares == null){ 128 | throw new MiException("ejemplares no puede ser nulo"); 129 | } 130 | if(idAutor.isEmpty() || idAutor == null){ 131 | throw new MiException("el Autor no puede ser nulo o estar vacio"); 132 | } 133 | 134 | if(idEditorial.isEmpty() || idEditorial == null){ 135 | throw new MiException("La Editorial no puede ser nula o estar vacia"); 136 | } 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/java/com/egg/biblioteca/servicios/UsuarioServicio.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.servicios; 2 | 3 | import com.egg.biblioteca.entidades.Usuario; 4 | import com.egg.biblioteca.enumeraciones.Rol; 5 | import com.egg.biblioteca.excepciones.MiException; 6 | import com.egg.biblioteca.repositorios.UsuarioRepositorio; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import javax.servlet.http.HttpSession; 10 | import javax.transaction.Transactional; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.security.core.GrantedAuthority; 13 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 14 | import org.springframework.security.core.userdetails.User; 15 | import org.springframework.security.core.userdetails.UserDetails; 16 | import org.springframework.security.core.userdetails.UserDetailsService; 17 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 18 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 19 | import org.springframework.stereotype.Service; 20 | import org.springframework.web.context.request.RequestContextHolder; 21 | import org.springframework.web.context.request.ServletRequestAttributes; 22 | import org.springframework.web.multipart.MultipartFile; 23 | 24 | @Service 25 | public class UsuarioServicio implements UserDetailsService{ 26 | 27 | @Autowired 28 | private UsuarioRepositorio usuarioRepositorio; 29 | 30 | 31 | @Transactional 32 | public void registrar(MultipartFile archivo, String nombre, String email, String password, String password2) throws MiException { 33 | 34 | validar(nombre, email, password, password2); 35 | 36 | Usuario usuario = new Usuario(); 37 | 38 | usuario.setNombre(nombre); 39 | usuario.setEmail(email); 40 | 41 | usuario.setPassword(new BCryptPasswordEncoder().encode(password)); 42 | 43 | usuario.setRol(Rol.USER); 44 | 45 | usuarioRepositorio.save(usuario); 46 | } 47 | 48 | private void validar(String nombre, String email, String password, String password2) throws MiException { 49 | 50 | if (nombre.isEmpty() || nombre == null) { 51 | throw new MiException("el nombre no puede ser nulo o estar vacío"); 52 | } 53 | if (email.isEmpty() || email == null) { 54 | throw new MiException("el email no puede ser nulo o estar vacio"); 55 | } 56 | if (password.isEmpty() || password == null || password.length() <= 5) { 57 | throw new MiException("La contraseña no puede estar vacía, y debe tener más de 5 dígitos"); 58 | } 59 | 60 | if (!password.equals(password2)) { 61 | throw new MiException("Las contraseñas ingresadas deben ser iguales"); 62 | } 63 | 64 | } 65 | 66 | @Override 67 | public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { 68 | 69 | Usuario usuario = usuarioRepositorio.buscarPorEmail(email); 70 | 71 | if (usuario != null) { 72 | 73 | List permisos = new ArrayList(); 74 | 75 | GrantedAuthority p = new SimpleGrantedAuthority("ROLE_"+ usuario.getRol().toString()); 76 | 77 | permisos.add(p); 78 | 79 | ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); 80 | 81 | HttpSession session = attr.getRequest().getSession(true); 82 | 83 | session.setAttribute("usuariosession", usuario); 84 | 85 | return new User(usuario.getEmail(), usuario.getPassword(),permisos); 86 | }else{ 87 | return null; 88 | } 89 | 90 | } 91 | 92 | 93 | 94 | 95 | 96 | } 97 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url: jdbc:mysql://localhost:3306/biblioteca?allowPublicKeyRetrieval=true&useSSL=false&useTimezone=true&serverTimezone=GMT&characterEncoding=UTF-8 2 | spring.datasource.username: root 3 | spring.datasource.password: root 4 | spring.datasource.driver-class-name: com.mysql.cj.jdbc.Driver 5 | spring.jpa.show-sql: true 6 | spring.jpa.hibernate.ddl-auto: update 7 | spring.jpa.properties.hibernate.dialect: org.hibernate.dialect.MySQL5InnoDBDialect 8 | spring.thymeleaf.cache: false 9 | 10 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/static/css/formulario.css: -------------------------------------------------------------------------------- 1 | .navBar{ 2 | background-color: #fff !important; 3 | } 4 | 5 | .elementosNav{ 6 | display: flex; 7 | width: 30%; 8 | justify-content: space-around; 9 | color: #37474f; 10 | font-weight: 700; 11 | } 12 | 13 | .elementos{ 14 | margin-right: 50px; 15 | } 16 | 17 | .containerImg{ 18 | width: 20%; 19 | } 20 | 21 | .logo{ 22 | width: 40%; 23 | margin: auto; 24 | } 25 | 26 | 27 | .mensajeExito{ 28 | width: 20%; 29 | margin: auto; 30 | text-align: center; 31 | } 32 | 33 | .mensajeError{ 34 | width: 20%; 35 | margin: auto; 36 | text-align: center; 37 | } 38 | 39 | .formulario{ 40 | width: 50%; 41 | margin: auto; 42 | display: flex; 43 | flex-direction: column; 44 | } 45 | 46 | .divVolver{ 47 | width: 50%; 48 | display: flex; 49 | justify-content: center; 50 | align-items: center; 51 | margin: auto; 52 | } 53 | 54 | .botonVolver{ 55 | width: 70%; 56 | } 57 | 58 | .botones{ 59 | box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 60 | -webkit-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 61 | -moz-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 62 | } 63 | 64 | .botones:active{ 65 | box-shadow: none; 66 | } 67 | 68 | .containerFooter{ 69 | display: flex; 70 | justify-content: space-around; 71 | align-items: center; 72 | } -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/static/css/index.css: -------------------------------------------------------------------------------- 1 | .navBar{ 2 | background-color: #fff !important; 3 | } 4 | 5 | .elementosNav{ 6 | display: flex; 7 | width: 30%; 8 | justify-content: space-around; 9 | color: #37474f; 10 | font-weight: 700; 11 | } 12 | 13 | .elementos{ 14 | margin-right: 50px; 15 | } 16 | 17 | .containerImg{ 18 | width: 20%; 19 | } 20 | 21 | .logo{ 22 | width: 40%; 23 | margin: auto; 24 | } 25 | 26 | .tituloBiblioteca{ 27 | width: 80%; 28 | text-align: center; 29 | font-size: 40px; 30 | margin-top: 80px; 31 | font-weight: 500; 32 | } 33 | 34 | .header{ 35 | background-image: url(../img/FondoZoom_2.jpg); 36 | background-size: cover; 37 | height: 550px; 38 | display: flex; 39 | justify-content: end; 40 | } 41 | 42 | .contenedorLibros{ 43 | margin-top: 80px; 44 | display: flex; 45 | flex-direction: column; 46 | justify-content: center; 47 | align-items: center; 48 | } 49 | 50 | .tituloLibros{ 51 | font-size: 22px; 52 | font-weight: 500; 53 | } 54 | 55 | .contenedorMain{ 56 | width: 50%; 57 | display: flex; 58 | flex-direction: column; 59 | align-items: center; 60 | } 61 | 62 | .containerFooter{ 63 | display: flex; 64 | justify-content: space-around; 65 | align-items: center; 66 | } 67 | 68 | .boton{ 69 | background-color: #ffcb00; 70 | box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 71 | -webkit-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 72 | -moz-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 73 | } 74 | 75 | .boton:hover{ 76 | background-color: #ffcb00; 77 | } 78 | .boton:active{ 79 | box-shadow: none; 80 | } -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/static/css/inicio.css: -------------------------------------------------------------------------------- 1 | .navBar{ 2 | background-color: #fff !important; 3 | } 4 | 5 | .elementosNav{ 6 | display: flex; 7 | width: 30%; 8 | justify-content: space-around; 9 | color: #37474f; 10 | font-weight: 700; 11 | } 12 | 13 | .containerImg{ 14 | width: 20%; 15 | } 16 | 17 | .logo{ 18 | width: 40%; 19 | margin: auto; 20 | } 21 | 22 | .main{ 23 | background-image: url(../img/FondoZoom.jpg); 24 | background-size: cover; 25 | height: 400px; 26 | display: flex; 27 | align-items: center; 28 | } 29 | 30 | .containerFooter{ 31 | display: flex; 32 | justify-content: space-around; 33 | align-items: center; 34 | } 35 | 36 | .boton{ 37 | background-color: #ffcb00; 38 | box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 39 | -webkit-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 40 | -moz-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 41 | margin-right: 10px; 42 | margin-left: -10px; 43 | } 44 | 45 | .botonCargar{ 46 | box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 47 | -webkit-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 48 | -moz-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 49 | } 50 | 51 | .boton:active{ 52 | box-shadow: none; 53 | } 54 | .botonCargar:active{ 55 | box-shadow: none; 56 | } -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/static/img/Egg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V3/src/main/resources/static/img/Egg.png -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/static/img/FondoZoom.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V3/src/main/resources/static/img/FondoZoom.jpg -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/static/img/FondoZoom_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V3/src/main/resources/static/img/FondoZoom_1.jpg -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/static/img/FondoZoom_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V3/src/main/resources/static/img/FondoZoom_2.jpg -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/static/img/imgEgg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V3/src/main/resources/static/img/imgEgg.png -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/static/img/imgEggBlanco.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V3/src/main/resources/static/img/imgEggBlanco.jpg -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/templates/fragments/head.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Biblioteca Egg 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/templates/fragments/navbar.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Biblioteca Egg 7 | 8 | 9 | 10 | 11 | 12 | 65 | 66 |
67 |
68 |
Exito
69 |

70 |
71 |
72 |
73 |
74 |
Error 👎
75 |

76 |
77 |
78 |
79 |
80 |
81 | BIBLIOTECA EGG 82 |
83 |
84 |

Encontrá todos los Libros Aquí!

85 | 86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 | 94 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/templates/inicio.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Inicio 6 | 7 | 8 | 9 | 10 | 11 | 64 | 65 |
66 |
67 |
68 | BIBLIOTECA EGG 69 |
70 |
71 |

72 | Ver Listado 73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | 81 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Biblioteca Egg - Acceder 6 | 7 | 8 | 9 | 10 | 11 | 32 | 33 | 34 | 35 |
36 |
37 |
38 |
Error!
39 |

40 |
41 |
42 |
43 |
44 |
Exito!
45 |

46 |
47 |
48 | 49 |
50 | 51 | 52 |
53 |

Accede a la Biblioteca!

54 |
55 | 56 |
57 | 58 |
59 | 60 |
61 | 62 |
63 | 64 | 65 | 66 |
67 | 68 | 69 |
70 |
71 |
72 | Volver 73 |
74 |
75 |
76 |
77 | 78 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/main/resources/templates/registro.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Biblioteca Egg - Registrate! 6 | 7 | 8 | 9 | 10 | 11 | 30 | 31 |
32 |
33 |
Error!
34 |

35 |
36 |
37 |
38 |
39 |
Exito!
40 |

41 |
42 |
43 | 44 |
45 | 46 |
47 | 48 | 49 |
50 |

Registrate!

51 |
52 |
53 | 54 |
55 |
56 | 57 |
58 | 59 |
60 | 61 |
62 |
63 | 64 |
65 | 66 | 67 | 68 |
69 | 70 | 71 |
72 |
73 |
74 | Volver 75 |
76 |
77 |
78 |
79 | 80 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /Biblioteca_V3/src/test/java/com/egg/biblioteca/BibliotecaApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class BibliotecaApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Biblioteca_V4/.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 | -------------------------------------------------------------------------------- /Biblioteca_V4/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.7 9 | 10 | 11 | com.egg 12 | biblioteca 13 | 0.0.1-SNAPSHOT 14 | Biblioteca 15 | Proyecto de Biblioteca para Egg. 16 | 17 | 1.8 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-data-jpa 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-thymeleaf 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | mysql 35 | mysql-connector-java 36 | runtime 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-security 46 | 47 | 48 | org.thymeleaf.extras 49 | thymeleaf-extras-springsecurity5 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-maven-plugin 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/BibliotecaApplication.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BibliotecaApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BibliotecaApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/SeguridadWeb.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca; 2 | 3 | import com.egg.biblioteca.servicios.UsuarioServicio; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 7 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 9 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 10 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 11 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 12 | 13 | @Configuration 14 | @EnableWebSecurity 15 | @EnableGlobalMethodSecurity(prePostEnabled = true) 16 | public class SeguridadWeb extends WebSecurityConfigurerAdapter { 17 | 18 | @Autowired 19 | public UsuarioServicio usuarioServicio; 20 | 21 | @Autowired 22 | public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{ 23 | auth.userDetailsService(usuarioServicio) 24 | .passwordEncoder(new BCryptPasswordEncoder()); 25 | } 26 | 27 | @Override 28 | protected void configure(HttpSecurity http) throws Exception { 29 | http 30 | .authorizeRequests() 31 | .antMatchers("/admin/*").hasRole("ADMIN") 32 | .antMatchers("/css/*", "/js/*", "/img/*", "/**") 33 | .permitAll() 34 | .and().formLogin() 35 | .loginPage("/login") 36 | .loginProcessingUrl("/logincheck") 37 | .usernameParameter("email") 38 | .passwordParameter("password") 39 | .defaultSuccessUrl("/inicio") 40 | .permitAll() 41 | .and().logout() 42 | .logoutUrl("/logout") 43 | .logoutSuccessUrl("/login") 44 | .permitAll() 45 | .and().csrf() 46 | .disable(); 47 | 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/controladores/AdminControlador.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.controladores; 3 | 4 | import com.egg.biblioteca.entidades.Usuario; 5 | import com.egg.biblioteca.servicios.UsuarioServicio; 6 | import java.util.List; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.ui.ModelMap; 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | 14 | @Controller 15 | @RequestMapping("/admin") 16 | public class AdminControlador { 17 | 18 | @Autowired 19 | private UsuarioServicio usuarioServicio; 20 | 21 | @GetMapping("/dashboard") 22 | public String panelAdministrativo(){ 23 | return "panel.html"; 24 | } 25 | 26 | @GetMapping("/usuarios") 27 | public String listar(ModelMap modelo) { 28 | List usuarios = usuarioServicio.listarUsuarios(); 29 | modelo.addAttribute("usuarios", usuarios); 30 | 31 | return "usuario_list"; 32 | } 33 | 34 | @GetMapping("/modificarRol/{id}") 35 | public String cambiarRol(@PathVariable String id){ 36 | usuarioServicio.cambiarRol(id); 37 | 38 | return "redirect:/admin/usuarios"; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/controladores/AutorControlador.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.controladores; 3 | 4 | import com.egg.biblioteca.entidades.Autor; 5 | import com.egg.biblioteca.excepciones.MiException; 6 | import com.egg.biblioteca.servicios.AutorServicio; 7 | import java.util.List; 8 | import java.util.logging.Level; 9 | import java.util.logging.Logger; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Controller; 12 | import org.springframework.ui.ModelMap; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.PathVariable; 15 | import org.springframework.web.bind.annotation.PostMapping; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.RequestParam; 18 | 19 | @Controller 20 | @RequestMapping("/autor") //localhost:8080/autor 21 | public class AutorControlador { 22 | 23 | @Autowired 24 | private AutorServicio autorServicio; 25 | 26 | @GetMapping("/registrar") //localhost:8080/autor/registrar 27 | public String registrar(){ 28 | return "autor_form.html"; 29 | } 30 | 31 | 32 | @PostMapping("/registro") 33 | public String registro(@RequestParam String nombre, ModelMap modelo){ 34 | 35 | try { 36 | autorServicio.crearAutor(nombre); 37 | 38 | modelo.put("exito", "El Autor fue registrado correctamente!"); 39 | } catch (MiException ex) { 40 | 41 | modelo.put("error", ex.getMessage()); 42 | return "autor_form.html"; 43 | } 44 | 45 | return "index.html"; 46 | } 47 | 48 | @GetMapping("/lista") 49 | public String listar(ModelMap modelo){ 50 | 51 | List autores = autorServicio.listarAutores(); 52 | 53 | modelo.addAttribute("autores", autores); 54 | 55 | return "autor_list.html"; 56 | } 57 | 58 | @GetMapping("/modificar/{id}") 59 | public String modificar(@PathVariable String id, ModelMap modelo){ 60 | modelo.put("autor", autorServicio.getOne(id)); 61 | 62 | return "autor_modificar.html"; 63 | } 64 | 65 | @PostMapping("/modificar/{id}") 66 | public String modificar(@PathVariable String id, String nombre, ModelMap modelo){ 67 | try { 68 | autorServicio.modificarAutor(nombre, id); 69 | 70 | return "redirect:../lista"; 71 | } catch (MiException ex) { 72 | modelo.put("error", ex.getMessage()); 73 | return "autor_modificar.html"; 74 | } 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/controladores/EditorialControlador.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.controladores; 3 | 4 | import com.egg.biblioteca.excepciones.MiException; 5 | import com.egg.biblioteca.servicios.EditorialServicio; 6 | import java.util.logging.Level; 7 | import java.util.logging.Logger; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.ui.ModelMap; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RequestParam; 15 | 16 | @Controller 17 | @RequestMapping("/editorial") 18 | public class EditorialControlador { 19 | @Autowired 20 | private EditorialServicio editorialServicio; 21 | 22 | @GetMapping("/registrar") //localhost:8080/autor/registrar 23 | public String registrar(){ 24 | return "editorial_form.html"; 25 | } 26 | 27 | 28 | @PostMapping("/registro") 29 | public String registro(@RequestParam String nombre, ModelMap modelo){ 30 | 31 | try { 32 | editorialServicio.crearEditorial(nombre); 33 | 34 | modelo.put("exito", "La Editorial fue registrada correctamente!"); 35 | } catch (MiException ex) { 36 | 37 | modelo.put("error", ex.getMessage()); 38 | return "editorial_form.html"; 39 | } 40 | 41 | return "index.html"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/controladores/ErroresControlador.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.controladores; 3 | 4 | import javax.servlet.http.HttpServletRequest; 5 | import org.springframework.boot.web.servlet.error.ErrorController; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.servlet.ModelAndView; 10 | 11 | 12 | @Controller 13 | public class ErroresControlador implements ErrorController { 14 | 15 | @RequestMapping(value = "/error", method = { RequestMethod.GET, RequestMethod.POST }) 16 | public ModelAndView renderErrorPage(HttpServletRequest httpRequest) { 17 | 18 | ModelAndView errorPage = new ModelAndView("error"); 19 | 20 | String errorMsg = ""; 21 | 22 | int httpErrorCode = getErrorCode(httpRequest); 23 | 24 | switch (httpErrorCode) { 25 | case 400: { 26 | errorMsg = "El recurso solicitado no existe."; 27 | break; 28 | } 29 | case 403: { 30 | errorMsg = "No tiene permisos para acceder al recurso."; 31 | break; 32 | } 33 | case 401: { 34 | errorMsg = "No se encuentra autorizado."; 35 | break; 36 | } 37 | case 404: { 38 | errorMsg = "El recurso solicitado no fue encontrado."; 39 | break; 40 | } 41 | case 500: { 42 | errorMsg = "Ocurrió un error interno."; 43 | break; 44 | } 45 | } 46 | 47 | errorPage.addObject("codigo", httpErrorCode); 48 | errorPage.addObject("mensaje", errorMsg); 49 | return errorPage; 50 | } 51 | 52 | private int getErrorCode(HttpServletRequest httpRequest) { 53 | return (Integer) httpRequest.getAttribute("javax.servlet.error.status_code"); 54 | } 55 | 56 | 57 | public String getErrorPath() { 58 | return "/error.html"; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/controladores/ImagenControlador.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.controladores; 3 | 4 | import com.egg.biblioteca.entidades.Usuario; 5 | import com.egg.biblioteca.servicios.UsuarioServicio; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.HttpHeaders; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.MediaType; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.stereotype.Controller; 12 | import org.springframework.web.bind.annotation.GetMapping; 13 | import org.springframework.web.bind.annotation.PathVariable; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | 16 | @Controller 17 | @RequestMapping("/imagen") 18 | public class ImagenControlador { 19 | 20 | @Autowired 21 | UsuarioServicio usuarioServicio; 22 | 23 | @GetMapping("/perfil/{id}") 24 | public ResponseEntity imagenUsuario (@PathVariable String id){ 25 | Usuario usuario = usuarioServicio.getOne(id); 26 | 27 | byte[] imagen= usuario.getImagen().getContenido(); 28 | 29 | HttpHeaders headers = new HttpHeaders(); 30 | 31 | headers.setContentType(MediaType.IMAGE_JPEG); 32 | 33 | 34 | 35 | return new ResponseEntity<>(imagen,headers, HttpStatus.OK); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/controladores/LibroControlador.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.controladores; 2 | 3 | import com.egg.biblioteca.entidades.Autor; 4 | import com.egg.biblioteca.entidades.Editorial; 5 | import com.egg.biblioteca.entidades.Libro; 6 | import com.egg.biblioteca.excepciones.MiException; 7 | import com.egg.biblioteca.servicios.AutorServicio; 8 | import com.egg.biblioteca.servicios.EditorialServicio; 9 | import com.egg.biblioteca.servicios.LibroServicio; 10 | import java.util.List; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Controller; 13 | import org.springframework.ui.ModelMap; 14 | import org.springframework.web.bind.annotation.GetMapping; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.PostMapping; 17 | import org.springframework.web.bind.annotation.RequestMapping; 18 | import org.springframework.web.bind.annotation.RequestParam; 19 | import org.springframework.web.multipart.MultipartFile; 20 | 21 | @Controller 22 | @RequestMapping("/libro") 23 | public class LibroControlador { 24 | 25 | @Autowired 26 | private LibroServicio libroServicio; 27 | @Autowired 28 | private AutorServicio autorServicio; 29 | @Autowired 30 | private EditorialServicio editorialServicio; 31 | 32 | 33 | @GetMapping("/registrar") //localhost:8080/libro/registrar 34 | public String registrar(ModelMap modelo) { 35 | List autores = autorServicio.listarAutores(); 36 | List editoriales = editorialServicio.listarEditoriales(); 37 | 38 | modelo.addAttribute("autores", autores); 39 | modelo.addAttribute("editoriales", editoriales); 40 | 41 | return "libro_form.html"; 42 | } 43 | 44 | @PostMapping("/registro") 45 | public String registro(@RequestParam(required = false) Long isbn, @RequestParam String titulo, 46 | @RequestParam(required = false) Integer ejemplares, @RequestParam String idAutor, 47 | @RequestParam String idEditorial, ModelMap modelo, @RequestParam(required = false) MultipartFile archivo) { 48 | try { 49 | 50 | libroServicio.crearLibro(archivo,isbn, titulo, ejemplares, idAutor, idEditorial); 51 | 52 | modelo.put("exito", "El Libro fue cargado correctamente!"); 53 | 54 | } catch (MiException ex) { 55 | List autores = autorServicio.listarAutores(); 56 | List editoriales = editorialServicio.listarEditoriales(); 57 | 58 | modelo.addAttribute("autores", autores); 59 | modelo.addAttribute("editoriales", editoriales); 60 | modelo.put("error", ex.getMessage()); 61 | 62 | return "libro_form.html"; // volvemos a cargar el formulario. 63 | } 64 | return "index.html"; 65 | } 66 | 67 | @GetMapping("/lista") 68 | public String listar(ModelMap modelo) { 69 | List libros = libroServicio.listarLibros(); 70 | modelo.addAttribute("libros", libros); 71 | 72 | return "libro_list"; 73 | } 74 | 75 | 76 | @GetMapping("/modificar/{isbn}") 77 | public String modificar(@PathVariable Long isbn, ModelMap modelo) { 78 | 79 | modelo.put("libro", libroServicio.getOne(isbn)); 80 | 81 | List autores = autorServicio.listarAutores(); 82 | List editoriales = editorialServicio.listarEditoriales(); 83 | 84 | modelo.addAttribute("autores", autores); 85 | modelo.addAttribute("editoriales", editoriales); 86 | 87 | return "libro_modificar.html"; 88 | } 89 | 90 | @PostMapping("/modificar/{isbn}") 91 | public String modificar(@PathVariable Long isbn, String titulo, Integer ejemplares, String idAutor, String idEditorial, ModelMap modelo, MultipartFile archivo) { 92 | try { 93 | List autores = autorServicio.listarAutores(); 94 | List editoriales = editorialServicio.listarEditoriales(); 95 | 96 | modelo.addAttribute("autores", autores); 97 | modelo.addAttribute("editoriales", editoriales); 98 | 99 | libroServicio.modificarLibro(archivo, isbn, titulo, ejemplares, idAutor, idEditorial); 100 | 101 | 102 | return "redirect:../lista"; 103 | 104 | } catch (MiException ex) { 105 | List autores = autorServicio.listarAutores(); 106 | List editoriales = editorialServicio.listarEditoriales(); 107 | 108 | modelo.put("error", ex.getMessage()); 109 | 110 | modelo.addAttribute("autores", autores); 111 | modelo.addAttribute("editoriales", editoriales); 112 | 113 | return "libro_modificar.html"; 114 | } 115 | 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/controladores/PortalControlador.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.controladores; 2 | 3 | import com.egg.biblioteca.entidades.Usuario; 4 | import com.egg.biblioteca.excepciones.MiException; 5 | import com.egg.biblioteca.servicios.UsuarioServicio; 6 | import java.util.List; 7 | import javax.servlet.http.HttpSession; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.security.access.prepost.PreAuthorize; 10 | import org.springframework.stereotype.Controller; 11 | import org.springframework.ui.ModelMap; 12 | import org.springframework.web.bind.annotation.GetMapping; 13 | import org.springframework.web.bind.annotation.PathVariable; 14 | import org.springframework.web.bind.annotation.PostMapping; 15 | import org.springframework.web.bind.annotation.RequestMapping; 16 | import org.springframework.web.bind.annotation.RequestParam; 17 | import org.springframework.web.multipart.MultipartFile; 18 | 19 | @Controller 20 | @RequestMapping("/") 21 | public class PortalControlador { 22 | 23 | @Autowired 24 | private UsuarioServicio usuarioServicio; 25 | 26 | @GetMapping("/") 27 | public String index() { 28 | 29 | return "index.html"; 30 | } 31 | 32 | @GetMapping("/registrar") 33 | public String registrar() { 34 | return "registro.html"; 35 | } 36 | 37 | @PostMapping("/registro") 38 | public String registro(@RequestParam String nombre, @RequestParam String email, @RequestParam String password, 39 | String password2, ModelMap modelo, MultipartFile archivo) { 40 | 41 | try { 42 | usuarioServicio.registrar(archivo, nombre, email, password, password2); 43 | 44 | modelo.put("exito", "Usuario registrado correctamente!"); 45 | 46 | return "index.html"; 47 | } catch (MiException ex) { 48 | 49 | modelo.put("error", ex.getMessage()); 50 | modelo.put("nombre", nombre); 51 | modelo.put("email", email); 52 | 53 | return "registro.html"; 54 | } 55 | 56 | } 57 | 58 | @GetMapping("/login") 59 | public String login(@RequestParam(required = false) String error, ModelMap modelo ) { 60 | 61 | if (error != null) { 62 | modelo.put("error", "Usuario o Contraseña invalidos!"); 63 | } 64 | 65 | return "login.html"; 66 | } 67 | 68 | @PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')") 69 | @GetMapping("/inicio") 70 | public String inicio(HttpSession session) { 71 | 72 | Usuario logueado = (Usuario) session.getAttribute("usuariosession"); 73 | 74 | if (logueado.getRol().toString().equals("ADMIN")) { 75 | return "redirect:/admin/dashboard"; 76 | } 77 | 78 | return "inicio.html"; 79 | } 80 | 81 | @PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')") 82 | @GetMapping("/perfil") 83 | public String perfil(ModelMap modelo,HttpSession session){ 84 | Usuario usuario = (Usuario) session.getAttribute("usuariosession"); 85 | modelo.put("usuario", usuario); 86 | return "usuario_modificar.html"; 87 | } 88 | 89 | @PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')") 90 | @PostMapping("/perfil/{id}") 91 | public String actualizar(MultipartFile archivo,@PathVariable String id, @RequestParam String nombre,@RequestParam String email, 92 | @RequestParam String password,@RequestParam String password2, ModelMap modelo) { 93 | 94 | try { 95 | usuarioServicio.actualizar(archivo, id, nombre, email, password, password2); 96 | 97 | modelo.put("exito", "Usuario actualizado correctamente!"); 98 | 99 | return "inicio.html"; 100 | } catch (MiException ex) { 101 | 102 | modelo.put("error", ex.getMessage()); 103 | modelo.put("nombre", nombre); 104 | modelo.put("email", email); 105 | 106 | return "usuario_modificar.html"; 107 | } 108 | 109 | } 110 | 111 | 112 | } 113 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/entidades/Autor.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.entidades; 3 | 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | import org.hibernate.annotations.GenericGenerator; 8 | 9 | @Entity 10 | public class Autor { 11 | 12 | @Id 13 | @GeneratedValue(generator = "uuid") 14 | @GenericGenerator(name = "uuid", strategy = "uuid2") 15 | private String id; 16 | private String nombre; 17 | 18 | public Autor() { 19 | } 20 | 21 | public String getId() { 22 | return id; 23 | } 24 | 25 | public void setId(String id) { 26 | this.id = id; 27 | } 28 | 29 | public String getNombre() { 30 | return nombre; 31 | } 32 | 33 | public void setNombre(String nombre) { 34 | this.nombre = nombre; 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/entidades/Editorial.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.entidades; 3 | 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | import org.hibernate.annotations.GenericGenerator; 8 | 9 | @Entity 10 | public class Editorial { 11 | @Id 12 | @GeneratedValue(generator = "uuid") 13 | @GenericGenerator(name = "uuid", strategy = "uuid2") 14 | private String id; 15 | private String nombre; 16 | 17 | public Editorial() { 18 | } 19 | 20 | public String getId() { 21 | return id; 22 | } 23 | 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | 28 | public String getNombre() { 29 | return nombre; 30 | } 31 | 32 | public void setNombre(String nombre) { 33 | this.nombre = nombre; 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/entidades/Imagen.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.entidades; 3 | 4 | import javax.persistence.Basic; 5 | import javax.persistence.Entity; 6 | import javax.persistence.FetchType; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.Id; 9 | import javax.persistence.Lob; 10 | import org.hibernate.annotations.GenericGenerator; 11 | 12 | @Entity 13 | public class Imagen { 14 | @Id 15 | @GeneratedValue(generator = "uuid") 16 | @GenericGenerator(name = "uuid", strategy = "uuid2") 17 | private String id; 18 | 19 | private String mime; 20 | 21 | private String nombre; 22 | 23 | @Lob @Basic(fetch = FetchType.LAZY) 24 | private byte[] contenido; 25 | 26 | public Imagen() { 27 | } 28 | 29 | public String getId() { 30 | return id; 31 | } 32 | 33 | public void setId(String id) { 34 | this.id = id; 35 | } 36 | 37 | public String getMime() { 38 | return mime; 39 | } 40 | 41 | public void setMime(String mime) { 42 | this.mime = mime; 43 | } 44 | 45 | public String getNombre() { 46 | return nombre; 47 | } 48 | 49 | public void setNombre(String nombre) { 50 | this.nombre = nombre; 51 | } 52 | 53 | public byte[] getContenido() { 54 | return contenido; 55 | } 56 | 57 | public void setContenido(byte[] contenido) { 58 | this.contenido = contenido; 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/entidades/Libro.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.entidades; 3 | 4 | import java.util.Date; 5 | import javax.persistence.Entity; 6 | import javax.persistence.Id; 7 | import javax.persistence.ManyToOne; 8 | import javax.persistence.OneToOne; 9 | import javax.persistence.Temporal; 10 | import javax.persistence.TemporalType; 11 | 12 | @Entity 13 | public class Libro { 14 | @Id 15 | private Long isbn; 16 | private String titulo; 17 | private Integer ejemplares; 18 | 19 | @Temporal(TemporalType.DATE) 20 | private Date alta; 21 | 22 | @ManyToOne 23 | private Autor autor; 24 | 25 | @ManyToOne 26 | private Editorial editorial; 27 | // 28 | // @OneToOne 29 | // private Imagen imagen; 30 | 31 | public Libro() { 32 | } 33 | 34 | public Long getIsbn() { 35 | return isbn; 36 | } 37 | 38 | public void setIsbn(Long isbn) { 39 | this.isbn = isbn; 40 | } 41 | 42 | public String getTitulo() { 43 | return titulo; 44 | } 45 | 46 | public void setTitulo(String titulo) { 47 | this.titulo = titulo; 48 | } 49 | 50 | public Integer getEjemplares() { 51 | return ejemplares; 52 | } 53 | 54 | public void setEjemplares(Integer ejemplares) { 55 | this.ejemplares = ejemplares; 56 | } 57 | 58 | public Date getAlta() { 59 | return alta; 60 | } 61 | 62 | public void setAlta(Date alta) { 63 | this.alta = alta; 64 | } 65 | 66 | public Autor getAutor() { 67 | return autor; 68 | } 69 | 70 | public void setAutor(Autor autor) { 71 | this.autor = autor; 72 | } 73 | 74 | public Editorial getEditorial() { 75 | return editorial; 76 | } 77 | 78 | public void setEditorial(Editorial editorial) { 79 | this.editorial = editorial; 80 | } 81 | // 82 | // public Imagen getImagen() { 83 | // return imagen; 84 | // } 85 | // 86 | // public void setImagen(Imagen imagen) { 87 | // this.imagen = imagen; 88 | // } 89 | // 90 | 91 | } 92 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/entidades/Usuario.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.entidades; 3 | 4 | import com.egg.biblioteca.enumeraciones.Rol; 5 | import javax.persistence.Entity; 6 | import javax.persistence.EnumType; 7 | import javax.persistence.Enumerated; 8 | import javax.persistence.GeneratedValue; 9 | import javax.persistence.Id; 10 | import javax.persistence.OneToOne; 11 | import org.hibernate.annotations.GenericGenerator; 12 | 13 | @Entity 14 | public class Usuario { 15 | @Id 16 | @GeneratedValue(generator = "uuid") 17 | @GenericGenerator(name = "uuid", strategy = "uuid2") 18 | private String id; 19 | 20 | private String nombre; 21 | private String email; 22 | private String password; 23 | 24 | @Enumerated(EnumType.STRING) 25 | private Rol rol; 26 | 27 | @OneToOne 28 | private Imagen imagen; 29 | 30 | public Imagen getImagen() { 31 | return imagen; 32 | } 33 | 34 | public void setImagen(Imagen imagen) { 35 | this.imagen = imagen; 36 | } 37 | 38 | 39 | public Usuario() { 40 | } 41 | public String getId() { 42 | return id; 43 | } 44 | 45 | public void setId(String id) { 46 | this.id = id; 47 | } 48 | 49 | public String getNombre() { 50 | return nombre; 51 | } 52 | 53 | public void setNombre(String nombre) { 54 | this.nombre = nombre; 55 | } 56 | 57 | public String getEmail() { 58 | return email; 59 | } 60 | 61 | public void setEmail(String email) { 62 | this.email = email; 63 | } 64 | 65 | public String getPassword() { 66 | return password; 67 | } 68 | 69 | public void setPassword(String password) { 70 | this.password = password; 71 | } 72 | 73 | public Rol getRol() { 74 | return rol; 75 | } 76 | 77 | public void setRol(Rol rol) { 78 | this.rol = rol; 79 | } 80 | 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/enumeraciones/Rol.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.enumeraciones; 3 | 4 | 5 | public enum Rol { 6 | USER, 7 | ADMIN; 8 | } 9 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/excepciones/MiException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.excepciones; 3 | 4 | 5 | public class MiException extends Exception{ 6 | 7 | public MiException(String msg) { 8 | super(msg); 9 | } 10 | 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/repositorios/AutorRepositorio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.repositorios; 3 | 4 | import com.egg.biblioteca.entidades.Autor; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | @Repository 9 | public interface AutorRepositorio extends JpaRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/repositorios/EditorialRepositorio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.repositorios; 3 | 4 | import com.egg.biblioteca.entidades.Editorial; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | @Repository 9 | public interface EditorialRepositorio extends JpaRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/repositorios/ImagenRepositorio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.repositorios; 3 | 4 | import com.egg.biblioteca.entidades.Imagen; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | @Repository 9 | public interface ImagenRepositorio extends JpaRepository{ 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/repositorios/LibroRepositorio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.repositorios; 3 | 4 | import com.egg.biblioteca.entidades.Libro; 5 | import java.util.List; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.data.repository.query.Param; 9 | import org.springframework.stereotype.Repository; 10 | 11 | @Repository 12 | public interface LibroRepositorio extends JpaRepository{ 13 | 14 | @Query("SELECT l FROM Libro l WHERE l.titulo = :titulo") 15 | public Libro buscarPorTitulo(@Param("titulo") String titulo); 16 | 17 | @Query("SELECT l FROM Libro l WHERE l.autor.nombre = :nombre") 18 | public List buscarPorAutor(@Param ("nombre") String nombre); 19 | } 20 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/repositorios/UsuarioRepositorio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.repositorios; 3 | 4 | import com.egg.biblioteca.entidades.Usuario; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.data.jpa.repository.Query; 7 | import org.springframework.data.repository.query.Param; 8 | import org.springframework.stereotype.Repository; 9 | 10 | @Repository 11 | public interface UsuarioRepositorio extends JpaRepository { 12 | 13 | @Query("SELECT u FROM Usuario u WHERE u.email = :email") 14 | public Usuario buscarPorEmail(@Param("email")String email); 15 | } 16 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/servicios/AutorServicio.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.servicios; 2 | 3 | import com.egg.biblioteca.entidades.Autor; 4 | import com.egg.biblioteca.excepciones.MiException; 5 | import com.egg.biblioteca.repositorios.AutorRepositorio; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Optional; 9 | import javax.transaction.Transactional; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | 13 | @Service 14 | public class AutorServicio { 15 | 16 | @Autowired 17 | AutorRepositorio autorRepositorio; 18 | 19 | @Transactional 20 | public void crearAutor(String nombre) throws MiException{ 21 | 22 | validar(nombre); 23 | 24 | Autor autor = new Autor(); 25 | 26 | autor.setNombre(nombre); 27 | 28 | autorRepositorio.save(autor); 29 | 30 | } 31 | 32 | public List listarAutores() { 33 | 34 | List autores = new ArrayList(); 35 | 36 | autores = autorRepositorio.findAll(); 37 | 38 | return autores; 39 | } 40 | 41 | @Transactional 42 | public void modificarAutor(String nombre, String id) throws MiException{ 43 | 44 | validar(nombre); 45 | 46 | Optional respuesta = autorRepositorio.findById(id); 47 | 48 | if (respuesta.isPresent()) { 49 | Autor autor = respuesta.get(); 50 | 51 | autor.setNombre(nombre); 52 | 53 | autorRepositorio.save(autor); 54 | 55 | } 56 | } 57 | 58 | public Autor getOne(String id){ 59 | return autorRepositorio.getOne(id); 60 | } 61 | 62 | private void validar(String nombre) throws MiException { 63 | 64 | if (nombre.isEmpty() || nombre == null) { 65 | throw new MiException("el nombre no puede ser nulo o estar vacio"); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/servicios/EditorialServicio.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.servicios; 2 | 3 | import com.egg.biblioteca.entidades.Editorial; 4 | import com.egg.biblioteca.excepciones.MiException; 5 | import com.egg.biblioteca.repositorios.EditorialRepositorio; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Optional; 9 | import javax.transaction.Transactional; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | 13 | @Service 14 | public class EditorialServicio { 15 | 16 | @Autowired 17 | EditorialRepositorio editorialRepositorio; 18 | 19 | @Transactional 20 | public void crearEditorial(String nombre) throws MiException{ 21 | 22 | validar(nombre); 23 | 24 | Editorial editorial = new Editorial(); 25 | 26 | editorial.setNombre(nombre); 27 | 28 | editorialRepositorio.save(editorial); 29 | } 30 | 31 | public List listarEditoriales() { 32 | 33 | List editoriales = new ArrayList(); 34 | 35 | editoriales = editorialRepositorio.findAll(); 36 | 37 | return editoriales; 38 | } 39 | 40 | @Transactional 41 | public void modificarEditorial(String id, String nombre) throws MiException{ 42 | validar(nombre); 43 | 44 | Optional respuesta = editorialRepositorio.findById(id); 45 | 46 | if (respuesta.isPresent()) { 47 | 48 | Editorial editorial = respuesta.get(); 49 | 50 | editorial.setNombre(nombre); 51 | 52 | editorialRepositorio.save(editorial); 53 | } 54 | } 55 | 56 | private void validar(String nombre) throws MiException { 57 | 58 | if (nombre.isEmpty() || nombre == null) { 59 | throw new MiException("el nombre de la editorial no puede ser nulo o estar vacio"); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/servicios/ImagenServicio.java: -------------------------------------------------------------------------------- 1 | 2 | package com.egg.biblioteca.servicios; 3 | 4 | import com.egg.biblioteca.entidades.Imagen; 5 | import com.egg.biblioteca.excepciones.MiException; 6 | import com.egg.biblioteca.repositorios.ImagenRepositorio; 7 | import java.util.List; 8 | import java.util.Optional; 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Transactional; 13 | import org.springframework.web.multipart.MultipartFile; 14 | 15 | @Service 16 | public class ImagenServicio { 17 | @Autowired 18 | private ImagenRepositorio imagenRepositorio; 19 | 20 | public Imagen guardar(MultipartFile archivo) throws MiException{ 21 | if (archivo != null) { 22 | try { 23 | 24 | Imagen imagen = new Imagen(); 25 | 26 | imagen.setMime(archivo.getContentType()); 27 | 28 | imagen.setNombre(archivo.getName()); 29 | 30 | imagen.setContenido(archivo.getBytes()); 31 | 32 | return imagenRepositorio.save(imagen); 33 | 34 | } catch (Exception e) { 35 | System.err.println(e.getMessage()); 36 | } 37 | } 38 | return null; 39 | } 40 | 41 | public Imagen actualizar(MultipartFile archivo, String idImagen) throws MiException{ 42 | if (archivo != null) { 43 | try { 44 | 45 | Imagen imagen = new Imagen(); 46 | 47 | if (idImagen != null) { 48 | Optional respuesta = imagenRepositorio.findById(idImagen); 49 | 50 | if (respuesta.isPresent()) { 51 | imagen = respuesta.get(); 52 | } 53 | } 54 | 55 | imagen.setMime(archivo.getContentType()); 56 | 57 | imagen.setNombre(archivo.getName()); 58 | 59 | imagen.setContenido(archivo.getBytes()); 60 | 61 | return imagenRepositorio.save(imagen); 62 | 63 | } catch (Exception e) { 64 | System.err.println(e.getMessage()); 65 | } 66 | } 67 | return null; 68 | 69 | } 70 | 71 | @Transactional(readOnly = true) 72 | public List listarTodos() { 73 | return imagenRepositorio.findAll(); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/java/com/egg/biblioteca/servicios/LibroServicio.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca.servicios; 2 | 3 | import com.egg.biblioteca.entidades.Autor; 4 | import com.egg.biblioteca.entidades.Editorial; 5 | //import com.egg.biblioteca.entidades.Imagen; 6 | import com.egg.biblioteca.entidades.Libro; 7 | import com.egg.biblioteca.excepciones.MiException; 8 | import com.egg.biblioteca.repositorios.AutorRepositorio; 9 | import com.egg.biblioteca.repositorios.EditorialRepositorio; 10 | import com.egg.biblioteca.repositorios.LibroRepositorio; 11 | import java.util.ArrayList; 12 | import java.util.Date; 13 | import java.util.List; 14 | import java.util.Optional; 15 | import javax.transaction.Transactional; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.stereotype.Service; 18 | import org.springframework.web.multipart.MultipartFile; 19 | 20 | @Service 21 | public class LibroServicio { 22 | 23 | @Autowired 24 | private LibroRepositorio libroRepositorio; 25 | @Autowired 26 | private AutorRepositorio autorRepositorio; 27 | @Autowired 28 | private EditorialRepositorio editorialRepositorio; 29 | // @Autowired 30 | // private ImagenServicio imagenServicio; 31 | 32 | @Transactional 33 | public void crearLibro(MultipartFile archivo, Long isbn, String titulo, Integer ejemplares, String idAutor, String idEditorial) throws MiException{ 34 | 35 | validar(isbn, titulo, ejemplares, idAutor, idEditorial); 36 | 37 | Optional respuesta = libroRepositorio.findById(isbn); 38 | Optional respuestaAutor = autorRepositorio.findById(idAutor); 39 | Optional respuestaEditorial = editorialRepositorio.findById(idEditorial); 40 | 41 | Autor autor = new Autor(); 42 | Editorial editorial= new Editorial(); 43 | 44 | if(respuestaAutor.isPresent()){ 45 | 46 | autor = respuestaAutor.get(); 47 | } 48 | 49 | if(respuestaEditorial.isPresent()){ 50 | 51 | editorial = respuestaEditorial.get(); 52 | } 53 | 54 | Libro libro = new Libro(); 55 | 56 | libro.setIsbn(isbn); 57 | libro.setTitulo(titulo); 58 | libro.setEjemplares(ejemplares); 59 | libro.setAlta(new Date()); 60 | libro.setAutor(autor); 61 | libro.setEditorial(editorial); 62 | // 63 | // Imagen imagen = imagenServicio.guardar(archivo); 64 | // 65 | // libro.setImagen(imagen); 66 | 67 | libroRepositorio.save(libro); 68 | } 69 | 70 | public List listarLibros() { 71 | 72 | List libros = new ArrayList(); 73 | 74 | libros = libroRepositorio.findAll(); 75 | 76 | return libros; 77 | } 78 | 79 | @Transactional 80 | public void modificarLibro(MultipartFile archivo, Long isbn, String titulo, Integer ejemplares, String idAutor, String idEditorial) throws MiException{ 81 | 82 | validar(isbn, titulo, ejemplares, idAutor, idEditorial); 83 | 84 | Optional respuesta = libroRepositorio.findById(isbn); 85 | Optional respuestaAutor = autorRepositorio.findById(idAutor); 86 | Optional respuestaEditorial = editorialRepositorio.findById(idEditorial); 87 | 88 | Autor autor = new Autor(); 89 | Editorial editorial= new Editorial(); 90 | 91 | if(respuestaAutor.isPresent()){ 92 | 93 | autor = respuestaAutor.get(); 94 | } 95 | 96 | if(respuestaEditorial.isPresent()){ 97 | 98 | editorial = respuestaEditorial.get(); 99 | } 100 | 101 | if(respuesta.isPresent()){ 102 | 103 | Libro libro = respuesta.get(); 104 | 105 | 106 | libro.setTitulo(titulo); 107 | 108 | libro.setEjemplares(ejemplares); 109 | 110 | libro.setAutor(autor); 111 | 112 | libro.setEditorial(editorial); 113 | 114 | String idImagen = null; 115 | 116 | // if (libro.getImagen() != null) { 117 | // idImagen = libro.getImagen().getId(); 118 | // } 119 | // 120 | // Imagen imagen = imagenServicio.actualizar(idImagen, archivo); 121 | // libro.setImagen(imagen); 122 | // 123 | libroRepositorio.save(libro); 124 | 125 | } 126 | } 127 | 128 | public Libro getOne(Long isbn){ 129 | return libroRepositorio.getOne(isbn); 130 | } 131 | 132 | private void validar(Long isbn, String titulo, Integer ejemplares, String idAutor, String idEditorial) throws MiException{ 133 | 134 | if(isbn == null){ 135 | throw new MiException("el isbn no puede ser nulo"); // 136 | } 137 | if(titulo.isEmpty() || titulo == null){ 138 | throw new MiException("el titulo no puede ser nulo o estar vacio"); 139 | } 140 | if(ejemplares == null){ 141 | throw new MiException("ejemplares no puede ser nulo"); 142 | } 143 | if(idAutor.isEmpty() || idAutor == null){ 144 | throw new MiException("el Autor no puede ser nulo o estar vacio"); 145 | } 146 | 147 | if(idEditorial.isEmpty() || idEditorial == null){ 148 | throw new MiException("La Editorial no puede ser nula o estar vacia"); 149 | } 150 | } 151 | 152 | } 153 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url: jdbc:mysql://localhost:3306/biblioteca?allowPublicKeyRetrieval=true&useSSL=false&useTimezone=true&serverTimezone=GMT&characterEncoding=UTF-8 2 | spring.datasource.username: root 3 | spring.datasource.password: root 4 | spring.datasource.driver-class-name: com.mysql.cj.jdbc.Driver 5 | spring.jpa.show-sql: true 6 | spring.jpa.hibernate.ddl-auto: update 7 | spring.jpa.properties.hibernate.dialect: org.hibernate.dialect.MySQL5InnoDBDialect 8 | spring.thymeleaf.cache: false 9 | 10 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/static/css/formulario.css: -------------------------------------------------------------------------------- 1 | .navBar{ 2 | background-color: #fff !important; 3 | } 4 | 5 | .elementosNav{ 6 | display: flex; 7 | width: 30%; 8 | justify-content: space-around; 9 | color: #37474f; 10 | font-weight: 700; 11 | } 12 | 13 | .elementos{ 14 | margin-right: 50px; 15 | } 16 | 17 | .containerImg{ 18 | width: 20%; 19 | } 20 | 21 | .logo{ 22 | width: 40%; 23 | margin: auto; 24 | } 25 | 26 | 27 | .mensajeExito{ 28 | width: 20%; 29 | margin: auto; 30 | text-align: center; 31 | } 32 | 33 | .mensajeError{ 34 | width: 20%; 35 | margin: auto; 36 | text-align: center; 37 | } 38 | 39 | .formulario{ 40 | width: 50%; 41 | margin: auto; 42 | display: flex; 43 | flex-direction: column; 44 | } 45 | 46 | .divVolver{ 47 | width: 50%; 48 | display: flex; 49 | justify-content: center; 50 | align-items: center; 51 | margin: auto; 52 | } 53 | 54 | .botonVolver{ 55 | width: 70%; 56 | } 57 | 58 | .botones{ 59 | box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 60 | -webkit-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 61 | -moz-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 62 | } 63 | 64 | .botones:active{ 65 | box-shadow: none; 66 | } 67 | 68 | .containerFooter{ 69 | display: flex; 70 | justify-content: space-around; 71 | align-items: center; 72 | } -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/static/css/index.css: -------------------------------------------------------------------------------- 1 | .navBar{ 2 | background-color: #fff !important; 3 | } 4 | 5 | .elementosNav{ 6 | display: flex; 7 | width: 30%; 8 | justify-content: space-around; 9 | color: #37474f; 10 | font-weight: 700; 11 | } 12 | 13 | .elementos{ 14 | margin-right: 50px; 15 | } 16 | 17 | .containerImg{ 18 | width: 20%; 19 | } 20 | 21 | .logo{ 22 | width: 40%; 23 | margin: auto; 24 | } 25 | 26 | .tituloBiblioteca{ 27 | width: 80%; 28 | text-align: center; 29 | font-size: 40px; 30 | margin-top: 80px; 31 | font-weight: 500; 32 | } 33 | 34 | .header{ 35 | background-image: url(../img/FondoZoom_2.jpg); 36 | background-size: cover; 37 | height: 550px; 38 | display: flex; 39 | justify-content: end; 40 | } 41 | 42 | .contenedorLibros{ 43 | margin-top: 80px; 44 | display: flex; 45 | flex-direction: column; 46 | justify-content: center; 47 | align-items: center; 48 | } 49 | 50 | .tituloLibros{ 51 | font-size: 22px; 52 | font-weight: 500; 53 | } 54 | 55 | .contenedorMain{ 56 | width: 50%; 57 | display: flex; 58 | flex-direction: column; 59 | align-items: center; 60 | } 61 | 62 | .containerFooter{ 63 | display: flex; 64 | justify-content: space-around; 65 | align-items: center; 66 | } 67 | 68 | .boton{ 69 | background-color: #ffcb00; 70 | box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 71 | -webkit-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 72 | -moz-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 73 | } 74 | 75 | .boton:hover{ 76 | background-color: #ffcb00; 77 | } 78 | .boton:active{ 79 | box-shadow: none; 80 | } -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/static/css/inicio.css: -------------------------------------------------------------------------------- 1 | .navBar{ 2 | background-color: #fff !important; 3 | } 4 | 5 | .elementosNav{ 6 | display: flex; 7 | width: 30%; 8 | justify-content: space-around; 9 | color: #37474f; 10 | font-weight: 700; 11 | } 12 | 13 | .containerImg{ 14 | width: 20%; 15 | } 16 | 17 | .logo{ 18 | width: 40%; 19 | margin: auto; 20 | } 21 | 22 | .main{ 23 | background-image: url(../img/FondoZoom.jpg); 24 | background-size: cover; 25 | height: 400px; 26 | display: flex; 27 | align-items: center; 28 | } 29 | 30 | .containerFooter{ 31 | display: flex; 32 | justify-content: space-around; 33 | align-items: center; 34 | } 35 | 36 | .boton{ 37 | background-color: #ffcb00; 38 | box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 39 | -webkit-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 40 | -moz-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 41 | margin-right: 10px; 42 | margin-left: -10px; 43 | } 44 | 45 | .botonCargar{ 46 | box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 47 | -webkit-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 48 | -moz-box-shadow: 0px 2px 16px 4px rgba(0,0,0,0.36); 49 | } 50 | 51 | .boton:active{ 52 | box-shadow: none; 53 | } 54 | .botonCargar:active{ 55 | box-shadow: none; 56 | } -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/static/img/Egg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V4/src/main/resources/static/img/Egg.png -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/static/img/FondoZoom.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V4/src/main/resources/static/img/FondoZoom.jpg -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/static/img/FondoZoom_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V4/src/main/resources/static/img/FondoZoom_1.jpg -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/static/img/FondoZoom_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V4/src/main/resources/static/img/FondoZoom_2.jpg -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/static/img/imgEgg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V4/src/main/resources/static/img/imgEgg.png -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/static/img/imgEggBlanco.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EggCooperation/Spring/3f57c66cebd6652fcb9a3155d20bb6278b419344/Biblioteca_V4/src/main/resources/static/img/imgEggBlanco.jpg -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 33 | 34 |
35 |
36 |
37 | BIBLIOTECA EGG 38 |

39 | 40 |
41 |
42 |
43 |
44 | Volver 45 |
46 |
47 |
48 |
49 |

50 | 51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | 59 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/templates/fragments/head.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Biblioteca Egg 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/templates/fragments/navbar.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 33 | 34 |
35 |
36 |
37 | BIBLIOTECA EGG 38 |
39 |
40 |

41 | 42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | 50 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Biblioteca Egg - Login 6 | 7 | 8 | 9 | 10 | 11 | 32 | 33 | 34 | 35 |
36 |
37 |
38 |
Error!
39 |

40 |
41 |
42 |
43 |
44 |
Exito!
45 |

46 |
47 |
48 | 49 |
50 | 51 | 52 |
53 |

Accede a la Biblioteca!

54 |
55 | 56 |
57 | 58 |
59 | 60 |
61 | 62 |
63 | 64 | 65 | 66 |
67 | 68 | 69 |
70 |
71 |
72 | Volver 73 |
74 |
75 |
76 |
77 | 78 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/main/resources/templates/registro.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Biblioteca Egg - Registrate! 6 | 7 | 8 | 9 | 10 | 11 | 30 | 31 |
32 |
33 |
Error!
34 |

35 |
36 |
37 |
38 |
39 |
Exito!
40 |

41 |
42 |
43 | 44 |
45 | 46 |
47 | 48 | 49 |
50 |

Registrate!

51 |
52 |
53 | 54 |
55 |
56 | 57 |
58 | 59 | 60 |
61 | 62 |
63 | 64 | 65 |
66 | 67 |
68 |
69 | 70 |
71 | 72 | 73 | 74 |
75 | 76 | 77 |
78 |
79 |
80 | Volver 81 |
82 |
83 |
84 |
85 | 86 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /Biblioteca_V4/src/test/java/com/egg/biblioteca/BibliotecaApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.egg.biblioteca; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class BibliotecaApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## Proyecto Biblioteca Egg 2 | #### V1: 3 | Configuraciones iniciales del proyecto - Entidades, Servicios y Repositorio de Autor, Libro y Editorial. 4 | 5 | #### V2: 6 | Controladores Autor, Libro y Editorial. Portal Controlador. 7 | 8 | #### V3: 9 | Spring Security - Clase Usuario - Login y Registro. 10 | 11 | #### V4: 12 | Carga de Imagen - clases y controlador "ResponseEntity" de Imagen 13 | --------------------------------------------------------------------------------