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

Feature/#60 backend chatting #72

Open
wants to merge 34 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d649ca8
feat: add chatting table
kim1387 May 17, 2022
820375f
feat: chatting entity 연관관계 설정
kim1387 May 18, 2022
c926528
feat: text message를 위한 상속 message entity
kim1387 May 18, 2022
b385ae5
feat: 이모티콘 message를 위한 상속 message entity
kim1387 May 18, 2022
5e69a42
feat: 이미지 message를 위한 상속 message entity
kim1387 May 18, 2022
d3996d5
feat: add stomp config
kim1387 May 18, 2022
d59f5b6
style: move directory
kim1387 May 22, 2022
254205f
feat: add chatRoomUser entity for implements of many to many
kim1387 May 22, 2022
638f1f8
feat: add entities repository
kim1387 May 22, 2022
9989b5e
feat: 채팅방 관련 api spec 정의
kim1387 May 23, 2022
10b31f1
feat: 채팅 메시지 관련 api 스펙 정의
kim1387 May 23, 2022
836c4af
fix: 채팅방을 만드는 것은 seller 뿐만이 아니기 때문에 createdByUser로 바꾸었다. 그 외의 컬럼 추가
kim1387 May 24, 2022
ecfe542
feat: chatroomuser 엔티티를 위한 builder 생성
kim1387 May 24, 2022
7786631
feat: 중고거래 채팅방 생성을 위한 response 추가
kim1387 May 24, 2022
e73dadf
feat: sellerId를 이용해 채팅방 생성하는 기능 추가
kim1387 May 24, 2022
3cf0c2b
feat: 채팅에 대한 exception handler 추가
kim1387 May 24, 2022
21d93d1
feat: 채팅방 숨기기 기능 추가
kim1387 May 24, 2022
ac1c560
feat: 채팅방 리스트 조회용 테이블 추가
kim1387 May 25, 2022
7e3c11c
feat: ChatRoomEntranceRepository 추가
kim1387 May 25, 2022
ee3a387
fix: 메시지는 수정될 수 없음으로 수정 날짜는 필요없어서 기록하지 않도록 변경
kim1387 May 25, 2022
459a373
feat: 존재하지 않는 사용자에 대한 예외처리 추가
kim1387 May 25, 2022
5a878eb
fix: 존재하지 않는 사용자에 대한 예외처리 구체적으로 변경
kim1387 May 25, 2022
feaad2a
feat: 채팅방 리스트 조회 response 제작
kim1387 May 25, 2022
4fb01ea
style: UserProfileDTO에서 UserProfileInfo로 이름 변경
kim1387 May 25, 2022
0ce1a4c
feat: 들어가 있는 채팅 방을 조회할 수 있는 response 제작
kim1387 May 26, 2022
dc9c612
feat: 들어가 있는 채팅 방을 조회할 수 있는 response 제작
kim1387 May 26, 2022
3c14091
feat: 참여중인 채팅방이 없을 때 예외 처리
kim1387 May 26, 2022
3f64878
style: add 컬럼에 대한 주석
kim1387 May 26, 2022
506bcf3
feat: 들어가 있는 채팅방 조회 기능
kim1387 May 26, 2022
c1412cd
style: EntranceChatRoom로 rename
kim1387 May 26, 2022
3aa370b
feat: entity 생성 삭제 시간 기록 설정
kim1387 Jun 6, 2022
ab7f3b1
feat: text 일반 채팅 기능 구현
kim1387 Jun 7, 2022
c260aaa
fix: websocket prefix 주소 변경
kim1387 Jun 7, 2022
67a5052
Merge branch 'develop' of https://github.com/h-jjang/bauction into fe…
kim1387 Jun 7, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.hjjang.backend.domain.chat.controller;


