diff --git a/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/Attachment.java b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/Attachment.java new file mode 100644 index 0000000..30439f1 --- /dev/null +++ b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/Attachment.java @@ -0,0 +1,39 @@ +package com.lcaohoanq.shoppe.domain.chat; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.lcaohoanq.shoppe.base.entity.BaseEntity; +import com.lcaohoanq.shoppe.metadata.MediaMeta; +import jakarta.persistence.Column; +import jakarta.persistence.Embedded; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.SequenceGenerator; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Table(name = "attachments") +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Attachment { + + @Id + @SequenceGenerator(name = "attachments_seq", sequenceName = "attachments_id_seq", allocationSize = 1) + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "attachments_seq") + @Column(name="id", unique=true, nullable=false) + @JsonProperty("id") + private Long id; + + @Embedded + private MediaMeta mediaMeta; + +} diff --git a/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/ChatRoom.java b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/ChatRoom.java new file mode 100644 index 0000000..974e790 --- /dev/null +++ b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/ChatRoom.java @@ -0,0 +1,51 @@ +package com.lcaohoanq.shoppe.domain.chat; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.lcaohoanq.shoppe.base.entity.BaseEntity; +import com.lcaohoanq.shoppe.domain.user.User; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.SequenceGenerator; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Table(name = "chat_rooms") +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ChatRoom extends BaseEntity { + + @Id + @SequenceGenerator(name = "chat_rooms_seq", sequenceName = "chat_rooms_id_seq", allocationSize = 1) + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "chat_rooms_seq") + @Column(name = "id", unique = true, nullable = false) + @JsonProperty("id") + private Long id; + + @ManyToOne + @JoinColumn(name = "user_1_id", nullable = false) + private User user1; + + @ManyToOne + @JoinColumn(name = "user_2_id", nullable = false) + private User user2; + + @Column(name = "user1_typing_status") + private Boolean user1TypingStatus = false; + + @Column(name = "user2_typing_status") + private Boolean user2TypingStatus = false; + +} \ No newline at end of file diff --git a/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/Message.java b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/Message.java new file mode 100644 index 0000000..0d26a26 --- /dev/null +++ b/SPCServer/springboot/src/main/java/com/lcaohoanq/shoppe/domain/chat/Message.java @@ -0,0 +1,59 @@ +package com.lcaohoanq.shoppe.domain.chat; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.lcaohoanq.shoppe.base.entity.BaseEntity; +import com.lcaohoanq.shoppe.domain.user.User; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; +import jakarta.persistence.SequenceGenerator; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Table(name = "messages") +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Message extends BaseEntity { + + @Id + @SequenceGenerator(name = "messages_seq", sequenceName = "messages_id_seq", allocationSize = 1) + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "messages_seq") + @Column(name="id", unique=true, nullable=false) + @JsonProperty("id") + private Long id; + + @ManyToOne + @JoinColumn(name = "chat_room_id", nullable = false) + private ChatRoom chatRoom; + + @OneToOne(cascade = CascadeType.ALL) // If a message has one attachment + @JoinColumn(name = "attachment_id") + private Attachment attachment; + + @ManyToOne + @JoinColumn(name = "user_id", nullable = false) + private User user; + + @Column(name = "content", nullable = false) + private String content; // Store the message text + + @Column(name="is_read", nullable = false) + private Boolean isRead = false; + + // Timestamps from BaseEntity are inherited +} +