-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathChatMessage.java
More file actions
57 lines (47 loc) · 1.74 KB
/
ChatMessage.java
File metadata and controls
57 lines (47 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.example.solidconnection.chat.domain;
import com.example.solidconnection.common.BaseEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Where;
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Where(clause = "is_deleted = false")
public class ChatMessage extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, length = 500)
private String content;
private long senderId; // chat_participant의 id
@ManyToOne(fetch = FetchType.LAZY)
private ChatRoom chatRoom;
@Column(name = "is_deleted", columnDefinition = "boolean default false", nullable = false)
private boolean isDeleted = false;
@OneToMany(mappedBy = "chatMessage", cascade = CascadeType.ALL, orphanRemoval = true)
private final List<ChatAttachment> chatAttachments = new ArrayList<>();
public ChatMessage(String content, long senderId, ChatRoom chatRoom) {
this.content = content;
this.senderId = senderId;
this.chatRoom = chatRoom;
if (chatRoom != null) {
chatRoom.getChatMessages().add(this);
}
}
public void addAttachment(ChatAttachment attachment) {
this.chatAttachments.add(attachment);
attachment.setChatMessage(this);
}
}