From 49502b14695e40e0738981504e94eadbc97ccf0c Mon Sep 17 00:00:00 2001 From: Lee Da-hyeon Date: Thu, 14 Nov 2024 02:55:21 +0900 Subject: [PATCH 01/14] =?UTF-8?q?feat:=20ParticipantRepository=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20-=20findByWorkspaceId=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dangu/participant/domain/ParticipantRepository.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/hyunsolution/dangu/participant/domain/ParticipantRepository.java b/src/main/java/com/hyunsolution/dangu/participant/domain/ParticipantRepository.java index 764775a..3f8256c 100644 --- a/src/main/java/com/hyunsolution/dangu/participant/domain/ParticipantRepository.java +++ b/src/main/java/com/hyunsolution/dangu/participant/domain/ParticipantRepository.java @@ -21,4 +21,6 @@ public interface ParticipantRepository extends JpaRepository "SELECT p from Participant p join p.workspace w where p.user.id =:id and p.workspace.id=:workspaceId") Optional findByUserIdAndWorkspaceId( @Param("id") Long id, @Param("workspaceId") Long workspaceId); + + List findByWorkspaceId(Long workspaceId); } From 76f67a05b81c2503f0fc13c8ebd66d508819f8ba Mon Sep 17 00:00:00 2001 From: Lee Da-hyeon Date: Thu, 14 Nov 2024 02:57:33 +0900 Subject: [PATCH 02/14] =?UTF-8?q?feat:=20ParticipantController=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20-=20/participant/{roomNumber}=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../participant/controller/ParticipantController.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/hyunsolution/dangu/participant/controller/ParticipantController.java b/src/main/java/com/hyunsolution/dangu/participant/controller/ParticipantController.java index 371f5cd..c8489af 100644 --- a/src/main/java/com/hyunsolution/dangu/participant/controller/ParticipantController.java +++ b/src/main/java/com/hyunsolution/dangu/participant/controller/ParticipantController.java @@ -2,6 +2,7 @@ import com.hyunsolution.dangu.common.apiResponse.ApiResponse; import com.hyunsolution.dangu.participant.domain.ParticipantRepository; +import com.hyunsolution.dangu.participant.dto.response.EnterChatRoomResponse; import com.hyunsolution.dangu.participant.service.ParticipantService; import com.hyunsolution.dangu.user.domain.UserRepository; import com.hyunsolution.dangu.workspace.domain.WorkspaceRepository; @@ -21,6 +22,7 @@ public class ParticipantController { private final WorkspaceRepository workspaceRepository; private final ParticipantService participantService; + //사용자 매칭 버튼 클릭 @PostMapping("/participant/matching/{roomNumber}") public ApiResponse matching( @Parameter(hidden = true) @RequestHeader("Authorization") Long id, @@ -30,4 +32,13 @@ public ApiResponse matching( participantService.changeMatching(id, workspaceId); return ApiResponse.success(null); } + + // 사용자 채팅방 입장 + @PostMapping("/participant/{roomNumber}") + public ApiResponse enterChatRoom( + @Parameter(hidden = true) @RequestHeader("Authorization") Long id, + @PathVariable("roomNumber") Long workspaceId) { + EnterChatRoomResponse response = participantService.sendEnteringMessage(id, workspaceId); + return ApiResponse.success(response); + } } From 138dfff93fe8afe890e76adcf8e2b63972766bf6 Mon Sep 17 00:00:00 2001 From: Lee Da-hyeon Date: Thu, 14 Nov 2024 03:06:25 +0900 Subject: [PATCH 03/14] =?UTF-8?q?feat:=20=EC=97=90=EB=9F=AC=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20sendEnteringMessag?= =?UTF-8?q?e=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ParticipantService.java | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/hyunsolution/dangu/participant/service/ParticipantService.java b/src/main/java/com/hyunsolution/dangu/participant/service/ParticipantService.java index 597dd02..5c1f04e 100644 --- a/src/main/java/com/hyunsolution/dangu/participant/service/ParticipantService.java +++ b/src/main/java/com/hyunsolution/dangu/participant/service/ParticipantService.java @@ -2,12 +2,14 @@ import com.hyunsolution.dangu.participant.domain.Participant; import com.hyunsolution.dangu.participant.domain.ParticipantRepository; +import com.hyunsolution.dangu.participant.dto.response.EnterChatRoomResponse; +import com.hyunsolution.dangu.participant.exception.ParticipantNotFoundException; +import com.hyunsolution.dangu.user.domain.User; import com.hyunsolution.dangu.user.domain.UserRepository; import com.hyunsolution.dangu.workspace.domain.Workspace; import com.hyunsolution.dangu.workspace.domain.WorkspaceRepository; import java.util.List; -import java.util.NoSuchElementException; -import java.util.Optional; +import com.hyunsolution.dangu.workspace.exception.WorkspaceNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -23,8 +25,9 @@ public class ParticipantService { public void changeMatching(Long id, Long workspaceId) { // 상태 변경 Participant participantOptional = - participantRepository.findByUserIdAndWorkspaceId(id, workspaceId) - .orElseThrow(()-> new NoSuchElementException("Participant not found")); + participantRepository + .findByUserIdAndWorkspaceId(id, workspaceId) + .orElseThrow(() -> ParticipantNotFoundException.EXCEPTION); participantOptional.accept(); @@ -39,7 +42,33 @@ public void changeMatching(Long id, Long workspaceId) { } } // 게임방 테이블 속 매칭 결과를 true로 바꿈 - Workspace workspace1 = workspaceRepository.findById(workspaceId).orElseThrow(()-> new NoSuchElementException("Workspace not found")); + Workspace workspace1 = workspaceRepository.findById(workspaceId).orElseThrow(()-> WorkspaceNotFoundException.EXCEPTION); workspace1.acceptFinal(); } + + // 채팅방 입장 메시지 전송 + public EnterChatRoomResponse sendEnteringMessage(Long id, Long workspaceId) { + User user = userRepository.findById(id).orElseThrow(); + Workspace workspace = workspaceRepository.findById(workspaceId).orElseThrow(); + String message; + // 기존 채팅방에 1명(방장)만 존재하며 & 입장자가 방장이 아닐때 입장 메시지를 보낸다. + if (participantRepository.findByWorkspaceId(workspaceId).size() != 2 + && workspaceRepository.findById(workspaceId).get().getCreator().getId() != id) { + + // 입장자 participant 테이블에 저장 + Participant participant = + Participant.builder() + .user(user) + .workspace(workspace) + .participantMatch(false) + .build(); + participantRepository.save(participant); + + String userName = userRepository.findById(id).get().getUid(); + message = userName + "님이 입장하셨습니다."; + } else { + message = ""; + } + return new EnterChatRoomResponse(message); + } } From 39c56cc4179ffadaaf58529bbadab8667515fad7 Mon Sep 17 00:00:00 2001 From: Lee Da-hyeon Date: Thu, 14 Nov 2024 03:07:02 +0900 Subject: [PATCH 04/14] =?UTF-8?q?feat:=20EnterChatRoomResponse=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/EnterChatRoomResponse.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/com/hyunsolution/dangu/participant/dto/response/EnterChatRoomResponse.java diff --git a/src/main/java/com/hyunsolution/dangu/participant/dto/response/EnterChatRoomResponse.java b/src/main/java/com/hyunsolution/dangu/participant/dto/response/EnterChatRoomResponse.java new file mode 100644 index 0000000..9200048 --- /dev/null +++ b/src/main/java/com/hyunsolution/dangu/participant/dto/response/EnterChatRoomResponse.java @@ -0,0 +1,12 @@ +package com.hyunsolution.dangu.participant.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class EnterChatRoomResponse { + private String message; +} From e0b19fa4d2608bff62b9e3c2eba0602d79cab700 Mon Sep 17 00:00:00 2001 From: Lee Da-hyeon Date: Thu, 14 Nov 2024 03:07:31 +0900 Subject: [PATCH 05/14] =?UTF-8?q?feat:=20ParticipantError=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/ParticipantError.java | 22 +++++++++++++++++++ .../ParticipantNotFoundException.java | 11 ++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/main/java/com/hyunsolution/dangu/participant/exception/ParticipantError.java create mode 100644 src/main/java/com/hyunsolution/dangu/participant/exception/ParticipantNotFoundException.java diff --git a/src/main/java/com/hyunsolution/dangu/participant/exception/ParticipantError.java b/src/main/java/com/hyunsolution/dangu/participant/exception/ParticipantError.java new file mode 100644 index 0000000..58605a2 --- /dev/null +++ b/src/main/java/com/hyunsolution/dangu/participant/exception/ParticipantError.java @@ -0,0 +1,22 @@ +package com.hyunsolution.dangu.participant.exception; + +import com.hyunsolution.dangu.common.exception.BaseErrorCode; +import com.hyunsolution.dangu.common.exception.ExceptionDto; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum ParticipantError implements BaseErrorCode { + PARTICIPANT_NOT_FOUND("PARTICIPANT_400_1", HttpStatus.BAD_REQUEST, "해당 채팅방 참여자를 찾을 수 없습니다."); + + private final String code; + private final HttpStatus httpStatus; + private final String message; + + @Override + public ExceptionDto getErrorReason() { + return ExceptionDto.builder().code(code).message(message).httpStatus(httpStatus).build(); + } +} diff --git a/src/main/java/com/hyunsolution/dangu/participant/exception/ParticipantNotFoundException.java b/src/main/java/com/hyunsolution/dangu/participant/exception/ParticipantNotFoundException.java new file mode 100644 index 0000000..bed8a01 --- /dev/null +++ b/src/main/java/com/hyunsolution/dangu/participant/exception/ParticipantNotFoundException.java @@ -0,0 +1,11 @@ +package com.hyunsolution.dangu.participant.exception; + +import com.hyunsolution.dangu.common.exception.CustomException; + +public class ParticipantNotFoundException extends CustomException { + public static final ParticipantNotFoundException EXCEPTION = new ParticipantNotFoundException(); + + private ParticipantNotFoundException() { + super(ParticipantError.PARTICIPANT_NOT_FOUND); + } +} From 331515209cfceb91e5afd435dab332a19770830f Mon Sep 17 00:00:00 2001 From: Lee Da-hyeon Date: Thu, 14 Nov 2024 03:07:46 +0900 Subject: [PATCH 06/14] =?UTF-8?q?feat:=20WorkspaceError=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workspace/exception/WorkspaceError.java | 22 +++++++++++++++++++ .../exception/WorkspaceNotFoundException.java | 11 ++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/main/java/com/hyunsolution/dangu/workspace/exception/WorkspaceError.java create mode 100644 src/main/java/com/hyunsolution/dangu/workspace/exception/WorkspaceNotFoundException.java diff --git a/src/main/java/com/hyunsolution/dangu/workspace/exception/WorkspaceError.java b/src/main/java/com/hyunsolution/dangu/workspace/exception/WorkspaceError.java new file mode 100644 index 0000000..34c5026 --- /dev/null +++ b/src/main/java/com/hyunsolution/dangu/workspace/exception/WorkspaceError.java @@ -0,0 +1,22 @@ +package com.hyunsolution.dangu.workspace.exception; + +import com.hyunsolution.dangu.common.exception.BaseErrorCode; +import com.hyunsolution.dangu.common.exception.ExceptionDto; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum WorkspaceError implements BaseErrorCode { + WORKSPACE_NOT_FOUND("WORKSAPCE_400_1", HttpStatus.BAD_REQUEST, "채팅방을 찾을 수 없습니다."); + + private final String code; + private final HttpStatus httpStatus; + private final String message; + + @Override + public ExceptionDto getErrorReason() { + return ExceptionDto.builder().code(code).message(message).httpStatus(httpStatus).build(); + } +} diff --git a/src/main/java/com/hyunsolution/dangu/workspace/exception/WorkspaceNotFoundException.java b/src/main/java/com/hyunsolution/dangu/workspace/exception/WorkspaceNotFoundException.java new file mode 100644 index 0000000..dce40aa --- /dev/null +++ b/src/main/java/com/hyunsolution/dangu/workspace/exception/WorkspaceNotFoundException.java @@ -0,0 +1,11 @@ +package com.hyunsolution.dangu.workspace.exception; + +import com.hyunsolution.dangu.common.exception.CustomException; + +public class WorkspaceNotFoundException extends CustomException { + public static final WorkspaceNotFoundException EXCEPTION = new WorkspaceNotFoundException(); + + private WorkspaceNotFoundException() { + super(WorkspaceError.WORKSPACE_NOT_FOUND); + } +} From 2dfeb6a7f34314b95bcc4193bbbfda2f14b8db78 Mon Sep 17 00:00:00 2001 From: Lee Da-hyeon Date: Fri, 15 Nov 2024 01:11:43 +0900 Subject: [PATCH 07/14] =?UTF-8?q?feat:=20Workspace=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?-=20totalCnt=20=EC=B9=BC=EB=9F=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hyunsolution/dangu/workspace/domain/Workspace.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/com/hyunsolution/dangu/workspace/domain/Workspace.java b/src/main/java/com/hyunsolution/dangu/workspace/domain/Workspace.java index 9815859..6bcd072 100644 --- a/src/main/java/com/hyunsolution/dangu/workspace/domain/Workspace.java +++ b/src/main/java/com/hyunsolution/dangu/workspace/domain/Workspace.java @@ -31,19 +31,14 @@ public class Workspace { @ColumnDefault("false") private boolean isMatched; - @Column(name = "total_cnt", nullable = false) - @ColumnDefault("0") - private int totalCnt; - @Column(name = "created_at", nullable = false) @CreatedDate private LocalDateTime createdAt; @Builder - public Workspace(User creator, boolean isMatched, int totalCnt, LocalDateTime createdAt) { + public Workspace(User creator, boolean isMatched, LocalDateTime createdAt) { this.creator = creator; this.isMatched = isMatched; - this.totalCnt = totalCnt; this.createdAt = createdAt; } From e99bda40fbb07cf11f428dde5f2e417e07498861 Mon Sep 17 00:00:00 2001 From: Lee Da-hyeon Date: Fri, 15 Nov 2024 01:12:47 +0900 Subject: [PATCH 08/14] =?UTF-8?q?feat:=20ChatRepository=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20-=20countMessageByRoomId=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dangu/chatting/domain/ChatRepository.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/hyunsolution/dangu/chatting/domain/ChatRepository.java b/src/main/java/com/hyunsolution/dangu/chatting/domain/ChatRepository.java index 4c42de2..209dc61 100644 --- a/src/main/java/com/hyunsolution/dangu/chatting/domain/ChatRepository.java +++ b/src/main/java/com/hyunsolution/dangu/chatting/domain/ChatRepository.java @@ -1,5 +1,11 @@ package com.hyunsolution.dangu.chatting.domain; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; -public interface ChatRepository extends JpaRepository {} +public interface ChatRepository extends JpaRepository { + + @Query("SELECT COUNT(c) FROM Chatlog c WHERE c.workspace.id=:roomId") + int countMessageByRoomId(@Param("roomId") Long roomId); +} From 91347c1852bbce8d15946c0dd2347862abc9cb96 Mon Sep 17 00:00:00 2001 From: Lee Da-hyeon Date: Fri, 15 Nov 2024 01:13:27 +0900 Subject: [PATCH 09/14] =?UTF-8?q?feat:=20ChatController=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20-=20/chat/{chatRoomId}/exit=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chatting/controller/ChatController.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/hyunsolution/dangu/chatting/controller/ChatController.java b/src/main/java/com/hyunsolution/dangu/chatting/controller/ChatController.java index e625d3c..83485cd 100644 --- a/src/main/java/com/hyunsolution/dangu/chatting/controller/ChatController.java +++ b/src/main/java/com/hyunsolution/dangu/chatting/controller/ChatController.java @@ -3,7 +3,8 @@ import com.hyunsolution.dangu.chatting.dto.request.ChatMessageRequest; import com.hyunsolution.dangu.chatting.dto.response.ChatMessageDetailResponse; import com.hyunsolution.dangu.chatting.dto.response.ChatMessageResponse; -import com.hyunsolution.dangu.chatting.dto.service.ChatService; +import com.hyunsolution.dangu.chatting.service.ChatService; +import com.hyunsolution.dangu.common.apiResponse.ApiResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.messaging.handler.annotation.DestinationVariable; @@ -11,15 +12,18 @@ import org.springframework.messaging.handler.annotation.Payload; import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.messaging.simp.stomp.StompHeaderAccessor; -import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RestController; @Slf4j -@Controller +@RestController @RequiredArgsConstructor public class ChatController { private final ChatService chatService; - //채팅기능 + // 채팅기능 @MessageMapping("/chat/{chatRoomId}") @SendTo("/topic/chat/{chatRoomId}") public ChatMessageResponse sendChatMessage( @@ -33,4 +37,11 @@ public ChatMessageResponse sendChatMessage( return new ChatMessageResponse("success", response, null); } + + @PostMapping("/chat/{chatRoomId}/exit") + public ApiResponse exitChat( + @PathVariable Long chatRoomId, @RequestHeader("Authorization") Long userPk) { + chatService.readMessageCnt(userPk, chatRoomId); + return ApiResponse.success(true); + } } From bbf5a9d10495acc249f6842c67dea72a74f1c46f Mon Sep 17 00:00:00 2001 From: Lee Da-hyeon Date: Fri, 15 Nov 2024 01:13:57 +0900 Subject: [PATCH 10/14] =?UTF-8?q?feat:=20ChatService=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dangu/chatting/service/ChatService.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/hyunsolution/dangu/chatting/service/ChatService.java b/src/main/java/com/hyunsolution/dangu/chatting/service/ChatService.java index 072997b..3e9893d 100644 --- a/src/main/java/com/hyunsolution/dangu/chatting/service/ChatService.java +++ b/src/main/java/com/hyunsolution/dangu/chatting/service/ChatService.java @@ -1,5 +1,6 @@ package com.hyunsolution.dangu.chatting.service; +import com.hyunsolution.dangu.chatlog.service.ChatlogService; import com.hyunsolution.dangu.chatting.domain.ChatRepository; import com.hyunsolution.dangu.chatting.domain.Chatting; import com.hyunsolution.dangu.chatting.dto.response.ChatMessageDetailResponse; @@ -19,6 +20,7 @@ public class ChatService { private final ChatRepository chatRepository; private final WorkspaceRepository workspaceRepository; private final UserRepository userRepository; + private final ChatlogService chatlogService; @Transactional public ChatMessageDetailResponse sendMessage(Long chatRoomId, String message, Long userPk) { @@ -26,11 +28,9 @@ public ChatMessageDetailResponse sendMessage(Long chatRoomId, String message, Lo Workspace workspace = workspaceRepository .findById(chatRoomId) - .orElseThrow(() ->ChatRoomNotFoundException.EXCEPTION); + .orElseThrow(() -> ChatRoomNotFoundException.EXCEPTION); User user = - userRepository - .findById(userPk) - .orElseThrow(() -> UserNotFoundException.EXCEPTION); + userRepository.findById(userPk).orElseThrow(() -> UserNotFoundException.EXCEPTION); Chatting chatMessage = Chatting.builder().workspace(workspace).user(user).content(message).build(); @@ -41,4 +41,12 @@ public ChatMessageDetailResponse sendMessage(Long chatRoomId, String message, Lo new ChatMessageDetailResponse(message, user.getUid(), chatMessage.getCreatedAt()); return detailResponse; } + + @Transactional + public void readMessageCnt(Long chatRoomId, Long userPk) { + // 채팅방 나갈 시점에서의 메세지 개수 조회 + int messageCnt = chatRepository.countMessageByRoomId(chatRoomId); + // chatlog 테이블 속 readCount 업데이트 + chatlogService.updateReadCount(chatRoomId, userPk, messageCnt); + } } From 6c4fb42dfcfab8792f6818747b1a7c89aa25ad9a Mon Sep 17 00:00:00 2001 From: Lee Da-hyeon Date: Fri, 15 Nov 2024 01:14:47 +0900 Subject: [PATCH 11/14] =?UTF-8?q?feat:=20ChatlogService=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dangu/chatlog/service/ChatlogService.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/com/hyunsolution/dangu/chatlog/service/ChatlogService.java diff --git a/src/main/java/com/hyunsolution/dangu/chatlog/service/ChatlogService.java b/src/main/java/com/hyunsolution/dangu/chatlog/service/ChatlogService.java new file mode 100644 index 0000000..23fe682 --- /dev/null +++ b/src/main/java/com/hyunsolution/dangu/chatlog/service/ChatlogService.java @@ -0,0 +1,18 @@ +package com.hyunsolution.dangu.chatlog.service; + +import com.hyunsolution.dangu.chatlog.chatlogRepository.ChatlogRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class ChatlogService { + private final ChatlogRepository chatlogRepository; + + // 채팅방별 사용자의 읽은 채팅 개수 업데이트 + @Transactional + public void updateReadCount(Long chatRoomId, Long userPk, int messageCnt) { + chatlogRepository.updateCount(chatRoomId, userPk, messageCnt); + } +} From 1c2b5ea7229c40a8a3ed9aa276487965244147d5 Mon Sep 17 00:00:00 2001 From: Lee Da-hyeon Date: Fri, 15 Nov 2024 01:15:28 +0900 Subject: [PATCH 12/14] =?UTF-8?q?feat:=20ChatlogRepository=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20-=20updateCount=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chatlogRepository/ChatlogRepository.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/com/hyunsolution/dangu/chatlog/chatlogRepository/ChatlogRepository.java diff --git a/src/main/java/com/hyunsolution/dangu/chatlog/chatlogRepository/ChatlogRepository.java b/src/main/java/com/hyunsolution/dangu/chatlog/chatlogRepository/ChatlogRepository.java new file mode 100644 index 0000000..32d442b --- /dev/null +++ b/src/main/java/com/hyunsolution/dangu/chatlog/chatlogRepository/ChatlogRepository.java @@ -0,0 +1,18 @@ +package com.hyunsolution.dangu.chatlog.chatlogRepository; + +import com.hyunsolution.dangu.chatlog.Chatlog; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface ChatlogRepository extends JpaRepository { + + @Modifying + @Query( + "UPDATE Chatlog c SET c.readCount=:readCount WHERE c.user.id=:userId AND c.workspace.id=:workspaceId") + void updateCount( + @Param("userId") Long userId, + @Param("workspaceId") Long workspaceId, + @Param("readCount") int readCount); +} From 7f313aa6797608c7cb8e5cdba08551f9c165f760 Mon Sep 17 00:00:00 2001 From: Lee Da-hyeon Date: Sat, 16 Nov 2024 17:07:57 +0900 Subject: [PATCH 13/14] =?UTF-8?q?docs:=20/chat/{chatRoomId}/exit=20?= =?UTF-8?q?=EC=8A=A4=EC=9B=A8=EA=B1=B0=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hyunsolution/dangu/chatting/controller/ChatController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/hyunsolution/dangu/chatting/controller/ChatController.java b/src/main/java/com/hyunsolution/dangu/chatting/controller/ChatController.java index 83485cd..d485b16 100644 --- a/src/main/java/com/hyunsolution/dangu/chatting/controller/ChatController.java +++ b/src/main/java/com/hyunsolution/dangu/chatting/controller/ChatController.java @@ -5,6 +5,7 @@ import com.hyunsolution.dangu.chatting.dto.response.ChatMessageResponse; import com.hyunsolution.dangu.chatting.service.ChatService; import com.hyunsolution.dangu.common.apiResponse.ApiResponse; +import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.messaging.handler.annotation.DestinationVariable; @@ -38,6 +39,7 @@ public ChatMessageResponse sendChatMessage( return new ChatMessageResponse("success", response, null); } + @Operation(summary = "채팅방 나가기", description = "채팅방을 나갈 시 해당 채팅방의 전체 메세지 개수를 저장합니다.") @PostMapping("/chat/{chatRoomId}/exit") public ApiResponse exitChat( @PathVariable Long chatRoomId, @RequestHeader("Authorization") Long userPk) { From 01a8bb2563af91dd508406b805a1ed6e8e81e666 Mon Sep 17 00:00:00 2001 From: Lee Da-hyeon Date: Sat, 16 Nov 2024 17:08:53 +0900 Subject: [PATCH 14/14] =?UTF-8?q?docs:=20WebSocketSwaggerDocsController=20?= =?UTF-8?q?=EC=8A=A4=EC=9B=A8=EA=B1=B0=20=EC=A0=81=EC=9A=A9=20-=20?= =?UTF-8?q?=EC=9B=B9=EC=86=8C=EC=BC=93=20=EB=AC=B8=EC=84=9C=ED=99=94?= =?UTF-8?q?=EC=9A=A9=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WebSocketSwaggerDocsController.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/com/hyunsolution/dangu/common/config/webSocket/WebSocketSwaggerDocsController.java diff --git a/src/main/java/com/hyunsolution/dangu/common/config/webSocket/WebSocketSwaggerDocsController.java b/src/main/java/com/hyunsolution/dangu/common/config/webSocket/WebSocketSwaggerDocsController.java new file mode 100644 index 0000000..522b7c1 --- /dev/null +++ b/src/main/java/com/hyunsolution/dangu/common/config/webSocket/WebSocketSwaggerDocsController.java @@ -0,0 +1,20 @@ +package com.hyunsolution.dangu.common.config.webSocket; + +import io.swagger.v3.oas.annotations.Operation; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class WebSocketSwaggerDocsController { + @Operation( + summary = "WebSocket 연결 정보", + description = + """ + WebSocket URL, 구독 경로 및 발행 경로 안내 + - WebSocket 접속 URL: wss://54.221.244.36:8080/chat + - STOMP 구독 주소: /topic/chat/{chatRoomId} + - 메시지 전송 주소: /app/chat/{chatRoomId} + """) + @GetMapping("/websocket/info") // 스웨거 웹소켓관련 정보 제공을 위한 api + public void getWebSocketInfo() {} +}