Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.solidconnection.chat.domain;

import com.example.solidconnection.common.BaseEntity;
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 lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ChatAttachment extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private Boolean isImage;

@Column(nullable = false, length = 500)
private String url;

@Column(length = 500)
private String thumbnailUrl;

@ManyToOne(fetch = FetchType.LAZY)
private ChatMessage chatMessage;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ChatMessage extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false, length = 500)
private String content;
Comment on lines +28 to +29
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

메시지 내용에 대한 검증을 추가해주세요.

빈 메시지나 공백만 있는 메시지를 방지하기 위한 검증을 추가하는 것이 좋겠습니다.

+import jakarta.validation.constraints.NotBlank;
+
-@Column(nullable = false, length = 500)
+@Column(nullable = false, length = 500)
+@NotBlank
 private String content;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Column(nullable = false, length = 500)
private String content;
import jakarta.validation.constraints.NotBlank;
@Column(nullable = false, length = 500)
@NotBlank
private String content;
🤖 Prompt for AI Agents
In src/main/java/com/example/solidconnection/chat/domain/ChatMessage.java at
lines 28-29, the content field lacks validation to prevent empty or
whitespace-only messages. Add validation logic, such as using annotations like
@NotBlank or implementing a custom validator, to ensure the content is neither
null, empty, nor only whitespace before persisting or processing the message.


private long senderId;

@ManyToOne(fetch = FetchType.LAZY)
private ChatRoom chatRoom;

@OneToMany(mappedBy = "chatMessage", cascade = CascadeType.ALL)
private List<ChatAttachment> chatAttachments = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example.solidconnection.chat.domain;

import com.example.solidconnection.common.BaseEntity;
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.Table;
import jakarta.persistence.UniqueConstraint;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(uniqueConstraints = {
@UniqueConstraint(
name = "uk_chat_participant_chat_room_id_site_user_id",
columnNames = {"chat_room_id", "site_user_id"}
)
})
public class ChatParticipant extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "site_user_id")
private long siteUserId;

@ManyToOne(fetch = FetchType.LAZY)
private ChatRoom chatRoom;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.solidconnection.chat.domain;

import com.example.solidconnection.common.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(uniqueConstraints = {
@UniqueConstraint(
name = "uk_chat_read_status_chat_room_id_chat_participant_id",
columnNames = {"chat_room_id", "chat_participant_id"}
)
})
public class ChatReadStatus extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "chat_room_id")
private long chatRoomId;

@Column(name = "chat_participant_id")
private long chatParticipantId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.solidconnection.chat.domain;

import com.example.solidconnection.common.BaseEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ChatRoom extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private boolean isGroup = false;

@OneToMany(mappedBy = "chatRoom", cascade = CascadeType.ALL)
private List<ChatParticipant> chatParticipants = new ArrayList<>();

@OneToMany(mappedBy = "chatRoom", cascade = CascadeType.ALL)
private List<ChatMessage> chatMessages = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
CREATE TABLE chat_room
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
is_group BOOLEAN NOT NULL DEFAULT false,
created_at DATETIME(6) NOT NULL,
updated_at DATETIME(6) NOT NULL
);

CREATE TABLE chat_participant
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
site_user_id BIGINT NOT NULL,
chat_room_id BIGINT NOT NULL,
created_at DATETIME(6) NOT NULL,
updated_at DATETIME(6) NOT NULL,
CONSTRAINT FK_CHAT_PARTICIPANT_CHAT_ROOM_ID FOREIGN KEY (chat_room_id) REFERENCES chat_room (id),
CONSTRAINT FK_CHAT_PARTICIPANT_SITE_USER_ID FOREIGN KEY (site_user_id) REFERENCES site_user (id),
CONSTRAINT UK_CHAT_PARTICIPANT_CHAT_ROOM_ID_SITE_USER_ID UNIQUE (chat_room_id, site_user_id)
);

CREATE TABLE chat_message
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
content VARCHAR(500) NOT NULL,
sender_id BIGINT NOT NULL,
chat_room_id BIGINT NOT NULL,
created_at DATETIME(6) NOT NULL,
updated_at DATETIME(6) NOT NULL,
CONSTRAINT FK_CHAT_MESSAGE_CHAT_ROOM_ID FOREIGN KEY (chat_room_id) REFERENCES chat_room (id),
CONSTRAINT FK_CHAT_MESSAGE_SENDER_ID FOREIGN KEY (sender_id) REFERENCES chat_participant (id)
);

CREATE TABLE chat_attachment
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
is_image BOOLEAN NOT NULL,
url VARCHAR(500) NOT NULL,
thumbnail_url VARCHAR(500),
chat_message_id BIGINT NOT NULL,
created_at DATETIME(6) NOT NULL,
updated_at DATETIME(6) NOT NULL,
CONSTRAINT FK_CHAT_ATTACHMENT_CHAT_MESSAGE_ID FOREIGN KEY (chat_message_id) REFERENCES chat_message (id)
);

CREATE TABLE chat_read_status
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
chat_room_id BIGINT NOT NULL,
chat_participant_id BIGINT NOT NULL,
created_at DATETIME(6) NOT NULL,
updated_at DATETIME(6) NOT NULL,
CONSTRAINT FK_CHAT_READ_STATUS_CHAT_ROOM_ID FOREIGN KEY (chat_room_id) REFERENCES chat_room (id),
CONSTRAINT FK_CHAT_READ_STATUS_CHAT_PARTICIPANT_ID FOREIGN KEY (chat_participant_id) REFERENCES chat_participant (id),
CONSTRAINT UK_CHAT_READ_STATUS_CHAT_ROOM_ID_CHAT_PARTICIPANT_ID UNIQUE (chat_room_id, chat_participant_id)
);
Loading