-
Notifications
You must be signed in to change notification settings - Fork 8
feat: 채팅 관련 엔티티 및 DDL 작성 #395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
whqtker
merged 10 commits into
solid-connection:develop
from
whqtker:feat/394-create-chat-related-entities
Jul 25, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a2e64a1
feat: 채팅 관련 엔티티 생성
whqtker 8e944ba
feat: 채팅 관련 테이블의 DDL 작성
whqtker ea3ca25
fix: DDL 콤마 누락 문제 해결
whqtker 7d7608f
feat: chat_participant 테이블에서 chat_room, site_user 간 고유 키 생성
whqtker b4f76e4
chore: ChatReadStatus 엔티티에 UK 제약조건 추가
whqtker fc3f404
fix: JPA가 UK 제약 조건 생성 시 컬럼을 찾지 못하는 문제 해결
whqtker 454f545
chore: UK 제약 조건 이름 변경
whqtker 137ae2f
chore: isGroup, hasAttachment 필드에 기본값 생성
whqtker 9bd9858
chore: hasAttachment 컬럼 제거
whqtker d468369
chore: flyway 파일 버전 수정
whqtker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/com/example/solidconnection/chat/domain/ChatAttachment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/example/solidconnection/chat/domain/ChatMessage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
|
||
| private long senderId; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| private ChatRoom chatRoom; | ||
|
|
||
| @OneToMany(mappedBy = "chatMessage", cascade = CascadeType.ALL) | ||
| private List<ChatAttachment> chatAttachments = new ArrayList<>(); | ||
| } | ||
37 changes: 37 additions & 0 deletions
37
src/main/java/com/example/solidconnection/chat/domain/ChatParticipant.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/example/solidconnection/chat/domain/ChatReadStatus.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/example/solidconnection/chat/domain/ChatRoom.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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<>(); | ||
| } |
55 changes: 55 additions & 0 deletions
55
src/main/resources/db/migration/V24__add_chat_related_tables.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
메시지 내용에 대한 검증을 추가해주세요.
빈 메시지나 공백만 있는 메시지를 방지하기 위한 검증을 추가하는 것이 좋겠습니다.
📝 Committable suggestion
🤖 Prompt for AI Agents