Skip to content

Commit

Permalink
feat: add Chat feature
Browse files Browse the repository at this point in the history
  • Loading branch information
lcaohoanq committed Dec 9, 2024
1 parent 8062250 commit d0c6ce4
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit d0c6ce4

Please sign in to comment.