From 7ca5c34afed028e7a6d156637604f0037a3ded5e Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Tue, 2 Apr 2024 11:08:58 +0200 Subject: [PATCH] adding timestamp --- .../ovh/herisson/Clyde/DTO/Msg/MessagesDTO.java | 4 +++- .../ovh/herisson/Clyde/Tables/Msg/Message.java | 15 +++++++++++++-- frontend/src/Apps/Msg.vue | 6 +++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/DTO/Msg/MessagesDTO.java b/backend/src/main/java/ovh/herisson/Clyde/DTO/Msg/MessagesDTO.java index 7eb7ea1..d9dfd14 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/DTO/Msg/MessagesDTO.java +++ b/backend/src/main/java/ovh/herisson/Clyde/DTO/Msg/MessagesDTO.java @@ -4,6 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import ovh.herisson.Clyde.Tables.User; import ovh.herisson.Clyde.Tables.Msg.Message; +import java.util.Date; @Data @AllArgsConstructor @@ -12,12 +13,13 @@ public class MessagesDTO { private String content; private User author; private boolean sender; + private Date created; //TODO: Attachment public static MessagesDTO construct(Message m, User user){ boolean sender = false; if(m.getAuthor().equals(user)) sender = true; - return new MessagesDTO(m.getId(), m.getContent(), m.getAuthor(), sender); + return new MessagesDTO(m.getId(), m.getContent(), m.getAuthor(), sender, m.getCreated()); } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Message.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Message.java index ea1f473..246d92c 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Message.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Message.java @@ -1,8 +1,13 @@ package ovh.herisson.Clyde.Tables.Msg; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.Date; import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -10,6 +15,9 @@ import jakarta.persistence.Id; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; +import jakarta.persistence.PrePersist; +import jakarta.persistence.Temporal; +import jakarta.persistence.TemporalType; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -28,6 +36,10 @@ public class Message { private long id; private String content; + @CreationTimestamp + @Column(nullable = false) + private Date created; + @ManyToOne private User author; @@ -41,6 +53,5 @@ public class Message { @ManyToOne(optional = false) @JsonIgnore private Discussion discussion; - - //TODO: Attachment + } diff --git a/frontend/src/Apps/Msg.vue b/frontend/src/Apps/Msg.vue index 477eb8c..dfdf50d 100644 --- a/frontend/src/Apps/Msg.vue +++ b/frontend/src/Apps/Msg.vue @@ -12,6 +12,10 @@ const msgContent = ref(""); const addMember = ref(false); + function formatTime(date){ + return date.getHours() + ":" + date.getMinutes() + " " + date.getDate() + "/" + date.getMonth(); + } +