From 331a6a5f7b261b4ee8d2d57c4c55acf177ac41ea Mon Sep 17 00:00:00 2001 From: Cristobal Bernal Mayordomo <90463533+Racriberny@users.noreply.github.com> Date: Mon, 6 Feb 2023 17:59:25 +0100 Subject: [PATCH] commit --- pom.xml | 20 ++- .../foro/Entidades/CategoriaForoEntity.java | 64 ++++++++ .../foro/Entidades/RespuestasEntity.java | 105 +++++++++++++ .../foro/Entidades/UsersEntity.java | 143 ++++++++++++++++++ .../foro/Modelo/Respuestas.java | 44 ------ .../foro/Respositorios/ICategoriaForo.java | 4 + .../foro/Respositorios/IForo.java | 8 + .../foro/Respositorios/IRespuestas.java | 8 + .../foro/Respositorios/IUsers.java | 8 + .../foro/Servicios/ServicioForo.java | 21 +++ .../foro/Servicios/ServicioRespuestas.java | 28 +--- .../foro/controlador/Controlador.java | 29 ++-- .../foro/seguridad/MvcConfig.java | 1 - src/main/resources/application.properties | 7 + src/main/resources/templates/index.html | 6 +- 15 files changed, 418 insertions(+), 78 deletions(-) create mode 100644 src/main/java/com/cristobalbernal/foro/Entidades/CategoriaForoEntity.java create mode 100644 src/main/java/com/cristobalbernal/foro/Entidades/RespuestasEntity.java create mode 100644 src/main/java/com/cristobalbernal/foro/Entidades/UsersEntity.java delete mode 100644 src/main/java/com/cristobalbernal/foro/Modelo/Respuestas.java create mode 100644 src/main/java/com/cristobalbernal/foro/Respositorios/ICategoriaForo.java create mode 100644 src/main/java/com/cristobalbernal/foro/Respositorios/IForo.java create mode 100644 src/main/java/com/cristobalbernal/foro/Respositorios/IRespuestas.java create mode 100644 src/main/java/com/cristobalbernal/foro/Respositorios/IUsers.java create mode 100644 src/main/java/com/cristobalbernal/foro/Servicios/ServicioForo.java diff --git a/pom.xml b/pom.xml index 062db77..7862c0b 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,25 @@ spring-boot-starter-web 3.0.0 - + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.mariadb.jdbc + mariadb-java-client + + + + + org.hibernate.orm + hibernate-core + + + + org.springframework.cloud spring-cloud-starter 3.1.5 diff --git a/src/main/java/com/cristobalbernal/foro/Entidades/CategoriaForoEntity.java b/src/main/java/com/cristobalbernal/foro/Entidades/CategoriaForoEntity.java new file mode 100644 index 0000000..e1ae03a --- /dev/null +++ b/src/main/java/com/cristobalbernal/foro/Entidades/CategoriaForoEntity.java @@ -0,0 +1,64 @@ +package com.cristobalbernal.foro.Entidades; + +import jakarta.persistence.*; + +@Entity +@Table(name = "categoria_foro", schema = "forogruas", catalog = "") +public class CategoriaForoEntity { + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Id + @Column(name = "id", nullable = false) + private int id; + @Basic + @Column(name = "name", nullable = true, length = 45) + private String name; + @Basic + @Column(name = "descripcion", nullable = true, length = 45) + private String descripcion; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescripcion() { + return descripcion; + } + + public void setDescripcion(String descripcion) { + this.descripcion = descripcion; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + CategoriaForoEntity that = (CategoriaForoEntity) o; + + if (id != that.id) return false; + if (name != null ? !name.equals(that.name) : that.name != null) return false; + if (descripcion != null ? !descripcion.equals(that.descripcion) : that.descripcion != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = id; + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (descripcion != null ? descripcion.hashCode() : 0); + return result; + } +} diff --git a/src/main/java/com/cristobalbernal/foro/Entidades/RespuestasEntity.java b/src/main/java/com/cristobalbernal/foro/Entidades/RespuestasEntity.java new file mode 100644 index 0000000..323cfe8 --- /dev/null +++ b/src/main/java/com/cristobalbernal/foro/Entidades/RespuestasEntity.java @@ -0,0 +1,105 @@ +package com.cristobalbernal.foro.Entidades; + +import jakarta.persistence.*; + +import java.sql.Timestamp; + +@Entity +@Table(name = "respuestas", schema = "forogruas", catalog = "") +public class RespuestasEntity { + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Id + @Column(name = "id", nullable = false) + private int id; + @Basic + @Column(name = "Post", nullable = true, length = 45) + private String post; + @Basic + @Column(name = "fechaYHora", nullable = true) + private Timestamp fechaYHora; + @Basic + @Column(name = "Respuestas_id", nullable = false) + private int respuestasId; + @Basic + @Column(name = "users_id", nullable = false) + private int usersId; + @Basic + @Column(name = "Foro_id", nullable = false) + private int foroId; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getPost() { + return post; + } + + public void setPost(String post) { + this.post = post; + } + + public Timestamp getFechaYHora() { + return fechaYHora; + } + + public void setFechaYHora(Timestamp fechaYHora) { + this.fechaYHora = fechaYHora; + } + + public int getRespuestasId() { + return respuestasId; + } + + public void setRespuestasId(int respuestasId) { + this.respuestasId = respuestasId; + } + + public int getUsersId() { + return usersId; + } + + public void setUsersId(int usersId) { + this.usersId = usersId; + } + + public int getForoId() { + return foroId; + } + + public void setForoId(int foroId) { + this.foroId = foroId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + RespuestasEntity that = (RespuestasEntity) o; + + if (id != that.id) return false; + if (respuestasId != that.respuestasId) return false; + if (usersId != that.usersId) return false; + if (foroId != that.foroId) return false; + if (post != null ? !post.equals(that.post) : that.post != null) return false; + if (fechaYHora != null ? !fechaYHora.equals(that.fechaYHora) : that.fechaYHora != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = id; + result = 31 * result + (post != null ? post.hashCode() : 0); + result = 31 * result + (fechaYHora != null ? fechaYHora.hashCode() : 0); + result = 31 * result + respuestasId; + result = 31 * result + usersId; + result = 31 * result + foroId; + return result; + } +} diff --git a/src/main/java/com/cristobalbernal/foro/Entidades/UsersEntity.java b/src/main/java/com/cristobalbernal/foro/Entidades/UsersEntity.java new file mode 100644 index 0000000..0bb5398 --- /dev/null +++ b/src/main/java/com/cristobalbernal/foro/Entidades/UsersEntity.java @@ -0,0 +1,143 @@ +package com.cristobalbernal.foro.Entidades; + +import jakarta.persistence.*; + +@Entity +@Table(name = "users", schema = "forogruas", catalog = "") +public class UsersEntity { + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Id + @Column(name = "id", nullable = false) + private int id; + @Basic + @Column(name = "name", nullable = true, length = 45) + private String name; + @Basic + @Column(name = "firstname", nullable = true, length = 45) + private String firstname; + @Basic + @Column(name = "secondname", nullable = true, length = 45) + private String secondname; + @Basic + @Column(name = "password", nullable = true, length = 45) + private String password; + @Basic + @Column(name = "email", nullable = true, length = 45) + private String email; + @Basic + @Column(name = "username", nullable = true, length = 45) + private String username; + @Basic + @Column(name = "Imgen", nullable = true, length = 150) + private String imgen; + @Basic + @Column(name = "tipoPrivilegios", nullable = true) + private Byte tipoPrivilegios; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getFirstname() { + return firstname; + } + + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + public String getSecondname() { + return secondname; + } + + public void setSecondname(String secondname) { + this.secondname = secondname; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getImgen() { + return imgen; + } + + public void setImgen(String imgen) { + this.imgen = imgen; + } + + public Byte getTipoPrivilegios() { + return tipoPrivilegios; + } + + public void setTipoPrivilegios(Byte tipoPrivilegios) { + this.tipoPrivilegios = tipoPrivilegios; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + UsersEntity that = (UsersEntity) o; + + if (id != that.id) return false; + if (name != null ? !name.equals(that.name) : that.name != null) return false; + if (firstname != null ? !firstname.equals(that.firstname) : that.firstname != null) return false; + if (secondname != null ? !secondname.equals(that.secondname) : that.secondname != null) return false; + if (password != null ? !password.equals(that.password) : that.password != null) return false; + if (email != null ? !email.equals(that.email) : that.email != null) return false; + if (username != null ? !username.equals(that.username) : that.username != null) return false; + if (imgen != null ? !imgen.equals(that.imgen) : that.imgen != null) return false; + if (tipoPrivilegios != null ? !tipoPrivilegios.equals(that.tipoPrivilegios) : that.tipoPrivilegios != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = id; + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (firstname != null ? firstname.hashCode() : 0); + result = 31 * result + (secondname != null ? secondname.hashCode() : 0); + result = 31 * result + (password != null ? password.hashCode() : 0); + result = 31 * result + (email != null ? email.hashCode() : 0); + result = 31 * result + (username != null ? username.hashCode() : 0); + result = 31 * result + (imgen != null ? imgen.hashCode() : 0); + result = 31 * result + (tipoPrivilegios != null ? tipoPrivilegios.hashCode() : 0); + return result; + } +} diff --git a/src/main/java/com/cristobalbernal/foro/Modelo/Respuestas.java b/src/main/java/com/cristobalbernal/foro/Modelo/Respuestas.java deleted file mode 100644 index adb3a99..0000000 --- a/src/main/java/com/cristobalbernal/foro/Modelo/Respuestas.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.cristobalbernal.foro.Modelo; - -import java.util.ArrayList; -public class Respuestas { - private int id; - private String titulos; - private String descripcion; - private ArrayList respuestasInternas; - - public Respuestas(int id, String titulos, String descripcion) { - this.id = id; - this.titulos = titulos; - this.descripcion = descripcion; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getTitulos() { - return titulos; - } - - public void setTitulos(String titulos) { - this.titulos = titulos; - } - - public String getDescripcion() { - return descripcion; - } - - public void setDescripcion(String descripcion) { - this.descripcion = descripcion; - } - - public ArrayList getRespuestas() { - return respuestasInternas; - } -} - diff --git a/src/main/java/com/cristobalbernal/foro/Respositorios/ICategoriaForo.java b/src/main/java/com/cristobalbernal/foro/Respositorios/ICategoriaForo.java new file mode 100644 index 0000000..d92975c --- /dev/null +++ b/src/main/java/com/cristobalbernal/foro/Respositorios/ICategoriaForo.java @@ -0,0 +1,4 @@ +package com.cristobalbernal.foro.Respositorios; + +public interface ICategoriaForo { +} diff --git a/src/main/java/com/cristobalbernal/foro/Respositorios/IForo.java b/src/main/java/com/cristobalbernal/foro/Respositorios/IForo.java new file mode 100644 index 0000000..c28216d --- /dev/null +++ b/src/main/java/com/cristobalbernal/foro/Respositorios/IForo.java @@ -0,0 +1,8 @@ +package com.cristobalbernal.foro.Respositorios; + +import com.cristobalbernal.foro.Entidades.Foro; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface IForo extends JpaRepository { + +} diff --git a/src/main/java/com/cristobalbernal/foro/Respositorios/IRespuestas.java b/src/main/java/com/cristobalbernal/foro/Respositorios/IRespuestas.java new file mode 100644 index 0000000..2026a87 --- /dev/null +++ b/src/main/java/com/cristobalbernal/foro/Respositorios/IRespuestas.java @@ -0,0 +1,8 @@ +package com.cristobalbernal.foro.Respositorios; + +import com.cristobalbernal.foro.Entidades.RespuestasEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface IRespuestas extends JpaRepository { + +} diff --git a/src/main/java/com/cristobalbernal/foro/Respositorios/IUsers.java b/src/main/java/com/cristobalbernal/foro/Respositorios/IUsers.java new file mode 100644 index 0000000..93d71d8 --- /dev/null +++ b/src/main/java/com/cristobalbernal/foro/Respositorios/IUsers.java @@ -0,0 +1,8 @@ +package com.cristobalbernal.foro.Respositorios; + +import com.cristobalbernal.foro.Entidades.UsersEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface IUsers extends JpaRepository { + +} diff --git a/src/main/java/com/cristobalbernal/foro/Servicios/ServicioForo.java b/src/main/java/com/cristobalbernal/foro/Servicios/ServicioForo.java new file mode 100644 index 0000000..067e416 --- /dev/null +++ b/src/main/java/com/cristobalbernal/foro/Servicios/ServicioForo.java @@ -0,0 +1,21 @@ +package com.cristobalbernal.foro.Servicios; + +import com.cristobalbernal.foro.Entidades.Foro; +import jakarta.annotation.PostConstruct; +import org.springframework.stereotype.Service; +@Service +public class ServicioForo { + private Foro[] foro; + public ServicioForo(){ + } + public Foro[] findAll(){ + return foro; + } + @PostConstruct + public void init(){ + foro = new Foro[3]; + foro[0] = new Foro(0,"Titular1","Hola",1,1); + foro[1] = new Foro(1,"Titular2","HolaDos",2,2); + foro[2] = new Foro(2,"Titular3","HolaTres",3,3); + } +} diff --git a/src/main/java/com/cristobalbernal/foro/Servicios/ServicioRespuestas.java b/src/main/java/com/cristobalbernal/foro/Servicios/ServicioRespuestas.java index 4e766db..08dee83 100644 --- a/src/main/java/com/cristobalbernal/foro/Servicios/ServicioRespuestas.java +++ b/src/main/java/com/cristobalbernal/foro/Servicios/ServicioRespuestas.java @@ -1,39 +1,27 @@ package com.cristobalbernal.foro.Servicios; -import com.cristobalbernal.foro.Modelo.Respuestas; +import com.cristobalbernal.foro.Entidades.RespuestasEntity; import jakarta.annotation.PostConstruct; import org.springframework.stereotype.Service; @Service public class ServicioRespuestas { - private Respuestas[] respuestas; + private RespuestasEntity[] respuestas; public ServicioRespuestas() { } - public Respuestas[] findAll(){ + public RespuestasEntity[] findAll(){ return respuestas; } @PostConstruct public void init(){ - respuestas = new Respuestas[6]; - respuestas[0] = new Respuestas(0, "TITULO 1", "aslkjbdakjdbkajwdbjakwdbkawjdbawkd.bawdawd" + - "adaw,dbakwjdbawkjd,abjwkd,awk,dad" + - "awda,wbjdwakjdawkjdawdblaw"); - respuestas[1] = new Respuestas(1, "TITULO 2", "aslkjbdakjdbkajwdbjakwdbkawjdbawkd.bawdawd" + - "adaw,dbakwjdbawkjd,abjwkd,awk,dad" + - "awda,wbjdwakjdawkjdawdblaw"); - respuestas[2] = new Respuestas(2, "TITULO 3", "aslkjbdakjdbkajwdbjakwdbkawjdbawkd.bawdawd" + - "adaw,dbakwjdbawkjd,abjwkd,awk,dad" + - "awda,wbjdwakjdawkjdawdblaw"); - respuestas[3] = new Respuestas(3, "TITULO 4", "aslkjbdakjdbkajwdbjakwdbkawjdbawkd.bawdawd" + - "adaw,dbakwjdbawkjd,abjwkd,awk,dad" + - "awda,wbjdwakjdawkjdawdblaw"); - respuestas[4] = new Respuestas(4, "TITULO 5", "aslkjbdakjdbkajwdbjakwdbkawjdbawkd.bawdawd" + - "adaw,dbakwjdbawkjd,abjwkd,awk,dad" + - "awda,wbjdwakjdawkjdawdblaw"); - respuestas[5] = new Respuestas(5, "TITULO 6", "aslkjbdakjdbkajwdbjakwdbkawjdbawkd.bawdawd" + + /* + respuestas = new RespuestasEntity[6]; + respuestas[0] = new RespuestasEntity(0, "TITULO 1", "aslkjbdakjdbkajwdbjakwdbkawjdbawkd.bawdawd" + "adaw,dbakwjdbawkjd,abjwkd,awk,dad" + "awda,wbjdwakjdawkjdawdblaw"); + + */ } } diff --git a/src/main/java/com/cristobalbernal/foro/controlador/Controlador.java b/src/main/java/com/cristobalbernal/foro/controlador/Controlador.java index 4f9b15f..59b89e7 100644 --- a/src/main/java/com/cristobalbernal/foro/controlador/Controlador.java +++ b/src/main/java/com/cristobalbernal/foro/controlador/Controlador.java @@ -1,19 +1,27 @@ package com.cristobalbernal.foro.controlador; -import com.cristobalbernal.foro.Modelo.Respuestas; +import com.cristobalbernal.foro.Entidades.Foro; +import com.cristobalbernal.foro.Entidades.RespuestasEntity; +import com.cristobalbernal.foro.Entidades.UsersEntity; +import com.cristobalbernal.foro.Respositorios.IUsers; +import com.cristobalbernal.foro.Servicios.ServicioForo; import com.cristobalbernal.foro.Servicios.ServicioRespuestas; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.ResponseBody; -import java.net.MalformedURLException; +import java.util.List; @Controller public class Controlador { + @Autowired + private IUsers iUsers; @Autowired private ServicioRespuestas servicioRespuestas; + @Autowired + private ServicioForo servicioForo; @GetMapping("/miperfil") public String miPerfil(){ @@ -21,7 +29,7 @@ public class Controlador { } @GetMapping({"","/home","/"}) public String indice(Model model){ - model.addAttribute("listaRespuestas",servicioRespuestas.findAll()); + model.addAttribute("listaForo",servicioForo.findAll()); return "index"; } @GetMapping("/login") @@ -36,14 +44,17 @@ public class Controlador { public String pregunta(){ return "Ask_Question/ask_question"; } + @GetMapping("/postdetall") public String postDetall(Model model){ - Respuestas[] respuestas = servicioRespuestas.findAll(); - model.addAttribute("titulo", respuestas[0].getTitulos()); - model.addAttribute("cuerpo", respuestas[0].getDescripcion()); + Foro[] foro = servicioForo.findAll(); + model.addAttribute("titulo", foro[0].getTitulo()); + model.addAttribute("cuerpo", foro[0].getDescripcion()); return "Respuestas/post-detall"; } - - + @GetMapping("/all") + public @ResponseBody List getAllUsers(){ + return iUsers.findAll(); + } } diff --git a/src/main/java/com/cristobalbernal/foro/seguridad/MvcConfig.java b/src/main/java/com/cristobalbernal/foro/seguridad/MvcConfig.java index 4167e58..268a3a5 100644 --- a/src/main/java/com/cristobalbernal/foro/seguridad/MvcConfig.java +++ b/src/main/java/com/cristobalbernal/foro/seguridad/MvcConfig.java @@ -1,7 +1,6 @@ package com.cristobalbernal.foro.seguridad; import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistration; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4a0fc08..5cdfb66 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,9 @@ server.port=9000 spring.thymeleaf.cache=false + +spring.jpa.hibernate.ddl-auto=update +spring.datasource.url=jdbc:mariadb://localhost:3306/forogruas +spring.datasource.username=root +spring.datasource.password= +spring.jpa.properties.hibernate.jdbc.time_zone=UTC +spring.data.jpa.repositories.enabled=true \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 10df8dd..47164f2 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -45,14 +45,14 @@
-
+
-

Wouldn’t it be great if you knew exactly what questions a hiring manager would be asking you in your next job interview? +

Wouldn’t it be great if you knew exactly what questions a hiring manager would be asking you in your next job interview? We can’t read minds, unfortunately, but we’ll give you the next best thing: a list of more than 40 of the most commonly asked interview questions, along with advice for answering them all. While we don’t recommend having a canned response for every interview question (in fact, please don’t), we do recommend spending some time getting comfortable with what you might be asked, what hiring managers are really looking for in your responses, and what it takes to show that you’re the right person for the job.