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/#29 채팅 관련 로직 구현 #183

Merged
merged 15 commits into from
Jul 31, 2024
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
8fa3862
Feat: 채팅방 및 관련기능, 채팅 메세지 전송을 위한 웹소켓 설정
runtime-zer0 Jul 31, 2024
63714f3
Feat: 채팅방 관련 로직을 구현을 위한 레포지토리 및 DTO 구현
runtime-zer0 Jul 31, 2024
ee55eae
Feat: 채팅방에 참여한 사용자 정보 관리 로직 구현을 위한 레포지토리 및 DTO 구현
runtime-zer0 Jul 31, 2024
51fc1f9
Feat: 채팅 메세지 발행 및 전송, 메세지 수신 구현을 위한 레포지토리 및 DTO 구현
runtime-zer0 Jul 31, 2024
d0dee9a
Feat: 채팅방 입장, 퇴장 관련 로직을 구현하기 위한 비즈니스 로직 구현
runtime-zer0 Jul 31, 2024
ec84270
Feat: 메세지 발행 및 전송, 수신 관련 로직을 구현하기 위한 비즈니스 로직 및 유틸 클래스 구현
runtime-zer0 Jul 31, 2024
8392c8e
Feat: 채팅방 입장/퇴장 요청을 캐치하기 위한 컨트롤러 구현
runtime-zer0 Jul 31, 2024
8df6cef
Feat: 채팅 메세지 발행 및 전송, 채팅방 메세지 조회 요청을 캐치하기 위한 컨트롤러 구현
runtime-zer0 Jul 31, 2024
4686033
Feat: 채팅방 정보와 연관된 모집글 요약 정보 조희를 위한 로직 및 DTO 구현
runtime-zer0 Jul 31, 2024
c447551
Feat: 채팅방 입장/퇴장시 발생할 수 있는 예외 클래스 및 예외 핸들러 구현
runtime-zer0 Jul 31, 2024
84dafca
Feat: 채팅방에 입장한 사용자 관련 정보 관리시 발생할 수 있는 예외 클래스 및 예외 핸들러 구현
runtime-zer0 Jul 31, 2024
9db6afe
Feat: 채팅 메세지 발행 및 전송시 발생할 수 있는 예외 클래스 및 예외 핸들러 구현
runtime-zer0 Jul 31, 2024
b6cfb5d
Refactor: 클래스 이름 변경으로 인한 리팩토링 및 필드 이름 수정
runtime-zer0 Jul 31, 2024
7ac0dee
Refactor: 스프링의 단일 책임 원칙을 위한 리팩토링
runtime-zer0 Jul 31, 2024
42ff90c
Merge branch 'main' into feature/#29
runtime-zer0 Jul 31, 2024
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
Prev Previous commit
Next Next commit
Feat: 채팅 메세지 발행 및 전송, 채팅방 메세지 조회 요청을 캐치하기 위한 컨트롤러 구현
- ChatMessage
- 채팅방 입장/퇴장 요청을 캐치하기 위한 ChatMessageController.java 구현

- ChatMessageController.java
- 필드: chatMessageService

- publishMessage() 메서드: 특정 채팅방에 메세지 발행 및 전송 요청 캐치
- 요청 URI: '/api/chat/publication/{chatRoomId}'

- getChatMessages() 메서드: 채팅방 메세지 내역 조회 요청 캐치
- 요청 URI: '/api/chat/rooms/{chatRoomId}/messages'
runtime-zer0 committed Jul 31, 2024
commit 8df6ceff11d8613b39182c5ffe55535cf267b80b
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package sumcoda.boardbuddy.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestAttribute;
import sumcoda.boardbuddy.dto.ChatMessageRequest;
import sumcoda.boardbuddy.dto.ChatMessageResponse;
import sumcoda.boardbuddy.dto.common.ApiResponse;
import sumcoda.boardbuddy.service.ChatMessageService;

import java.util.List;
import java.util.Map;

import static sumcoda.boardbuddy.builder.ResponseBuilder.buildSuccessResponseWithPairKeyData;

@Controller
@RequiredArgsConstructor
public class ChatMessageController {

private final ChatMessageService chatMessageService;

/**
* 특정 채팅방에 메세지 발행 및 전송
*
* @param chatRoomId 채팅방 Id
* @param publishDTO 발행할 메세지 내용 DTO
* @param username 메시지를 발행하는 사용자 이름
**/
@MessageMapping("/publication/{chatRoomId}")
public void publishMessage(
@DestinationVariable Long chatRoomId,
@Payload ChatMessageRequest.PublishDTO publishDTO,
@RequestAttribute String username) {

chatMessageService.publishMessage(chatRoomId, publishDTO, username);
}

/**
* 채팅방 메세지 내역 조회
*
* @param chatRoomId 채팅방 Id
* @param username 요청을 보낸 사용자 아이디
* @return 채팅방 메세지 내역
*/
@GetMapping("/api/chat/rooms/{chatRoomId}/messages")
public ResponseEntity<ApiResponse<Map<String, List<ChatMessageResponse.ChatMessageInfoDTO>>>> getChatMessages(
@PathVariable Long chatRoomId,
@RequestAttribute String username) {

List<ChatMessageResponse.ChatMessageInfoDTO> chatMessages = chatMessageService.findMessagesAfterMemberJoinedByChatRoomIdAndUsername(chatRoomId, username);

return buildSuccessResponseWithPairKeyData("chatMessages", chatMessages, "채팅 메세지들의 정보를 성공적으로 조회했습니다.", HttpStatus.OK);
}
}