From 127ed20959f92126ce17d895e913d9c51f8ea6cc Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 9 Jan 2023 21:24:39 +0100 Subject: [PATCH] add table comment --- .../java/com/covas/Entity/CommentEntity.java | 65 +++++++++++++++++++ .../com/covas/Entity/PublisherEntity.java | 4 ++ .../java/com/covas/Entity/UsersEntity.java | 3 + src/main/java/com/covas/Enum/Type.java | 2 +- 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/covas/Entity/CommentEntity.java diff --git a/src/main/java/com/covas/Entity/CommentEntity.java b/src/main/java/com/covas/Entity/CommentEntity.java new file mode 100644 index 0000000..0fe5a8e --- /dev/null +++ b/src/main/java/com/covas/Entity/CommentEntity.java @@ -0,0 +1,65 @@ +package com.covas.Entity; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.List; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.CascadeType; + +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.GenericGenerator; + +import com.covas.Enum.Type; + +import io.quarkus.hibernate.orm.panache.PanacheEntityBase; + + +@Entity +@Table(name = "comment") +@NamedQueries({ +@NamedQuery(name = "Comment.bySearch", query = "from CommentEntity u where u.comment like :comment"), +}) +public class CommentEntity extends PanacheEntityBase implements Serializable { + @Id + @Column(name = "id") + @GeneratedValue(generator = "UUID") + @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") + public UUID id; + + @Column(columnDefinition="TEXT") + public String comment; + + @Column(nullable = false) + public LocalDateTime created_at; + @Column(nullable = false) + public LocalDateTime updated_at; + @ColumnDefault("null") + public LocalDateTime deleted_at; + + @ColumnDefault("1") + public Short status; + + @ManyToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "users_id", referencedColumnName = "id") + public UsersEntity users; + + @ManyToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "publishers_id", referencedColumnName = "id") + public PublisherEntity publishers; + + public static List findByUsers(String uuid){ + return find("users_id", uuid).list(); + } +} \ No newline at end of file diff --git a/src/main/java/com/covas/Entity/PublisherEntity.java b/src/main/java/com/covas/Entity/PublisherEntity.java index 5310c46..fc5ea32 100644 --- a/src/main/java/com/covas/Entity/PublisherEntity.java +++ b/src/main/java/com/covas/Entity/PublisherEntity.java @@ -60,6 +60,10 @@ public class PublisherEntity extends PanacheEntityBase implements Serializable { @JoinColumn(name = "users_id", referencedColumnName = "id") public UsersEntity users; + @OneToMany(mappedBy = "publishers") + public Collection comment; + + public static List findByUsers(String uuid){ return find("users_id", uuid).list(); } diff --git a/src/main/java/com/covas/Entity/UsersEntity.java b/src/main/java/com/covas/Entity/UsersEntity.java index e8a5a14..bc86693 100644 --- a/src/main/java/com/covas/Entity/UsersEntity.java +++ b/src/main/java/com/covas/Entity/UsersEntity.java @@ -77,6 +77,9 @@ public class UsersEntity extends PanacheEntityBase implements Serializable { @OneToMany(mappedBy = "users") public Collection publisher; + @OneToMany(mappedBy = "users") + public Collection comment; + public static UsersEntity findByPseudo(String pseudo){ return find("pseudo", pseudo).firstResult(); } diff --git a/src/main/java/com/covas/Enum/Type.java b/src/main/java/com/covas/Enum/Type.java index e9d6839..3198aa0 100644 --- a/src/main/java/com/covas/Enum/Type.java +++ b/src/main/java/com/covas/Enum/Type.java @@ -1,6 +1,6 @@ package com.covas.Enum; public enum Type { - VIDEO, PHOTO, TEXT, URL + VIDEO, PHOTO, TEXT, URL, EVENT }