Browse Source

Intento de añadir foros y poder responder!!!

master
Cristobal Bernal Mayordomo 1 year ago
parent
commit
f7b0104d0c
7 changed files with 85 additions and 73 deletions
  1. +8
    -30
      src/main/java/com/cristobalbernal/foro/Entidades/Foro.java
  2. +9
    -22
      src/main/java/com/cristobalbernal/foro/Entidades/RespuestasEntity.java
  3. +18
    -0
      src/main/java/com/cristobalbernal/foro/Servicios/ServicioCategoria.java
  4. +3
    -0
      src/main/java/com/cristobalbernal/foro/Servicios/ServicioRespuestas.java
  5. +18
    -5
      src/main/java/com/cristobalbernal/foro/controlador/Controlador.java
  6. +13
    -12
      src/main/resources/templates/Ask_Question/ask_question.html
  7. +16
    -4
      src/main/resources/templates/Respuestas/post-detall.html

+ 8
- 30
src/main/java/com/cristobalbernal/foro/Entidades/Foro.java View File

@ -3,6 +3,7 @@ package com.cristobalbernal.foro.Entidades;
import jakarta.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;
@Entity
public class Foro {
@ -22,9 +23,9 @@ public class Foro {
@Basic
@Column(name = "imagen", nullable = false)
private int imagen;
@Basic
@Column(name = "categoria_foro_id", nullable = false)
private int categoriaForoId;
@ManyToOne
@JoinColumn(name = "categoria_foro_id", nullable = false)
private CategoriaForoEntity categoriaForoId;
public Foro() {
}
@ -69,11 +70,11 @@ public class Foro {
this.imagen = imagen;
}
public int getCategoriaForoId() {
public CategoriaForoEntity getCategoriaForoId() {
return categoriaForoId;
}
public void setCategoriaForoId(int categoriaForoId) {
public void setCategoriaForoId(CategoriaForoEntity categoriaForoId) {
this.categoriaForoId = categoriaForoId;
}
@ -81,35 +82,12 @@ public class Foro {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Foro foro = (Foro) o;
if (id != foro.id) return false;
if (imagen != foro.imagen) return false;
if (categoriaForoId != foro.categoriaForoId) return false;
if (titulo != null ? !titulo.equals(foro.titulo) : foro.titulo != null) return false;
if (descripcion != null ? !descripcion.equals(foro.descripcion) : foro.descripcion != null) return false;
if (fechaYHora != null ? !fechaYHora.equals(foro.fechaYHora) : foro.fechaYHora != null) return false;
return true;
return id == foro.id && imagen == foro.imagen && Objects.equals(titulo, foro.titulo) && Objects.equals(descripcion, foro.descripcion) && Objects.equals(fechaYHora, foro.fechaYHora) && Objects.equals(categoriaForoId, foro.categoriaForoId);
}
@Override
public int hashCode() {
int result = id;
result = 31 * result + (titulo != null ? titulo.hashCode() : 0);
result = 31 * result + (descripcion != null ? descripcion.hashCode() : 0);
result = 31 * result + (fechaYHora != null ? fechaYHora.hashCode() : 0);
result = 31 * result + imagen;
result = 31 * result + categoriaForoId;
return result;
}
public Foro(int id, String titulo, String descripcion, int imagen, int categoriaForoId) {
this.id = id;
this.titulo = titulo;
this.descripcion = descripcion;
this.imagen = imagen;
this.categoriaForoId = categoriaForoId;
return Objects.hash(id, titulo, descripcion, fechaYHora, imagen, categoriaForoId);
}
}

+ 9
- 22
src/main/java/com/cristobalbernal/foro/Entidades/RespuestasEntity.java View File

@ -3,6 +3,7 @@ package com.cristobalbernal.foro.Entidades;
import jakarta.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;
@Entity
@Table(name = "respuestas", schema = "forogruas", catalog = "")
@ -14,12 +15,13 @@ public class RespuestasEntity {
@Basic
@Column(name = "Post", nullable = true, length = 45)
private String post;
@Version
@Basic
@Column(name = "fechaYHora", nullable = true)
private Timestamp fechaYHora;
@Basic
@Column(name = "Respuestas_id", nullable = false)
private int respuestasId;
@ManyToOne
@JoinColumn(name = "Respuestas_id", nullable = false)
private RespuestasEntity respuestasId;
@Basic
@Column(name = "users_id", nullable = false)
private int usersId;
@ -51,11 +53,11 @@ public class RespuestasEntity {
this.fechaYHora = fechaYHora;
}
public int getRespuestasId() {
public RespuestasEntity getRespuestasId() {
return respuestasId;
}
public void setRespuestasId(int respuestasId) {
public void setRespuestasId(RespuestasEntity respuestasId) {
this.respuestasId = respuestasId;
}
@ -79,27 +81,12 @@ public class RespuestasEntity {
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;
return id == that.id && usersId == that.usersId && foroId == that.foroId && Objects.equals(post, that.post) && Objects.equals(fechaYHora, that.fechaYHora) && Objects.equals(respuestasId, that.respuestasId);
}
@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;
return Objects.hash(id, post, fechaYHora, respuestasId, usersId, foroId);
}
}

+ 18
- 0
src/main/java/com/cristobalbernal/foro/Servicios/ServicioCategoria.java View File

@ -0,0 +1,18 @@
package com.cristobalbernal.foro.Servicios;
import com.cristobalbernal.foro.Entidades.CategoriaForoEntity;
import com.cristobalbernal.foro.Entidades.Foro;
import com.cristobalbernal.foro.Respositorios.ICategoriaForo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ServicioCategoria {
@Autowired
private ICategoriaForo iCategoriaForo;
public List<CategoriaForoEntity> findAll(){
return iCategoriaForo.findAll();
}
}

+ 3
- 0
src/main/java/com/cristobalbernal/foro/Servicios/ServicioRespuestas.java View File

@ -17,4 +17,7 @@ public class ServicioRespuestas {
public List<RespuestasEntity> respuestasEntityList(int id){
return iRespuestas.findAllByForoId(id);
}
public void save(RespuestasEntity respuestas){
iRespuestas.save(respuestas);
}
}

+ 18
- 5
src/main/java/com/cristobalbernal/foro/controlador/Controlador.java View File

@ -1,22 +1,22 @@
package com.cristobalbernal.foro.controlador;
import com.cristobalbernal.foro.Entidades.CategoriaForoEntity;
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.ServicioCategoria;
import com.cristobalbernal.foro.Servicios.ServicioForo;
import com.cristobalbernal.foro.Servicios.ServicioRespuestas;
import com.cristobalbernal.foro.seguridad.models.UserDetailsImpl;
import org.apache.commons.logging.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -27,6 +27,8 @@ public class Controlador {
@Autowired
private ServicioRespuestas servicioRespuestas;
@Autowired
private ServicioCategoria servicioCategoria;
@Autowired
private ServicioForo servicioForo;
@GetMapping("/miperfil")
@ -50,15 +52,26 @@ public class Controlador {
return "Registrar/Registrar";
}
@GetMapping("/crearPregunta")
public String pregunta(){
public String pregunta(Model model){
model.addAttribute("listaCategoria",servicioCategoria.findAll());
return "Ask_Question/ask_question";
}
@PostMapping("/postdetall/add/submit/{id}")
public String addRespuesta(@ModelAttribute("respuesta") RespuestasEntity respuestas, @PathVariable int id){
respuestas.setForoId(id);
respuestas.setRespuestasId(respuestas);
respuestas.setUsersId(1);
servicioRespuestas.save(respuestas);
return "redirect:/postdetall/" + id;
}
@GetMapping("/postdetall/{id}")
public String postDetall(@PathVariable int id,Model model){
Foro foro = servicioForo.findById(id);
List<RespuestasEntity> respuestas = servicioRespuestas.respuestasEntityList(id);
model.addAttribute("listaRespuestas",respuestas);
model.addAttribute("Foro",foro);
model.addAttribute("respuesta",new RespuestasEntity());
return "Respuestas/post-detall";
}
@GetMapping("/all")


+ 13
- 12
src/main/resources/templates/Ask_Question/ask_question.html View File

@ -25,24 +25,25 @@
<div class="col-md-9">
<div class="ask-question-input-part032">
<h4>Ask Question</h4>
<form>
<div class="username-part940">
<span class="form-description43">User name* </span><input type="text" name="fname" class="username029" placeholder="Enter your Name">
</div>
<div class="email-part320">
<span class="form-description442">E-Mail* </span><input type="text" name="fname" class="email30" placeholder="Enter Your Email">
</div>
<form action="#" th:action="@{ask_question/add/submit}" th:object="${categoria}" method="post">
<div class="question-title39">
<span class="form-description433">Question-Title* </span><input type="text" name="fname" class="question-ttile32" placeholder="Write Your Question Title">
<span class="form-description433">Question-Title*</span><input th:field="*{titulo}" type="text" name="fname" class="question-ttile32" placeholder="Escribe tu titulo!!!">
</div>
<div class="details2-239">
<div class="question-title39">
<span class="form-description433">Respuesta *</span><input th:field="*{descripcion}" type="text" name="fname" class="question-ttile32" placeholder="Escribe tu respues!!!">
</div>
</form>
<fieldset>
<legend>Seleciona Categoria:</legend>
<div th:each="Categoria: ${listaCategoria}">
<input type="checkbox" id="scales" name="scales" checked>
<label for="scales" th:text="${Categoria.name}">Scales</label>
</div>
</fieldset>
<div class="publish-button2389">
<button type="button" class="publis1291">Publish your Question</button>
</div>
</form>
</div>


+ 16
- 4
src/main/resources/templates/Respuestas/post-detall.html View File

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="es">
<html lang="es" >
<head>
<meta charset="utf-8">
@ -39,13 +39,22 @@
</div>
<button id="boton" onclick="mostrar();">Responder</button>
</div>
<div class="comments-container">
<div class="comment-list12993">
<div class="container">
<div class="row">
<ul>Hola</ul>
<ul>
<li th:each="Respuesta: ${listaRespuestas}">
<div class="comment-box">
<div class="comment-head">
<div class="comment-content" th:text="${Respuesta.Post}"> Lorem ipsum dolor sit amet, consectetur adipisicin iure laudantium vitae, praesentium optio, sapiente distinctio illo? </div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="comment289-box">
<h3>Responder</h3>
<hr>
@ -53,8 +62,11 @@
<div class="row">
<div class="col-md-12">
<div class="post9320-box">
<input type="text" class="comment-input219882" placeholder="Enter Your Post"> </div>
<button type="button" class="pos393-submit">Post Your Answer</button>
<form action="#" th:action="@{/postdetall/add/submit/{id}(id=${Foro.id})}" th:object="${respuesta}" method="post">
<input type="text" class="comment-input219882" id="idRespuesta" th:field="*{post}" placeholder="Enter Your Post">
<button type="submit" class="pos393-submit">Post Your Answer</button>
</form>
</div>
</div>
</div>
</div>


Loading…
Cancel
Save