-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 채팅방 관련 api * feat: 채팅방, 채팅 메시지 엔티티 생성(#75) * feat: 채팅방 생성(#75) * feat: 체팅 메시지 엔티티에 채팅 방 추가(#75) * feat: 채팅방 목록 조회 쿼리 생성(#75) * feat: 채팅방 목록 조회 api 생성(#75) * feat: 채팅 요청 시 입장 메시지 추가(#75) * feat: 채팅 요청 수락(#75) * chore: 주석 추가(#75) * feat: sender, receiver로 변수명 통일(#75) * fix: 채팅 및 채팅방 생성과 알림 순서 수정(#75) * fix: sender, receiver로 변수명 통일(#75)
- Loading branch information
1 parent
8bbaade
commit 0c72062
Showing
27 changed files
with
582 additions
and
170 deletions.
There are no files selected for viewing
This file contains 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
46 changes: 0 additions & 46 deletions
46
be/src/main/java/yeonba/be/chatting/dto/ChattingRoomResponse.java
This file was deleted.
Oops, something went wrong.
This file contains 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
30 changes: 30 additions & 0 deletions
30
be/src/main/java/yeonba/be/chatting/dto/response/ChatRoomResponse.java
This file contains 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,30 @@ | ||
package yeonba.be.chatting.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import yeonba.be.chatting.entity.ChatRoom; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class ChatRoomResponse { | ||
|
||
@Schema(type = "number", description = "채팅방 ID", example = "1") | ||
private long id; | ||
|
||
@Schema(type = "string", description = "채팅 상대 이름", example = "김민재") | ||
private String partnerName; | ||
|
||
@Schema(type = "string", description = "채팅 상대 프로필 이미지 URL", example = "yeonba.com/profile") | ||
private String partnerProfileImageUrl; | ||
|
||
@Schema(type = "number", description = "읽지 않은 메시지 수", example = "25") | ||
private int unreadMessageNumber; | ||
|
||
@Schema(type = "string", description = "마지막 메시지", example = "잘 자!") | ||
private String lastMessage; | ||
|
||
@Schema(type = "string", description = "마지막 메시지 일시", example = "2022-10-11 13:20:15") | ||
private LocalDateTime lastMessageAt; | ||
} |
64 changes: 64 additions & 0 deletions
64
be/src/main/java/yeonba/be/chatting/entity/ChatMessage.java
This file contains 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,64 @@ | ||
package yeonba.be.chatting.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import java.time.LocalDateTime; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
import yeonba.be.user.entity.User; | ||
|
||
@Table(name = "chat_messages") | ||
@Getter | ||
@Entity | ||
@EntityListeners(value = AuditingEntityListener.class) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class ChatMessage { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "chat_room_id") | ||
private ChatRoom chatRoom; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "sent_user_id") | ||
private User sender; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "received_user_id") | ||
private User receiver; | ||
|
||
private String content; | ||
|
||
@Column(name = "is_read") | ||
private boolean read; | ||
|
||
private LocalDateTime sentAt; | ||
|
||
@CreatedDate | ||
private LocalDateTime createdAt; | ||
|
||
private LocalDateTime deletedAt; | ||
|
||
public ChatMessage(ChatRoom chatRoom, User sender, User receiver, String content) { | ||
|
||
this.chatRoom = chatRoom; | ||
this.sender = sender; | ||
this.receiver = receiver; | ||
this.content = content; | ||
this.read = false; | ||
} | ||
} |
This file contains 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,64 @@ | ||
package yeonba.be.chatting.entity; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.Table; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
import yeonba.be.user.entity.User; | ||
|
||
@Table(name = "chat_rooms") | ||
@Getter | ||
@Entity | ||
@EntityListeners(value = AuditingEntityListener.class) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EqualsAndHashCode(of = "id") | ||
public class ChatRoom { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "sent_user_id") | ||
private User sender; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "received_user_id") | ||
private User receiver; | ||
|
||
private boolean active; | ||
|
||
@CreatedDate | ||
private LocalDateTime createdAt; | ||
|
||
private LocalDateTime deletedAt; | ||
|
||
@OneToMany(mappedBy = "chatRoom") | ||
private List<ChatMessage> chatMessages; | ||
|
||
public ChatRoom(User sender, User receiver) { | ||
|
||
this.sender = sender; | ||
this.receiver = receiver; | ||
this.active = false; | ||
} | ||
|
||
public void activeRoom() { | ||
|
||
this.active = true; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
be/src/main/java/yeonba/be/chatting/repository/chatmessage/ChatMessageCommand.java
This file contains 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,17 @@ | ||
package yeonba.be.chatting.repository.chatmessage; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import yeonba.be.chatting.entity.ChatMessage; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ChatMessageCommand { | ||
|
||
private final ChatMessageRepository chatMessageRepository; | ||
|
||
public ChatMessage createChatMessage(ChatMessage message) { | ||
|
||
return chatMessageRepository.save(message); | ||
} | ||
} |
Oops, something went wrong.