Skip to content
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

[feat #92] 채팅방 메시지 조회 API #93

Merged
merged 18 commits into from
Aug 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 32 additions & 41 deletions src/main/java/com/dnd/gongmuin/chat/domain/ChatMessage.java
Original file line number Diff line number Diff line change
@@ -1,69 +1,60 @@
package com.dnd.gongmuin.chat.domain;

import static jakarta.persistence.ConstraintMode.*;
import static jakarta.persistence.EnumType.*;
import static jakarta.persistence.FetchType.*;
import static jakarta.persistence.GenerationType.*;
import static lombok.AccessLevel.*;

import com.dnd.gongmuin.common.entity.TimeBaseEntity;
import com.dnd.gongmuin.member.domain.Member;
import java.time.LocalDateTime;

import org.springframework.data.mongodb.core.mapping.Document;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Enumerated;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Document(collection = "chat_messages")
@Getter
@NoArgsConstructor(access = PROTECTED)
public class ChatMessage extends TimeBaseEntity {
public class ChatMessage {

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "chat_message_id")
private Long id;
private String id;

@Column(name = "content", nullable = false)
private String content;

@Column(name = "is_read", nullable = false)
private long chatRoomId;

private long memberId;

private Boolean isRead;

@Column(name = "media_url", nullable = false)
private String mediaUrl;

@Enumerated(STRING)
@Column(name = "type", nullable = false)
private MessageType type;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "member_id",
nullable = false,
foreignKey = @ForeignKey(NO_CONSTRAINT))
private Member member;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "chat_room_id",
nullable = false,
foreignKey = @ForeignKey(NO_CONSTRAINT))
private ChatRoom chatRoom;
private LocalDateTime createdAt;

@Builder
public ChatMessage(String content, String mediaUrl, MessageType type, Member member,
ChatRoom chatRoom) {
this.isRead = false;
private ChatMessage(
String content,
long chatRoomId,
long memberId,
String mediaUrl,
MessageType type
) {
this.content = content;
this.chatRoomId = chatRoomId;
this.memberId = memberId;
this.mediaUrl = mediaUrl;
this.type = type;
this.member = member;
this.chatRoom = chatRoom;
this.isRead = false;
this.createdAt = LocalDateTime.now();
}

public static ChatMessage of(
String content,
long chatRoomId,
long memberId,
String mediaUrl,
MessageType type
) {
return new ChatMessage(content, chatRoomId, memberId, mediaUrl, type);
}
}
hyun2371 marked this conversation as resolved.
Show resolved Hide resolved