import com.hjjang.backend.domain.chat.dto.MessageRequest;
import com.hjjang.backend.domain.chat.service.ChatMessageService;
import lombok.RequiredArgsConstructor;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
public class ChatMessageController {

private final ChatMessageService chatMessageService;

// 일반 채팅 보내기
@MessageMapping("/text/{roomId}")
public void chatByText(@PathVariable("roomId") Long roomId, @RequestBody MessageRequest messageRequest) {
chatMessageService.chatByText(roomId, messageRequest);
}

// 사진 채팅 보내기
@MessageMapping("/image")
public void chatByImage() {

}

// 이모티콘 채팅 보내기
@MessageMapping("/emoji")
public void chatByEmoji() {

}


// 메시지 숨기기
@DeleteMapping
public void hideMessage() {

}

// 메시지 조회 / 페이징
@GetMapping("/{chatRoomId}")
public void readMessageByChatRoom() {

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.hjjang.backend.domain.chat.controller;


import com.hjjang.backend.domain.chat.dto.CreateTradeChatRoomResponse;
import com.hjjang.backend.domain.chat.service.ChatRoomService;
import com.hjjang.backend.global.response.response.SuccessResponse;
import com.hjjang.backend.global.util.UserUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import static com.hjjang.backend.global.response.code.SuccessCode.CREATE_CHAT_ROOM_SUCCESS;

@RequestMapping("/api/chatroom")
@RestController
@RequiredArgsConstructor
public class ChatRoomController {

private final ChatRoomService chatRoomService;
private final UserUtil userUtil;

// 채팅방 생성 test를 위한 api
// 채팅방은 거래 시작 혹은 경매 시작과 동시에 생성되기 때문
@PostMapping("/trade/{sellerId}")
public ResponseEntity<SuccessResponse> createChatRoom(@PathVariable Long sellerId) {
CreateTradeChatRoomResponse createTradeChatRoomResponse
= chatRoomService.createChatTradeRoomBySellerId(sellerId);
return ResponseEntity.ok(SuccessResponse.of(CREATE_CHAT_ROOM_SUCCESS, createTradeChatRoomResponse));
}

// 채팅 방 리스트 조회 / 페이징
@GetMapping
public void readPagingChatRoomList() {

}

// 채팅 방 신고하기
@PostMapping("/report")
public void reportChatRoom() {

}


// 규정을 어길 시 채팅 방 삭제하기
@DeleteMapping("/{chatRoomId}")
public void hideChatRoom() {

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.hjjang.backend.domain.chat.domain.entity;

import com.hjjang.backend.domain.user.entity.User;
import com.hjjang.backend.global.domain.BaseCreatedTimeEntity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

import static javax.persistence.FetchType.LAZY;
import static javax.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

@Getter
@AllArgsConstructor
@Entity
@NoArgsConstructor(access = PROTECTED)
@DiscriminatorColumn
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "chat_message")
public class ChatMessage extends BaseCreatedTimeEntity {

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

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "sender_user_id")
private User senderUser;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "chat_room_id")
private ChatRoom chatRoom;

// chatting 할 때 이미지 메세지, 이모티콘, 이미지를 구별할 수 있는 dtype
// 없어도 되지만 명시적으로 선언
@Column(updatable = false)
private String dtype;

public ChatMessage(User senderUser, ChatRoom chatRoom) {
this.senderUser = senderUser;
this.chatRoom = chatRoom;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.hjjang.backend.domain.chat.domain.entity;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Table;

@Getter
@Entity
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@DiscriminatorValue("emoji")
@Table(name = "chat_message_emoji")
public class ChatMessageEmoji extends ChatMessage {

@Column(name = "chat_message_emoji_content")
private Emoji emoji;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.hjjang.backend.domain.chat.domain.entity;

import com.hjjang.backend.domain.image.domain.entity.Image;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Getter
@Entity
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@DiscriminatorValue("image")
@Table(name = "chat_message_image")
public class ChatMessageImage extends ChatMessage {

@OneToOne
@JoinColumn(name = "image_id")
private Image image;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.hjjang.backend.domain.chat.domain.entity;

import com.hjjang.backend.domain.user.entity.User;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Table;

@Getter
@Entity
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@DiscriminatorValue("text")
@Table(name = "chat_message_text")
public class ChatMessageText extends ChatMessage {

@Column(name = "chat_message_text_content")
private String chatMessageContent;

public ChatMessageText(User senderUser, ChatRoom chatRoom, String chatMessageContent) {
super(senderUser, chatRoom);
this.chatMessageContent = chatMessageContent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.hjjang.backend.domain.chat.domain.entity;

import com.hjjang.backend.domain.user.entity.User;
import com.hjjang.backend.global.domain.BaseTimeEntity;
import lombok.*;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

import static javax.persistence.FetchType.LAZY;

@Getter
@Entity
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "chat_room")
public class ChatRoom extends BaseTimeEntity {

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

// 경매 상황을 대비하여 생성 유저를 알 수 있는 컬럼을 만들었다.
@ManyToOne(fetch = LAZY)
@JoinColumn(name = "created_by_user_id")
private User createdByUser;

@OneToMany(mappedBy = "chatRoom")
private List<ChatRoomUser> chatRoomUsers = new ArrayList<>();

// 채팅방 삭제 관련 컬럼
@Column(name = "is_hidden")
private Boolean isHidden;

@Builder
public ChatRoom(User createdByUser, List<ChatRoomUser> chatRoomUsers) {
this.createdByUser = createdByUser;
this.chatRoomUsers = chatRoomUsers;
this.isHidden = false;
}

public void hideChatRoom() {
this.isHidden = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.hjjang.backend.domain.chat.domain.entity;

import com.hjjang.backend.domain.user.entity.User;
import lombok.*;

import javax.persistence.*;

import static javax.persistence.FetchType.LAZY;

@Getter
@Entity
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "chat_room_user")
public class ChatRoomUser {

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

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "user_id")
private User user;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "chat_room_id")
private ChatRoom chatRoom;

@Builder
public ChatRoomUser(User user, ChatRoom chatRoom) {
this.user = user;
this.chatRoom = chatRoom;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.hjjang.backend.domain.chat.domain.entity;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum Emoji {
SMILE("스마일", "스마일 이모지 url 입니다."),
CRY("울음", "울음 이모지 url 입니다."),
MAD("화남", "화남 이모지 url 입니다.");

private final String name;
private final String url;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.hjjang.backend.domain.chat.domain.entity;

import com.hjjang.backend.domain.user.entity.User;
import com.hjjang.backend.global.domain.BaseCreatedTimeEntity;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "chat_room_entrance")
public class EntranceChatRoom extends BaseCreatedTimeEntity {
// 채팅 방 목록을 조회할 때 사용하는 조회용 테이블
// 장점
// 1. 마지막 보낸 메시지 join 없이 찾기 가능
// 2. 별도의 join 없이 사용자 id로 바로 찾을 수 있음

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

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "chat_room_id")
private ChatRoom chatRoom;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "last_chat_message_id")
private ChatMessage lastChatMessage;

@Builder
public EntranceChatRoom(ChatRoom chatRoom, User user, ChatMessage lastChatMessage) {
this.chatRoom = chatRoom;
this.user = user;
this.lastChatMessage = lastChatMessage;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.hjjang.backend.domain.chat.domain.repository;

import com.hjjang.backend.domain.chat.domain.entity.ChatMessageEmoji;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ChatMessageEmojiRepository extends JpaRepository<ChatMessageEmoji, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.hjjang.backend.domain.chat.domain.repository;

import com.hjjang.backend.domain.chat.domain.entity.ChatMessageImage;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ChatMessageImageRepository extends JpaRepository<ChatMessageImage, Long> {


}
Loading