From e9f5a0a857a229d5aa2453968643cc9e75af4f9e Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Thu, 23 May 2024 20:08:42 +0900 Subject: [PATCH 01/12] =?UTF-8?q?[refactor]:Socket=20Chat=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EA=B4=80=EB=A0=A8=20api=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat}/controller/ChatController.java | 18 +++---------- .../chat}/service/ChatService.java | 11 +++----- .../request/ChatMessageRoomRequestDto.java | 2 +- .../response/ChatMessageRoomResponseDto.java | 3 ++- .../room}/controller/RoomController.java | 12 +++------ .../dto/request/ChatListRequestDto.java | 11 -------- .../request/ChatMessageListRequestDto.java | 13 --------- .../dto/request/ChatMessageRequestDto.java | 14 ---------- .../dto/request/RoomChatMessageListReq.java | 14 ---------- .../request/RoomMessageListRequestDto.java | 13 --------- .../dto/response/ChatListResponseDto.java | 18 ------------- .../dto/response/ChatMessageResponseDto.java | 22 --------------- .../dto/response/SendMessageResponseDto.java | 18 ------------- .../dto/response/UserChatResponseDto.java | 27 ------------------- .../application/service/RedisSubscriber.java | 3 +-- .../chat/application/service/RoomService.java | 4 --- 16 files changed, 13 insertions(+), 190 deletions(-) rename socket/src/main/java/Backend/socket/{domain/chat/application => api/chat}/controller/ChatController.java (79%) rename socket/src/main/java/Backend/socket/{domain/chat/application => api/chat}/service/ChatService.java (95%) rename socket/src/main/java/Backend/socket/{domain/chat/application/controller => api/chat/service}/dto/request/ChatMessageRoomRequestDto.java (85%) rename socket/src/main/java/Backend/socket/{domain/chat/application/controller => api/chat/service}/dto/response/ChatMessageRoomResponseDto.java (78%) rename socket/src/main/java/Backend/socket/{domain/chat/application => api/room}/controller/RoomController.java (81%) delete mode 100644 socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/ChatListRequestDto.java delete mode 100644 socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/ChatMessageListRequestDto.java delete mode 100644 socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/ChatMessageRequestDto.java delete mode 100644 socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/RoomChatMessageListReq.java delete mode 100644 socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/RoomMessageListRequestDto.java delete mode 100644 socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatListResponseDto.java delete mode 100644 socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageResponseDto.java delete mode 100644 socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/SendMessageResponseDto.java delete mode 100644 socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/UserChatResponseDto.java diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/ChatController.java b/socket/src/main/java/Backend/socket/api/chat/controller/ChatController.java similarity index 79% rename from socket/src/main/java/Backend/socket/domain/chat/application/controller/ChatController.java rename to socket/src/main/java/Backend/socket/api/chat/controller/ChatController.java index b19c710..fe664dd 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/ChatController.java +++ b/socket/src/main/java/Backend/socket/api/chat/controller/ChatController.java @@ -1,28 +1,16 @@ -package Backend.socket.domain.chat.application.controller; +package Backend.socket.api.chat.controller; -import Backend.socket.domain.chat.application.controller.dto.request.ChatListRequestDto; -import Backend.socket.domain.chat.application.controller.dto.request.ChatMessageListRequestDto; -import Backend.socket.domain.chat.application.controller.dto.request.ChatMessageRequestDto; -import Backend.socket.domain.chat.application.controller.dto.request.ChatMessageRoomRequestDto; -import Backend.socket.domain.chat.application.controller.dto.response.ChatListResponseDto; -import Backend.socket.domain.chat.application.controller.dto.response.ChatMessageListResponseDto; -import Backend.socket.domain.chat.application.controller.dto.response.ChatMessageResponseDto; -import Backend.socket.domain.chat.application.controller.dto.response.ChatMessageRoomResponseDto; -import Backend.socket.domain.chat.application.service.ChatService; +import Backend.socket.api.chat.service.dto.request.ChatMessageRoomRequestDto; +import Backend.socket.api.chat.service.ChatService; import Backend.socket.global.common.MessageSuccessCode; import Backend.socket.global.common.MessageSuccessResponse; -import Backend.socket.global.common.image; -import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.messaging.handler.annotation.DestinationVariable; -import org.springframework.messaging.handler.annotation.Header; import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.messaging.simp.SimpMessagingTemplate; -import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/service/ChatService.java b/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java similarity index 95% rename from socket/src/main/java/Backend/socket/domain/chat/application/service/ChatService.java rename to socket/src/main/java/Backend/socket/api/chat/service/ChatService.java index 7f16eb1..a7ad9ce 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/service/ChatService.java +++ b/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java @@ -1,16 +1,12 @@ -package Backend.socket.domain.chat.application.service; +package Backend.socket.api.chat.service; -import Backend.socket.domain.chat.application.controller.dto.request.ChatListRequestDto; -import Backend.socket.domain.chat.application.controller.dto.request.ChatMessageListRequestDto; -import Backend.socket.domain.chat.application.controller.dto.request.ChatMessageRequestDto; - -import Backend.socket.domain.chat.application.controller.dto.request.ChatMessageRoomRequestDto; +import Backend.socket.api.chat.service.dto.request.ChatMessageRoomRequestDto; +import Backend.socket.api.chat.service.dto.response.ChatMessageRoomResponseDto; import Backend.socket.domain.chat.application.controller.dto.response.*; import Backend.socket.domain.chat.domain.*; import Backend.socket.domain.chat.repository.ChatRepository; import Backend.socket.domain.chat.repository.RoomRepository; import Backend.socket.domain.chat.repository.UserRepository; -import Backend.socket.global.common.image; import Backend.socket.global.error.socketException.EntityNotFoundException; import Backend.socket.infra.external.AwsService; //import Backend.socket.infra.external.fcm.service.PushNotificationService; @@ -23,7 +19,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/ChatMessageRoomRequestDto.java b/socket/src/main/java/Backend/socket/api/chat/service/dto/request/ChatMessageRoomRequestDto.java similarity index 85% rename from socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/ChatMessageRoomRequestDto.java rename to socket/src/main/java/Backend/socket/api/chat/service/dto/request/ChatMessageRoomRequestDto.java index 92159a4..34cb81b 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/ChatMessageRoomRequestDto.java +++ b/socket/src/main/java/Backend/socket/api/chat/service/dto/request/ChatMessageRoomRequestDto.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.application.controller.dto.request; +package Backend.socket.api.chat.service.dto.request; import lombok.AccessLevel; import lombok.Getter; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageRoomResponseDto.java b/socket/src/main/java/Backend/socket/api/chat/service/dto/response/ChatMessageRoomResponseDto.java similarity index 78% rename from socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageRoomResponseDto.java rename to socket/src/main/java/Backend/socket/api/chat/service/dto/response/ChatMessageRoomResponseDto.java index 26ead2d..ac628e5 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageRoomResponseDto.java +++ b/socket/src/main/java/Backend/socket/api/chat/service/dto/response/ChatMessageRoomResponseDto.java @@ -1,5 +1,6 @@ -package Backend.socket.domain.chat.application.controller.dto.response; +package Backend.socket.api.chat.service.dto.response; +import Backend.socket.domain.chat.application.controller.dto.response.ChatMessageElementResponseDto; import lombok.Builder; import lombok.Getter; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/RoomController.java b/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java similarity index 81% rename from socket/src/main/java/Backend/socket/domain/chat/application/controller/RoomController.java rename to socket/src/main/java/Backend/socket/api/room/controller/RoomController.java index a27d3a5..3395846 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/RoomController.java +++ b/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java @@ -1,20 +1,14 @@ -package Backend.socket.domain.chat.application.controller; +package Backend.socket.api.room.controller; -import Backend.socket.domain.chat.application.controller.dto.request.ChatListRequestDto; -import Backend.socket.domain.chat.application.controller.dto.request.ChatMessageListRequestDto; -import Backend.socket.domain.chat.application.controller.dto.request.ChatMessageRoomRequestDto; +import Backend.socket.api.chat.service.dto.request.ChatMessageRoomRequestDto; import Backend.socket.domain.chat.application.controller.dto.response.*; -import Backend.socket.domain.chat.application.service.ChatService; +import Backend.socket.api.chat.service.ChatService; import Backend.socket.domain.chat.application.service.RoomService; -import Backend.socket.domain.chat.domain.Chat; import Backend.socket.global.common.MessageSuccessCode; import Backend.socket.global.common.MessageSuccessResponse; -import Backend.socket.infra.config.auth.UserId; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.http.ResponseEntity; import org.springframework.messaging.handler.annotation.DestinationVariable; -import org.springframework.messaging.handler.annotation.Header; import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.web.bind.annotation.PathVariable; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/ChatListRequestDto.java b/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/ChatListRequestDto.java deleted file mode 100644 index 239df31..0000000 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/ChatListRequestDto.java +++ /dev/null @@ -1,11 +0,0 @@ -package Backend.socket.domain.chat.application.controller.dto.request; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Getter -public class ChatListRequestDto { - private String userName; -} diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/ChatMessageListRequestDto.java b/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/ChatMessageListRequestDto.java deleted file mode 100644 index d555d5c..0000000 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/ChatMessageListRequestDto.java +++ /dev/null @@ -1,13 +0,0 @@ -package Backend.socket.domain.chat.application.controller.dto.request; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Getter -public class ChatMessageListRequestDto { - private String chatSession; - private String fromUserName; - private String toUserName; -} diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/ChatMessageRequestDto.java b/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/ChatMessageRequestDto.java deleted file mode 100644 index 98a782e..0000000 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/ChatMessageRequestDto.java +++ /dev/null @@ -1,14 +0,0 @@ -package Backend.socket.domain.chat.application.controller.dto.request; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Getter -public class ChatMessageRequestDto { - private String chatSession; - private String fromUserName; - private String toUserName; - private String content; -} diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/RoomChatMessageListReq.java b/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/RoomChatMessageListReq.java deleted file mode 100644 index d1d5b21..0000000 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/RoomChatMessageListReq.java +++ /dev/null @@ -1,14 +0,0 @@ -package Backend.socket.domain.chat.application.controller.dto.request; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Getter -public class RoomChatMessageListReq { - private String roomSession; - private String fromUserName; - private String toRoomName; - -} diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/RoomMessageListRequestDto.java b/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/RoomMessageListRequestDto.java deleted file mode 100644 index f88b51b..0000000 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/request/RoomMessageListRequestDto.java +++ /dev/null @@ -1,13 +0,0 @@ -package Backend.socket.domain.chat.application.controller.dto.request; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Getter -public class RoomMessageListRequestDto { - private String chatSession; - private String fromUserName; - private String toRoomName; -} diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatListResponseDto.java b/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatListResponseDto.java deleted file mode 100644 index 4f690fa..0000000 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatListResponseDto.java +++ /dev/null @@ -1,18 +0,0 @@ -package Backend.socket.domain.chat.application.controller.dto.response; - -import lombok.Builder; -import lombok.Getter; - -import java.util.List; - -@Builder -@Getter -public class ChatListResponseDto { - private List chatList; - - public static ChatListResponseDto of(List chatList) { - return ChatListResponseDto.builder() - .chatList(chatList) - .build(); - } -} diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageResponseDto.java b/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageResponseDto.java deleted file mode 100644 index f3036ea..0000000 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageResponseDto.java +++ /dev/null @@ -1,22 +0,0 @@ -package Backend.socket.domain.chat.application.controller.dto.response; - -import lombok.Builder; -import lombok.Getter; - -import java.util.List; - -@Builder -@Getter -public class ChatMessageResponseDto { - private String receivedUser; - private List sessionList; - private ChatMessageElementResponseDto message; - - public static ChatMessageResponseDto of(String receivedUser, List sessionList, ChatMessageElementResponseDto message) { - return ChatMessageResponseDto.builder() - .receivedUser(receivedUser) - .sessionList(sessionList) - .message(message) - .build(); - } -} diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/SendMessageResponseDto.java b/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/SendMessageResponseDto.java deleted file mode 100644 index cc9c667..0000000 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/SendMessageResponseDto.java +++ /dev/null @@ -1,18 +0,0 @@ -package Backend.socket.domain.chat.application.controller.dto.response; - -import lombok.Builder; -import lombok.Getter; - -@Builder -@Getter -public class SendMessageResponseDto { - private String receivedUser; - private ChatMessageElementResponseDto message; - - public static SendMessageResponseDto of(String receivedUser, ChatMessageElementResponseDto message) { - return SendMessageResponseDto.builder() - .receivedUser(receivedUser) - .message(message) - .build(); - } -} \ No newline at end of file diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/UserChatResponseDto.java b/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/UserChatResponseDto.java deleted file mode 100644 index ef2dfaa..0000000 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/UserChatResponseDto.java +++ /dev/null @@ -1,27 +0,0 @@ -package Backend.socket.domain.chat.application.controller.dto.response; - -import Backend.socket.domain.chat.domain.ChatUser; -import lombok.Builder; -import lombok.Getter; - -import java.time.LocalDateTime; - -@Builder -@Getter -public class UserChatResponseDto { - private String sessionId; - private String profile; - private String userName; - private String content; - private String time; - - public static UserChatResponseDto of(ChatUser user, String content, LocalDateTime time) { - return UserChatResponseDto.builder() - .sessionId(user.getSessionId()) - .profile(user.getProfile()) - .userName(user.getName()) - .content(content) - .time(time.toString()) - .build(); - } -} \ No newline at end of file diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/service/RedisSubscriber.java b/socket/src/main/java/Backend/socket/domain/chat/application/service/RedisSubscriber.java index 61ef887..64571b1 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/service/RedisSubscriber.java +++ b/socket/src/main/java/Backend/socket/domain/chat/application/service/RedisSubscriber.java @@ -2,12 +2,11 @@ import Backend.socket.domain.chat.application.controller.dto.response.ChatMessageElementResponseDto; import Backend.socket.domain.chat.application.controller.dto.response.ChatMessageResponseDto; -import Backend.socket.domain.chat.application.controller.dto.response.ChatMessageRoomResponseDto; +import Backend.socket.api.chat.service.dto.response.ChatMessageRoomResponseDto; import Backend.socket.domain.chat.application.controller.dto.response.SendMessageResponseDto; import Backend.socket.global.common.MessageSuccessCode; import Backend.socket.global.common.MessageSuccessResponse; import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.redis.connection.Message; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/service/RoomService.java b/socket/src/main/java/Backend/socket/domain/chat/application/service/RoomService.java index 02f0ce4..53cde9d 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/service/RoomService.java +++ b/socket/src/main/java/Backend/socket/domain/chat/application/service/RoomService.java @@ -1,14 +1,10 @@ package Backend.socket.domain.chat.application.service; -import Backend.socket.domain.chat.application.controller.dto.request.ChatMessageListRequestDto; import Backend.socket.domain.chat.application.controller.dto.response.*; -import Backend.socket.domain.chat.domain.Chat; import Backend.socket.domain.chat.domain.ChatContent; import Backend.socket.domain.chat.domain.ChatUser; import Backend.socket.domain.chat.domain.Room; -import Backend.socket.domain.chat.repository.ChatRepository; import Backend.socket.domain.chat.repository.RoomRepository; -import Backend.socket.domain.chat.repository.UserRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.data.mongodb.core.MongoTemplate; From 792cd19e8d29521222bb2ce1a7e70f089cb2afff Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Thu, 23 May 2024 20:09:49 +0900 Subject: [PATCH 02/12] =?UTF-8?q?[refactor]:Socket=20Chat=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EA=B4=80=EB=A0=A8=20api=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Backend/socket/api/chat/service/ChatService.java | 2 +- .../dto/response/ChatMessageElementResponseDto.java | 7 +------ .../service/dto/response/ChatMessageRoomResponseDto.java | 1 - .../dto/response/ChatMessageListResponseDto.java | 1 + .../domain/chat/application/service/RedisSubscriber.java | 2 +- .../external/fcm/service/PushNotificationService.java | 2 +- 6 files changed, 5 insertions(+), 10 deletions(-) rename socket/src/main/java/Backend/socket/{domain/chat/application/controller => api/chat/service}/dto/response/ChatMessageElementResponseDto.java (83%) diff --git a/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java b/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java index a7ad9ce..644276c 100644 --- a/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java +++ b/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java @@ -1,8 +1,8 @@ package Backend.socket.api.chat.service; import Backend.socket.api.chat.service.dto.request.ChatMessageRoomRequestDto; +import Backend.socket.api.chat.service.dto.response.ChatMessageElementResponseDto; import Backend.socket.api.chat.service.dto.response.ChatMessageRoomResponseDto; -import Backend.socket.domain.chat.application.controller.dto.response.*; import Backend.socket.domain.chat.domain.*; import Backend.socket.domain.chat.repository.ChatRepository; import Backend.socket.domain.chat.repository.RoomRepository; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageElementResponseDto.java b/socket/src/main/java/Backend/socket/api/chat/service/dto/response/ChatMessageElementResponseDto.java similarity index 83% rename from socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageElementResponseDto.java rename to socket/src/main/java/Backend/socket/api/chat/service/dto/response/ChatMessageElementResponseDto.java index 18c3336..8d16e5b 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageElementResponseDto.java +++ b/socket/src/main/java/Backend/socket/api/chat/service/dto/response/ChatMessageElementResponseDto.java @@ -1,14 +1,9 @@ -package Backend.socket.domain.chat.application.controller.dto.response; +package Backend.socket.api.chat.service.dto.response; -import Backend.socket.domain.chat.application.service.TriFunction; import Backend.socket.domain.chat.domain.ChatContent; -import Backend.socket.domain.chat.domain.ChatUser; import lombok.Builder; import lombok.Getter; -import java.util.List; -import java.util.stream.Collectors; - @Builder @Getter public class ChatMessageElementResponseDto { diff --git a/socket/src/main/java/Backend/socket/api/chat/service/dto/response/ChatMessageRoomResponseDto.java b/socket/src/main/java/Backend/socket/api/chat/service/dto/response/ChatMessageRoomResponseDto.java index ac628e5..9caeaa1 100644 --- a/socket/src/main/java/Backend/socket/api/chat/service/dto/response/ChatMessageRoomResponseDto.java +++ b/socket/src/main/java/Backend/socket/api/chat/service/dto/response/ChatMessageRoomResponseDto.java @@ -1,6 +1,5 @@ package Backend.socket.api.chat.service.dto.response; -import Backend.socket.domain.chat.application.controller.dto.response.ChatMessageElementResponseDto; import lombok.Builder; import lombok.Getter; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageListResponseDto.java b/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageListResponseDto.java index 8b5939b..025b771 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageListResponseDto.java +++ b/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageListResponseDto.java @@ -1,5 +1,6 @@ package Backend.socket.domain.chat.application.controller.dto.response; +import Backend.socket.api.chat.service.dto.response.ChatMessageElementResponseDto; import lombok.Builder; import lombok.Getter; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/service/RedisSubscriber.java b/socket/src/main/java/Backend/socket/domain/chat/application/service/RedisSubscriber.java index 64571b1..220854f 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/service/RedisSubscriber.java +++ b/socket/src/main/java/Backend/socket/domain/chat/application/service/RedisSubscriber.java @@ -1,6 +1,6 @@ package Backend.socket.domain.chat.application.service; -import Backend.socket.domain.chat.application.controller.dto.response.ChatMessageElementResponseDto; +import Backend.socket.api.chat.service.dto.response.ChatMessageElementResponseDto; import Backend.socket.domain.chat.application.controller.dto.response.ChatMessageResponseDto; import Backend.socket.api.chat.service.dto.response.ChatMessageRoomResponseDto; import Backend.socket.domain.chat.application.controller.dto.response.SendMessageResponseDto; diff --git a/socket/src/main/java/Backend/socket/infra/external/fcm/service/PushNotificationService.java b/socket/src/main/java/Backend/socket/infra/external/fcm/service/PushNotificationService.java index 0baf648..b23c69d 100644 --- a/socket/src/main/java/Backend/socket/infra/external/fcm/service/PushNotificationService.java +++ b/socket/src/main/java/Backend/socket/infra/external/fcm/service/PushNotificationService.java @@ -1,6 +1,6 @@ //package Backend.socket.infra.external.fcm.service; // -//import Backend.socket.domain.chat.application.controller.dto.response.ChatMessageElementResponseDto; +//import Backend.socket.api.chat.service.dto.response.ChatMessageElementResponseDto; //import Backend.socket.domain.chat.domain.Room; //import Backend.socket.domain.chat.domain.User; //import Backend.socket.domain.chat.domain.notification.entity.NotificationHistory; From bad4c7baace285b8c450f222e84d27e66dc533fd Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Thu, 23 May 2024 20:13:19 +0900 Subject: [PATCH 03/12] =?UTF-8?q?[del]:Socket=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../socket/api/chat/service/ChatService.java | 130 +----------------- 1 file changed, 2 insertions(+), 128 deletions(-) diff --git a/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java b/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java index 644276c..e389a3c 100644 --- a/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java +++ b/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java @@ -4,12 +4,9 @@ import Backend.socket.api.chat.service.dto.response.ChatMessageElementResponseDto; import Backend.socket.api.chat.service.dto.response.ChatMessageRoomResponseDto; import Backend.socket.domain.chat.domain.*; -import Backend.socket.domain.chat.repository.ChatRepository; import Backend.socket.domain.chat.repository.RoomRepository; import Backend.socket.domain.chat.repository.UserRepository; import Backend.socket.global.error.socketException.EntityNotFoundException; -import Backend.socket.infra.external.AwsService; -//import Backend.socket.infra.external.fcm.service.PushNotificationService; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.data.mongodb.core.MongoTemplate; @@ -17,11 +14,9 @@ import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; import static Backend.socket.domain.chat.domain.ChatContent.createChatContent; import static Backend.socket.global.error.ErrorCode.USER_NOT_FOUND; @@ -32,38 +27,15 @@ @Service public class ChatService { private final MongoTemplate mongoTemplate; - private final ChatRepository chatRepository; private final UserRepository userRepository; private final RoomRepository roomRepository; - private final AwsService awsService; -// private final PushNotificationService pushNotificationService; - -// public ChatMessageResponseDto createSendMessageContent(String sessionId, ChatMessageRequestDto chatMessageRequestDto) { -// Chat chat = getChatBySessions(sessionId, chatMessageRequestDto.getChatSession()); -// User user = userRepository.findBySessionId(chatMessageRequestDto.getChatSession()).orElseThrow(); -// ChatContent chatContent = createChatContent(chatMessageRequestDto.getFromUserName(), chatMessageRequestDto.getContent(), chat); -// ChatMessageElementResponseDto chatMessage = ChatMessageElementResponseDto.of(chatContent, chatMessageRequestDto.getChatSession(), user.getProfile()); -// List sessionIdList = getSessionIdList(sessionId, chatMessageRequestDto.getChatSession()); -// saveChat(chat); -// return ChatMessageResponseDto.of(chatMessageRequestDto.getToUserName(), sessionIdList, chatMessage); -// } - public ChatMessageRoomResponseDto createSendMessageContentInRoom(String roomName, ChatMessageRoomRequestDto chatMessageRoomRequestDto) throws IOException { -// StringBuilder imageBuilder = new StringBuilder(); -// for (String imagePart : chatMessageRoomRequestDto.getImage()) { -// imageBuilder.append(imagePart); -// } -// String image = imageBuilder.toString(); -// String modifiedImageString = image.replaceAll("[\\[\\]]", "").replaceAll(",", " "); -// System.out.println("Modified byte array: " + modifiedImageString); + public ChatMessageRoomResponseDto createSendMessageContentInRoom(String roomName, ChatMessageRoomRequestDto chatMessageRoomRequestDto) { Room room = getChatBySessionsInRoom(roomName, chatMessageRoomRequestDto.getChatSession()); User user = userRepository.findBySessionId(chatMessageRoomRequestDto.getChatSession()).orElseThrow(); -// String images = awsService.uploadImageToS3(modifiedImageString); ChatContent chatContent = createChatContent(chatMessageRoomRequestDto.getFromUserName(), chatMessageRoomRequestDto.getContent(), room, chatMessageRoomRequestDto.getImage()); - ChatMessageElementResponseDto chatMessage = ChatMessageElementResponseDto.of(chatContent, chatMessageRoomRequestDto.getChatSession(), user.getProfile(), chatMessageRoomRequestDto.getImage(), validate(room.getOwnerSession(),chatMessageRoomRequestDto.getChatSession())); List sessionIdList = getSessionIdListInRoom(roomName, chatMessageRoomRequestDto.getChatSession()); saveChatRoom(room); -// pushNotificationService.sendChatMessageNotification(room, chatMessage, sessionIdList); //채팅 알림 return ChatMessageRoomResponseDto.of(chatMessageRoomRequestDto.getToRoomName(), sessionIdList, chatMessage); } private Boolean validate(String ownerSession, String sessionId){ @@ -71,43 +43,7 @@ private Boolean validate(String ownerSession, String sessionId){ return true; return false; } -// public ChatMessageRoomResponseDto createSendImageContentInRoom(String roomName, image chatMessageRoomRequestDto) throws IOException { -// // 대괄호 제거 및 공백으로 구분 -// String modifiedImageString = chatMessageRoomRequestDto.getImage().replaceAll("[\\[\\]]", "").replaceAll(",", " "); -// System.out.println("Modified byte array: " + modifiedImageString); -// -// String imageUrl = awsService.uploadImageToS3(modifiedImageString); -// String images = awsService.uploadImageToS3(imageUrl); -// Room room = getChatBySessionsInRoom(roomName, "113828093759900814627_ef4a27"); -// User user = userRepository.findBySessionId("113828093759900814627_ef4a27").orElseThrow(); -// ChatContent chatContent = createChatContent("양규리", images, room); -// ChatMessageElementResponseDto chatMessage = ChatMessageElementResponseDto.of(chatContent, "113828093759900814627_ef4a27", user.getProfile(), images); -// List sessionIdList = getSessionIdListInRoom(roomName, "113828093759900814627_ef4a27"); -// saveChatRoom(room); -// return ChatMessageRoomResponseDto.of("eksxhr", sessionIdList, chatMessage); -// } - -// public ChatMessageListResponseDto sendChatDetailMessage(String sessionId, ChatMessageListRequestDto chatMessageListRequestDto) { -// Chat chat = getChatBySessions(sessionId, chatMessageListRequestDto.getChatSession()); -// ChatUserResponseDto chatUserResponseDto = getChatUserResponseDto(chat, chatMessageListRequestDto.getFromUserName()); -// List chatMessageList = ChatMessageElementResponseDto.listOf(chat.getChatContentList(), chatMessageListRequestDto.getChatSession(), null); -// saveChat(chat); -// return ChatMessageListResponseDto.of(chatUserResponseDto, chatMessageList); -// } -// -// public ChatListResponseDto sendUserChatListMessage(String sessionId, ChatListRequestDto chatListRequestDto) { -// List chatList = findChatListBySession(sessionId); -// List userChatResponseDtoList = createUserChatResponseDto(chatList, chatListRequestDto.getUserName()); -// userChatResponseDtoList.sort(Comparator.comparing(UserChatResponseDto::getTime).reversed()); -// return ChatListResponseDto.of(userChatResponseDtoList); -// } - - private List getSessionIdList(String firstSessionId, String secondSessionId) { - List sessionList = new ArrayList<>(); - sessionList.add(firstSessionId); - sessionList.add(secondSessionId); - return sessionList; - } + private List getSessionIdListInRoom(String roomName, String sessionId) { List sessionList = new ArrayList<>(); @@ -124,49 +60,7 @@ private List getSessionIdListInRoom(String roomName, String sessionId) { return sessionList; } -// private ChatUserResponseDto getChatUserResponseDto(Chat chat, String name) { -// ChatUser chatUser = getChatUserReceivedUser(chat, name); -// return ChatUserResponseDto.of(chatUser); -// } - - private List createUserChatResponseDto(List chatList, String userName) { - List filterChat = getChatEmptyContentFilter(chatList); - return filterChat.stream() - .map(chat -> - UserChatResponseDto.of( - getChatUserReceivedUser(chat, userName), - getLastChatContent(chat.getChatContentList()).getContent(), - getLastChatContent(chat.getChatContentList()).getTime())) - .collect(Collectors.toList()); - } - - private List getChatEmptyContentFilter(List chatList) { - return chatList.stream() - .filter(chat -> (chat.getChatContentList().size() != 0)) - .collect(Collectors.toList()); - } - - private ChatUser getChatUserReceivedUser(Chat chat, String name) { - if (!Objects.equals(chat.getChatUserList().get(0).getName(), name)) - return chat.getChatUserList().get(0); - else - return chat.getChatUserList().get(1); - } - - private ChatContent getLastChatContent(List chatContentList) { - return chatContentList.get(chatContentList.size() - 1); - } - - private Chat getChatBySessions(String firstSessionId, String secondSessionId) { - Chat chat = findFirstChatBySessions(firstSessionId, secondSessionId); - if (Objects.isNull(chat)) { - ChatUser firstChatUser = createChatUser(firstSessionId); - ChatUser secondChatUser = createChatUser(secondSessionId); - return Chat.creatChat(firstChatUser, secondChatUser); - } else - return chat; - } private Room getChatBySessionsInRoom(String roomName, String sessionId) { Room room = findRoomChatByRoomName(roomName); if (Objects.isNull(room)) { @@ -203,38 +97,18 @@ private ChatUser createChatUser(String sessionId) { return ChatUser.createChatUser(user); } - private String getReceivedUserName(Chat chat, String user) { - if (!Objects.equals(chat.getChatUserList().get(0).getName(), user)) - return chat.getChatUserList().get(0).getName(); - else - return chat.getChatUserList().get(1).getName(); - } - - private Chat findFirstChatBySessions(String firstSessionId, String secondSessionId) { - Query query = new Query(); - query.addCriteria(Criteria.where("chatUserList.sessionId").all(firstSessionId, secondSessionId)); - return mongoTemplate.findOne(query, Chat.class); - } private Room findRoomChatByRoomName(String roomName) { Query query = new Query(); query.addCriteria(Criteria.where("roomName").is(roomName)); return mongoTemplate.findOne(query, Room.class); } - private List findChatListBySession(String sessionId) { - Query query = new Query(); - query.addCriteria(Criteria.where("chatUserList.sessionId").all(sessionId)); - return mongoTemplate.find(query, Chat.class); - } private User getUserFromSessionId(String sessionId) { return userRepository.findBySessionId(sessionId) .orElseThrow(() -> new EntityNotFoundException(USER_NOT_FOUND)); } - public void saveChat(Chat chat) { - chatRepository.save(chat); - } public void saveChatRoom(Room room) { roomRepository.save(room); } From 3fbae03c43ab6255d9352626e5f08f8b4ad1cf45 Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Thu, 23 May 2024 20:17:53 +0900 Subject: [PATCH 04/12] =?UTF-8?q?[refactor]:Socket=20response=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/room/controller/RoomController.java | 3 ++- .../response/ChatUserResponseDto.java | 2 +- .../response/RoomChatResponseDto.java | 3 +-- .../response/RoomListResponseDto.java | 2 +- .../RoomMessageElementResponseDto.java | 2 +- .../response/RoomMessageListResponseDto.java | 2 +- .../response/ChatMessageListResponseDto.java | 21 ------------------- .../chat/application/service/RoomService.java | 2 +- 8 files changed, 8 insertions(+), 29 deletions(-) rename socket/src/main/java/Backend/socket/{domain/chat/application/controller/dto => api/room/service}/response/ChatUserResponseDto.java (91%) rename socket/src/main/java/Backend/socket/{domain/chat/application/controller/dto => api/room/service}/response/RoomChatResponseDto.java (93%) rename socket/src/main/java/Backend/socket/{domain/chat/application/controller/dto => api/room/service}/response/RoomListResponseDto.java (86%) rename socket/src/main/java/Backend/socket/{domain/chat/application/controller/dto => api/room/service}/response/RoomMessageElementResponseDto.java (96%) rename socket/src/main/java/Backend/socket/{domain/chat/application/controller/dto => api/room/service}/response/RoomMessageListResponseDto.java (88%) delete mode 100644 socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageListResponseDto.java diff --git a/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java b/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java index 3395846..f0d5c8c 100644 --- a/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java +++ b/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java @@ -1,7 +1,8 @@ package Backend.socket.api.room.controller; import Backend.socket.api.chat.service.dto.request.ChatMessageRoomRequestDto; -import Backend.socket.domain.chat.application.controller.dto.response.*; +import Backend.socket.api.room.service.response.RoomListResponseDto; +import Backend.socket.api.room.service.response.RoomMessageListResponseDto; import Backend.socket.api.chat.service.ChatService; import Backend.socket.domain.chat.application.service.RoomService; import Backend.socket.global.common.MessageSuccessCode; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatUserResponseDto.java b/socket/src/main/java/Backend/socket/api/room/service/response/ChatUserResponseDto.java similarity index 91% rename from socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatUserResponseDto.java rename to socket/src/main/java/Backend/socket/api/room/service/response/ChatUserResponseDto.java index ce4a44e..8dfb120 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatUserResponseDto.java +++ b/socket/src/main/java/Backend/socket/api/room/service/response/ChatUserResponseDto.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.application.controller.dto.response; +package Backend.socket.api.room.service.response; import Backend.socket.domain.chat.domain.ChatUser; import lombok.Builder; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/RoomChatResponseDto.java b/socket/src/main/java/Backend/socket/api/room/service/response/RoomChatResponseDto.java similarity index 93% rename from socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/RoomChatResponseDto.java rename to socket/src/main/java/Backend/socket/api/room/service/response/RoomChatResponseDto.java index 13d806a..7b09b5c 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/RoomChatResponseDto.java +++ b/socket/src/main/java/Backend/socket/api/room/service/response/RoomChatResponseDto.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.application.controller.dto.response; +package Backend.socket.api.room.service.response; import Backend.socket.domain.chat.domain.Room; import lombok.Builder; @@ -6,7 +6,6 @@ import java.time.Duration; import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; @Builder @Getter diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/RoomListResponseDto.java b/socket/src/main/java/Backend/socket/api/room/service/response/RoomListResponseDto.java similarity index 86% rename from socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/RoomListResponseDto.java rename to socket/src/main/java/Backend/socket/api/room/service/response/RoomListResponseDto.java index 7fefb62..a99aafe 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/RoomListResponseDto.java +++ b/socket/src/main/java/Backend/socket/api/room/service/response/RoomListResponseDto.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.application.controller.dto.response; +package Backend.socket.api.room.service.response; import lombok.Builder; import lombok.Getter; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/RoomMessageElementResponseDto.java b/socket/src/main/java/Backend/socket/api/room/service/response/RoomMessageElementResponseDto.java similarity index 96% rename from socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/RoomMessageElementResponseDto.java rename to socket/src/main/java/Backend/socket/api/room/service/response/RoomMessageElementResponseDto.java index 3c29027..89cdc65 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/RoomMessageElementResponseDto.java +++ b/socket/src/main/java/Backend/socket/api/room/service/response/RoomMessageElementResponseDto.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.application.controller.dto.response; +package Backend.socket.api.room.service.response; import Backend.socket.domain.chat.application.service.TriFunction; import Backend.socket.domain.chat.domain.ChatContent; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/RoomMessageListResponseDto.java b/socket/src/main/java/Backend/socket/api/room/service/response/RoomMessageListResponseDto.java similarity index 88% rename from socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/RoomMessageListResponseDto.java rename to socket/src/main/java/Backend/socket/api/room/service/response/RoomMessageListResponseDto.java index e3c2615..ee540bf 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/RoomMessageListResponseDto.java +++ b/socket/src/main/java/Backend/socket/api/room/service/response/RoomMessageListResponseDto.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.application.controller.dto.response; +package Backend.socket.api.room.service.response; import lombok.Builder; import lombok.Getter; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageListResponseDto.java b/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageListResponseDto.java deleted file mode 100644 index 025b771..0000000 --- a/socket/src/main/java/Backend/socket/domain/chat/application/controller/dto/response/ChatMessageListResponseDto.java +++ /dev/null @@ -1,21 +0,0 @@ -package Backend.socket.domain.chat.application.controller.dto.response; - -import Backend.socket.api.chat.service.dto.response.ChatMessageElementResponseDto; -import lombok.Builder; -import lombok.Getter; - -import java.util.List; - -@Builder -@Getter -public class ChatMessageListResponseDto { - private ChatUserResponseDto user; - private List chatMessageList; - - public static ChatMessageListResponseDto of(ChatUserResponseDto chatUserResponseDto, List chatMessageList) { - return ChatMessageListResponseDto.builder() - .user(chatUserResponseDto) - .chatMessageList(chatMessageList) - .build(); - } -} diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/service/RoomService.java b/socket/src/main/java/Backend/socket/domain/chat/application/service/RoomService.java index 53cde9d..7b53eff 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/service/RoomService.java +++ b/socket/src/main/java/Backend/socket/domain/chat/application/service/RoomService.java @@ -1,6 +1,6 @@ package Backend.socket.domain.chat.application.service; -import Backend.socket.domain.chat.application.controller.dto.response.*; +import Backend.socket.api.room.service.response.*; import Backend.socket.domain.chat.domain.ChatContent; import Backend.socket.domain.chat.domain.ChatUser; import Backend.socket.domain.chat.domain.Room; From 242c4bed727f418e1c9c8b36b20e64c25f344dc8 Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Thu, 23 May 2024 20:19:45 +0900 Subject: [PATCH 05/12] =?UTF-8?q?[refactor]:Socket=20service=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Backend/socket/api/room/controller/RoomController.java | 2 +- .../chat/application => api/room}/service/RoomService.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) rename socket/src/main/java/Backend/socket/{domain/chat/application => api/room}/service/RoomService.java (97%) diff --git a/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java b/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java index f0d5c8c..9c7c2af 100644 --- a/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java +++ b/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java @@ -4,7 +4,7 @@ import Backend.socket.api.room.service.response.RoomListResponseDto; import Backend.socket.api.room.service.response.RoomMessageListResponseDto; import Backend.socket.api.chat.service.ChatService; -import Backend.socket.domain.chat.application.service.RoomService; +import Backend.socket.api.room.service.RoomService; import Backend.socket.global.common.MessageSuccessCode; import Backend.socket.global.common.MessageSuccessResponse; import org.springframework.beans.factory.annotation.Qualifier; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/service/RoomService.java b/socket/src/main/java/Backend/socket/api/room/service/RoomService.java similarity index 97% rename from socket/src/main/java/Backend/socket/domain/chat/application/service/RoomService.java rename to socket/src/main/java/Backend/socket/api/room/service/RoomService.java index 7b53eff..14f2d1a 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/service/RoomService.java +++ b/socket/src/main/java/Backend/socket/api/room/service/RoomService.java @@ -1,6 +1,7 @@ -package Backend.socket.domain.chat.application.service; +package Backend.socket.api.room.service; import Backend.socket.api.room.service.response.*; +import Backend.socket.domain.chat.application.service.Formatter; import Backend.socket.domain.chat.domain.ChatContent; import Backend.socket.domain.chat.domain.ChatUser; import Backend.socket.domain.chat.domain.Room; From bae889a308a19c2cba951e077b26c1c492c101c7 Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Thu, 23 May 2024 20:20:51 +0900 Subject: [PATCH 06/12] =?UTF-8?q?[del]:Socket=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/service/RedisSubscriber.java | 28 ++----------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/service/RedisSubscriber.java b/socket/src/main/java/Backend/socket/domain/chat/application/service/RedisSubscriber.java index 220854f..a1a4416 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/service/RedisSubscriber.java +++ b/socket/src/main/java/Backend/socket/domain/chat/application/service/RedisSubscriber.java @@ -1,9 +1,7 @@ package Backend.socket.domain.chat.application.service; import Backend.socket.api.chat.service.dto.response.ChatMessageElementResponseDto; -import Backend.socket.domain.chat.application.controller.dto.response.ChatMessageResponseDto; import Backend.socket.api.chat.service.dto.response.ChatMessageRoomResponseDto; -import Backend.socket.domain.chat.application.controller.dto.response.SendMessageResponseDto; import Backend.socket.global.common.MessageSuccessCode; import Backend.socket.global.common.MessageSuccessResponse; import com.fasterxml.jackson.databind.ObjectMapper; @@ -28,32 +26,15 @@ public RedisSubscriber(ObjectMapper objectMapper, @Qualifier("redisTemplate") Re this.redisTemplate = redisTemplate; this.messagingTemplate = messagingTemplate; } -// @Override -// public void onMessage(Message message, byte[] pattern) { -// String publishMessage = getPublishMessage(message); -// ChatMessageResponseDto messageResponseDto = getChatMessageFromObjectMapper(publishMessage); -// SendMessageResponseDto sendMessageResponseDto -// = SendMessageResponseDto.of(messageResponseDto.getReceivedUser(), messageResponseDto.getMessage()); -// messageResponseDto.getSessionList().forEach(sessionId -> sendChatMessage(sessionId, sendMessageResponseDto)); -// } + @Override public void onMessage(Message message, byte[] pattern) { String publishMessage = getPublishMessage(message); ChatMessageRoomResponseDto messageResponseDto = getChatMessageFromObjectMapper(publishMessage); -// SendMessageResponseDto sendMessageResponseDto -// = SendMessageResponseDto.of(messageResponseDto.getReceivedUser(), messageResponseDto.getMessage()); messageResponseDto.getSessionList().forEach(sessionId -> sendChatMessage(messageResponseDto.getRoom(), messageResponseDto.getMessage())); } -// private ChatMessageResponseDto getChatMessageFromObjectMapper(String publishMessage) { -// ChatMessageResponseDto messageResponseDto; -// try { -// messageResponseDto = objectMapper.readValue(publishMessage, ChatMessageResponseDto.class); -// } catch (Exception e) { -// throw new MessageDeliveryException("Error"); -// } -// return messageResponseDto; -// } + private ChatMessageRoomResponseDto getChatMessageFromObjectMapper(String publishMessage) { ChatMessageRoomResponseDto messageResponseDto; try { @@ -70,8 +51,5 @@ private void sendChatMessage(String roomName, ChatMessageElementResponseDto mess messagingTemplate.convertAndSend("/sub/room/" + roomName, MessageSuccessResponse.of(MessageSuccessCode.RECEIVED, message)); } -// private void sendChatMessage(String sessionId, SendMessageResponseDto publishMessage) { -// messagingTemplate.convertAndSend("/sub/chat/" + sessionId, -// MessageSuccessResponse.of(MessageSuccessCode.RECEIVED, publishMessage)); -// } + } From 52d78e2b4c0b058595dc1bfaccc207ef45069fc6 Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Thu, 23 May 2024 20:22:34 +0900 Subject: [PATCH 07/12] =?UTF-8?q?[refactor]:Socket=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Backend/socket/api/room/service/RoomService.java | 2 +- .../room/service/response/RoomMessageElementResponseDto.java | 2 +- .../domain/chat/{application => }/service/Formatter.java | 2 +- .../chat/{application => }/service/RedisSubscriber.java | 2 +- .../application/service => global/common}/TriFunction.java | 2 +- .../main/java/Backend/socket/infra/config/RedisConfig.java | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) rename socket/src/main/java/Backend/socket/domain/chat/{application => }/service/Formatter.java (95%) rename socket/src/main/java/Backend/socket/domain/chat/{application => }/service/RedisSubscriber.java (97%) rename socket/src/main/java/Backend/socket/{domain/chat/application/service => global/common}/TriFunction.java (60%) diff --git a/socket/src/main/java/Backend/socket/api/room/service/RoomService.java b/socket/src/main/java/Backend/socket/api/room/service/RoomService.java index 14f2d1a..c322637 100644 --- a/socket/src/main/java/Backend/socket/api/room/service/RoomService.java +++ b/socket/src/main/java/Backend/socket/api/room/service/RoomService.java @@ -1,7 +1,7 @@ package Backend.socket.api.room.service; import Backend.socket.api.room.service.response.*; -import Backend.socket.domain.chat.application.service.Formatter; +import Backend.socket.domain.chat.service.Formatter; import Backend.socket.domain.chat.domain.ChatContent; import Backend.socket.domain.chat.domain.ChatUser; import Backend.socket.domain.chat.domain.Room; diff --git a/socket/src/main/java/Backend/socket/api/room/service/response/RoomMessageElementResponseDto.java b/socket/src/main/java/Backend/socket/api/room/service/response/RoomMessageElementResponseDto.java index 89cdc65..00cd3e8 100644 --- a/socket/src/main/java/Backend/socket/api/room/service/response/RoomMessageElementResponseDto.java +++ b/socket/src/main/java/Backend/socket/api/room/service/response/RoomMessageElementResponseDto.java @@ -1,6 +1,6 @@ package Backend.socket.api.room.service.response; -import Backend.socket.domain.chat.application.service.TriFunction; +import Backend.socket.global.common.TriFunction; import Backend.socket.domain.chat.domain.ChatContent; import Backend.socket.domain.chat.domain.ChatUser; import lombok.Builder; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/service/Formatter.java b/socket/src/main/java/Backend/socket/domain/chat/service/Formatter.java similarity index 95% rename from socket/src/main/java/Backend/socket/domain/chat/application/service/Formatter.java rename to socket/src/main/java/Backend/socket/domain/chat/service/Formatter.java index 5e60dfb..002eec9 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/service/Formatter.java +++ b/socket/src/main/java/Backend/socket/domain/chat/service/Formatter.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.application.service; +package Backend.socket.domain.chat.service; import Backend.socket.domain.chat.domain.ChatUser; import Backend.socket.domain.chat.domain.Room; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/service/RedisSubscriber.java b/socket/src/main/java/Backend/socket/domain/chat/service/RedisSubscriber.java similarity index 97% rename from socket/src/main/java/Backend/socket/domain/chat/application/service/RedisSubscriber.java rename to socket/src/main/java/Backend/socket/domain/chat/service/RedisSubscriber.java index a1a4416..50c684a 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/service/RedisSubscriber.java +++ b/socket/src/main/java/Backend/socket/domain/chat/service/RedisSubscriber.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.application.service; +package Backend.socket.domain.chat.service; import Backend.socket.api.chat.service.dto.response.ChatMessageElementResponseDto; import Backend.socket.api.chat.service.dto.response.ChatMessageRoomResponseDto; diff --git a/socket/src/main/java/Backend/socket/domain/chat/application/service/TriFunction.java b/socket/src/main/java/Backend/socket/global/common/TriFunction.java similarity index 60% rename from socket/src/main/java/Backend/socket/domain/chat/application/service/TriFunction.java rename to socket/src/main/java/Backend/socket/global/common/TriFunction.java index db2964e..7af2ad0 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/application/service/TriFunction.java +++ b/socket/src/main/java/Backend/socket/global/common/TriFunction.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.application.service; +package Backend.socket.global.common; @FunctionalInterface public interface TriFunction { diff --git a/socket/src/main/java/Backend/socket/infra/config/RedisConfig.java b/socket/src/main/java/Backend/socket/infra/config/RedisConfig.java index f62b263..536e3e4 100644 --- a/socket/src/main/java/Backend/socket/infra/config/RedisConfig.java +++ b/socket/src/main/java/Backend/socket/infra/config/RedisConfig.java @@ -1,5 +1,5 @@ package Backend.socket.infra.config; -import Backend.socket.domain.chat.application.service.RedisSubscriber; +import Backend.socket.domain.chat.service.RedisSubscriber; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; @@ -42,7 +42,7 @@ public ChannelTopic channelTopic() { } } // -//import Backend.socket.domain.chat.application.service.RedisSubscriber; +//import Backend.socket.domain.chat.service.RedisSubscriber; //import org.springframework.beans.factory.annotation.Qualifier; //import org.springframework.beans.factory.annotation.Value; //import org.springframework.context.annotation.Bean; From 328a45e7821ed4556536fcc8488716898f042f8b Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Thu, 23 May 2024 20:31:03 +0900 Subject: [PATCH 08/12] =?UTF-8?q?[refactor]:Socket=20user=20domain=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../socket/api/chat/service/ChatService.java | 1 + .../socket/domain/chat/domain/Chat.java | 37 ------------------- .../domain/chat/domain/ChatContent.java | 18 ++++----- .../socket/domain/chat/domain/ChatUser.java | 1 + .../entity/NotificationHistory.java | 2 +- .../chat/repository/ChatRepository.java | 8 ---- .../chat/repository/UserRepository.java | 2 +- .../{chat/domain => user/entity}/Gender.java | 2 +- .../domain => user/entity}/Language.java | 2 +- .../domain => user/entity}/Platform.java | 2 +- .../domain => user/entity}/SyncType.java | 2 +- .../{chat/domain => user/entity}/User.java | 2 +- .../fcm/service/PushNotificationService.java | 2 +- 13 files changed, 19 insertions(+), 62 deletions(-) delete mode 100644 socket/src/main/java/Backend/socket/domain/chat/domain/Chat.java delete mode 100644 socket/src/main/java/Backend/socket/domain/chat/repository/ChatRepository.java rename socket/src/main/java/Backend/socket/domain/{chat/domain => user/entity}/Gender.java (83%) rename socket/src/main/java/Backend/socket/domain/{chat/domain => user/entity}/Language.java (82%) rename socket/src/main/java/Backend/socket/domain/{chat/domain => user/entity}/Platform.java (93%) rename socket/src/main/java/Backend/socket/domain/{chat/domain => user/entity}/SyncType.java (93%) rename socket/src/main/java/Backend/socket/domain/{chat/domain => user/entity}/User.java (95%) diff --git a/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java b/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java index e389a3c..9454d61 100644 --- a/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java +++ b/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java @@ -6,6 +6,7 @@ import Backend.socket.domain.chat.domain.*; import Backend.socket.domain.chat.repository.RoomRepository; import Backend.socket.domain.chat.repository.UserRepository; +import Backend.socket.domain.user.entity.User; import Backend.socket.global.error.socketException.EntityNotFoundException; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; diff --git a/socket/src/main/java/Backend/socket/domain/chat/domain/Chat.java b/socket/src/main/java/Backend/socket/domain/chat/domain/Chat.java deleted file mode 100644 index e8e3b99..0000000 --- a/socket/src/main/java/Backend/socket/domain/chat/domain/Chat.java +++ /dev/null @@ -1,37 +0,0 @@ -package Backend.socket.domain.chat.domain; - -import lombok.Builder; -import lombok.Getter; -import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.Document; - -import java.util.ArrayList; -import java.util.List; - -@Getter -@Builder -@Document(collection = "chat") -public class Chat { - @Id - private String chatId; - @Builder.Default - private List chatUserList = new ArrayList<>(); - @Builder.Default - private List chatContentList = new ArrayList<>(); - - public static Chat creatChat(ChatUser firstUser, ChatUser secondUser) { - Chat chat = Chat.builder().build(); - chat.addChatUser(firstUser); - chat.addChatUser(secondUser); - return chat; - } - - public void addChatContent(ChatContent content) { - this.chatContentList.add(content); - } - - public void addChatUser(ChatUser chatUser) { - this.chatUserList.add(chatUser); - } - -} diff --git a/socket/src/main/java/Backend/socket/domain/chat/domain/ChatContent.java b/socket/src/main/java/Backend/socket/domain/chat/domain/ChatContent.java index bb3e3fb..74fdf99 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/domain/ChatContent.java +++ b/socket/src/main/java/Backend/socket/domain/chat/domain/ChatContent.java @@ -13,15 +13,15 @@ public class ChatContent { private String image; private LocalDateTime time; - public static ChatContent createChatContent(String userName, String content,Chat chat) { - ChatContent chatContent = ChatContent.builder() - .userName(userName) - .content(content) - .time(LocalDateTime.now()) - .build(); - chat.addChatContent(chatContent); - return chatContent; - } +// public static ChatContent createChatContent(String userName, String content,Chat chat) { +// ChatContent chatContent = ChatContent.builder() +// .userName(userName) +// .content(content) +// .time(LocalDateTime.now()) +// .build(); +// chat.addChatContent(chatContent); +// return chatContent; +// } public static ChatContent createChatContent(String userName, String content, Room room,String image) { ChatContent chatContent = ChatContent.builder() .userName(userName) diff --git a/socket/src/main/java/Backend/socket/domain/chat/domain/ChatUser.java b/socket/src/main/java/Backend/socket/domain/chat/domain/ChatUser.java index 280b1ec..dba5d3d 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/domain/ChatUser.java +++ b/socket/src/main/java/Backend/socket/domain/chat/domain/ChatUser.java @@ -1,5 +1,6 @@ package Backend.socket.domain.chat.domain; +import Backend.socket.domain.user.entity.User; import lombok.Builder; import lombok.Getter; diff --git a/socket/src/main/java/Backend/socket/domain/chat/domain/notification/entity/NotificationHistory.java b/socket/src/main/java/Backend/socket/domain/chat/domain/notification/entity/NotificationHistory.java index 29f3526..d77bd93 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/domain/notification/entity/NotificationHistory.java +++ b/socket/src/main/java/Backend/socket/domain/chat/domain/notification/entity/NotificationHistory.java @@ -1,6 +1,6 @@ package Backend.socket.domain.chat.domain.notification.entity; -import Backend.socket.domain.chat.domain.User; +import Backend.socket.domain.user.entity.User; import jakarta.persistence.*; import lombok.*; diff --git a/socket/src/main/java/Backend/socket/domain/chat/repository/ChatRepository.java b/socket/src/main/java/Backend/socket/domain/chat/repository/ChatRepository.java deleted file mode 100644 index 45c4c41..0000000 --- a/socket/src/main/java/Backend/socket/domain/chat/repository/ChatRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package Backend.socket.domain.chat.repository; - - -import Backend.socket.domain.chat.domain.Chat; -import org.springframework.data.mongodb.repository.MongoRepository; - -public interface ChatRepository extends MongoRepository { -} diff --git a/socket/src/main/java/Backend/socket/domain/chat/repository/UserRepository.java b/socket/src/main/java/Backend/socket/domain/chat/repository/UserRepository.java index 47ad8d4..751e1fc 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/repository/UserRepository.java +++ b/socket/src/main/java/Backend/socket/domain/chat/repository/UserRepository.java @@ -1,6 +1,6 @@ package Backend.socket.domain.chat.repository; -import Backend.socket.domain.chat.domain.User; +import Backend.socket.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; diff --git a/socket/src/main/java/Backend/socket/domain/chat/domain/Gender.java b/socket/src/main/java/Backend/socket/domain/user/entity/Gender.java similarity index 83% rename from socket/src/main/java/Backend/socket/domain/chat/domain/Gender.java rename to socket/src/main/java/Backend/socket/domain/user/entity/Gender.java index d6717d8..46528d8 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/domain/Gender.java +++ b/socket/src/main/java/Backend/socket/domain/user/entity/Gender.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.domain; +package Backend.socket.domain.user.entity; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/socket/src/main/java/Backend/socket/domain/chat/domain/Language.java b/socket/src/main/java/Backend/socket/domain/user/entity/Language.java similarity index 82% rename from socket/src/main/java/Backend/socket/domain/chat/domain/Language.java rename to socket/src/main/java/Backend/socket/domain/user/entity/Language.java index 715ea22..35ec0c7 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/domain/Language.java +++ b/socket/src/main/java/Backend/socket/domain/user/entity/Language.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.domain; +package Backend.socket.domain.user.entity; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/socket/src/main/java/Backend/socket/domain/chat/domain/Platform.java b/socket/src/main/java/Backend/socket/domain/user/entity/Platform.java similarity index 93% rename from socket/src/main/java/Backend/socket/domain/chat/domain/Platform.java rename to socket/src/main/java/Backend/socket/domain/user/entity/Platform.java index b2a3826..86dfa44 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/domain/Platform.java +++ b/socket/src/main/java/Backend/socket/domain/user/entity/Platform.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.domain; +package Backend.socket.domain.user.entity; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/socket/src/main/java/Backend/socket/domain/chat/domain/SyncType.java b/socket/src/main/java/Backend/socket/domain/user/entity/SyncType.java similarity index 93% rename from socket/src/main/java/Backend/socket/domain/chat/domain/SyncType.java rename to socket/src/main/java/Backend/socket/domain/user/entity/SyncType.java index dc005f2..ff62f15 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/domain/SyncType.java +++ b/socket/src/main/java/Backend/socket/domain/user/entity/SyncType.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.domain; +package Backend.socket.domain.user.entity; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/socket/src/main/java/Backend/socket/domain/chat/domain/User.java b/socket/src/main/java/Backend/socket/domain/user/entity/User.java similarity index 95% rename from socket/src/main/java/Backend/socket/domain/chat/domain/User.java rename to socket/src/main/java/Backend/socket/domain/user/entity/User.java index e9fab53..c3d9904 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/domain/User.java +++ b/socket/src/main/java/Backend/socket/domain/user/entity/User.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.domain; +package Backend.socket.domain.user.entity; import Backend.socket.global.common.BaseEntity; diff --git a/socket/src/main/java/Backend/socket/infra/external/fcm/service/PushNotificationService.java b/socket/src/main/java/Backend/socket/infra/external/fcm/service/PushNotificationService.java index b23c69d..b1ef31b 100644 --- a/socket/src/main/java/Backend/socket/infra/external/fcm/service/PushNotificationService.java +++ b/socket/src/main/java/Backend/socket/infra/external/fcm/service/PushNotificationService.java @@ -2,7 +2,7 @@ // //import Backend.socket.api.chat.service.dto.response.ChatMessageElementResponseDto; //import Backend.socket.domain.chat.domain.Room; -//import Backend.socket.domain.chat.domain.User; +//import Backend.socket.domain.user.entity.User; //import Backend.socket.domain.chat.domain.notification.entity.NotificationHistory; //import Backend.socket.domain.chat.domain.notification.entity.NotificationType; //import Backend.socket.domain.chat.domain.notification.entity.TopCategory; From da3bd31bc56ffab71328e4639558803cfb6869c2 Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Thu, 23 May 2024 20:33:28 +0900 Subject: [PATCH 09/12] =?UTF-8?q?[refactor]:Socket=20notification=20domain?= =?UTF-8?q?=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Backend/socket/api/chat/service/ChatService.java | 2 +- .../repository/NotificationHistoryRepository.java | 12 ------------ .../notification/entity/NotificationHistory.java | 2 +- .../notification/entity/NotificationType.java | 2 +- .../domain => }/notification/entity/TopCategory.java | 2 +- .../repository/NotificationHistoryRepository.java | 9 +++++++++ .../{chat => user}/repository/UserRepository.java | 2 +- .../fcm/service/PushNotificationService.java | 2 +- 8 files changed, 15 insertions(+), 18 deletions(-) delete mode 100644 socket/src/main/java/Backend/socket/domain/chat/domain/notification/repository/NotificationHistoryRepository.java rename socket/src/main/java/Backend/socket/domain/{chat/domain => }/notification/entity/NotificationHistory.java (96%) rename socket/src/main/java/Backend/socket/domain/{chat/domain => }/notification/entity/NotificationType.java (63%) rename socket/src/main/java/Backend/socket/domain/{chat/domain => }/notification/entity/TopCategory.java (92%) create mode 100644 socket/src/main/java/Backend/socket/domain/notification/repository/NotificationHistoryRepository.java rename socket/src/main/java/Backend/socket/domain/{chat => user}/repository/UserRepository.java (84%) diff --git a/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java b/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java index 9454d61..77ca4a1 100644 --- a/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java +++ b/socket/src/main/java/Backend/socket/api/chat/service/ChatService.java @@ -5,7 +5,7 @@ import Backend.socket.api.chat.service.dto.response.ChatMessageRoomResponseDto; import Backend.socket.domain.chat.domain.*; import Backend.socket.domain.chat.repository.RoomRepository; -import Backend.socket.domain.chat.repository.UserRepository; +import Backend.socket.domain.user.repository.UserRepository; import Backend.socket.domain.user.entity.User; import Backend.socket.global.error.socketException.EntityNotFoundException; import jakarta.transaction.Transactional; diff --git a/socket/src/main/java/Backend/socket/domain/chat/domain/notification/repository/NotificationHistoryRepository.java b/socket/src/main/java/Backend/socket/domain/chat/domain/notification/repository/NotificationHistoryRepository.java deleted file mode 100644 index dcae7bb..0000000 --- a/socket/src/main/java/Backend/socket/domain/chat/domain/notification/repository/NotificationHistoryRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package Backend.socket.domain.chat.domain.notification.repository; - -import Backend.socket.domain.chat.domain.notification.entity.NotificationHistory; -import Backend.socket.domain.chat.domain.notification.entity.TopCategory; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public interface NotificationHistoryRepository extends JpaRepository { -} diff --git a/socket/src/main/java/Backend/socket/domain/chat/domain/notification/entity/NotificationHistory.java b/socket/src/main/java/Backend/socket/domain/notification/entity/NotificationHistory.java similarity index 96% rename from socket/src/main/java/Backend/socket/domain/chat/domain/notification/entity/NotificationHistory.java rename to socket/src/main/java/Backend/socket/domain/notification/entity/NotificationHistory.java index d77bd93..b226c50 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/domain/notification/entity/NotificationHistory.java +++ b/socket/src/main/java/Backend/socket/domain/notification/entity/NotificationHistory.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.domain.notification.entity; +package Backend.socket.domain.notification.entity; import Backend.socket.domain.user.entity.User; import jakarta.persistence.*; diff --git a/socket/src/main/java/Backend/socket/domain/chat/domain/notification/entity/NotificationType.java b/socket/src/main/java/Backend/socket/domain/notification/entity/NotificationType.java similarity index 63% rename from socket/src/main/java/Backend/socket/domain/chat/domain/notification/entity/NotificationType.java rename to socket/src/main/java/Backend/socket/domain/notification/entity/NotificationType.java index a0951c3..9c8dd19 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/domain/notification/entity/NotificationType.java +++ b/socket/src/main/java/Backend/socket/domain/notification/entity/NotificationType.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.domain.notification.entity; +package Backend.socket.domain.notification.entity; public enum NotificationType { CHAT, diff --git a/socket/src/main/java/Backend/socket/domain/chat/domain/notification/entity/TopCategory.java b/socket/src/main/java/Backend/socket/domain/notification/entity/TopCategory.java similarity index 92% rename from socket/src/main/java/Backend/socket/domain/chat/domain/notification/entity/TopCategory.java rename to socket/src/main/java/Backend/socket/domain/notification/entity/TopCategory.java index 30643ea..fa97ffc 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/domain/notification/entity/TopCategory.java +++ b/socket/src/main/java/Backend/socket/domain/notification/entity/TopCategory.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.domain.notification.entity; +package Backend.socket.domain.notification.entity; import Backend.socket.global.error.httpException.InvalidValueException; import lombok.Getter; diff --git a/socket/src/main/java/Backend/socket/domain/notification/repository/NotificationHistoryRepository.java b/socket/src/main/java/Backend/socket/domain/notification/repository/NotificationHistoryRepository.java new file mode 100644 index 0000000..bbbfc90 --- /dev/null +++ b/socket/src/main/java/Backend/socket/domain/notification/repository/NotificationHistoryRepository.java @@ -0,0 +1,9 @@ +package Backend.socket.domain.notification.repository; + +import Backend.socket.domain.notification.entity.NotificationHistory; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface NotificationHistoryRepository extends JpaRepository { +} diff --git a/socket/src/main/java/Backend/socket/domain/chat/repository/UserRepository.java b/socket/src/main/java/Backend/socket/domain/user/repository/UserRepository.java similarity index 84% rename from socket/src/main/java/Backend/socket/domain/chat/repository/UserRepository.java rename to socket/src/main/java/Backend/socket/domain/user/repository/UserRepository.java index 751e1fc..54b8177 100644 --- a/socket/src/main/java/Backend/socket/domain/chat/repository/UserRepository.java +++ b/socket/src/main/java/Backend/socket/domain/user/repository/UserRepository.java @@ -1,4 +1,4 @@ -package Backend.socket.domain.chat.repository; +package Backend.socket.domain.user.repository; import Backend.socket.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/socket/src/main/java/Backend/socket/infra/external/fcm/service/PushNotificationService.java b/socket/src/main/java/Backend/socket/infra/external/fcm/service/PushNotificationService.java index b1ef31b..738d36a 100644 --- a/socket/src/main/java/Backend/socket/infra/external/fcm/service/PushNotificationService.java +++ b/socket/src/main/java/Backend/socket/infra/external/fcm/service/PushNotificationService.java @@ -8,7 +8,7 @@ //import Backend.socket.domain.chat.domain.notification.entity.TopCategory; //import Backend.socket.domain.chat.domain.notification.repository.NotificationHistoryRepository; //import Backend.socket.domain.chat.repository.RoomRepository; -//import Backend.socket.domain.chat.repository.UserRepository; +//import Backend.socket.domain.user.repository.UserRepository; //import Backend.socket.infra.external.fcm.MessageTemplate; //import Backend.socket.infra.external.fcm.repository.FCMTokenRepository; //import Backend.socket.infra.external.fcm.service.dto.NotificationDto; From 3ac801b787d872d398e1ccc51ff00114d5d924c9 Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Thu, 23 May 2024 20:34:54 +0900 Subject: [PATCH 10/12] =?UTF-8?q?[del]:Socket=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../socket/global/common/HealthCheck.java | 86 +------------------ .../Backend/socket/global/common/image.java | 11 --- .../socket/global/common/imageList.java | 4 - 3 files changed, 1 insertion(+), 100 deletions(-) delete mode 100644 socket/src/main/java/Backend/socket/global/common/image.java delete mode 100644 socket/src/main/java/Backend/socket/global/common/imageList.java diff --git a/socket/src/main/java/Backend/socket/global/common/HealthCheck.java b/socket/src/main/java/Backend/socket/global/common/HealthCheck.java index 1dfe859..e8d4cf6 100644 --- a/socket/src/main/java/Backend/socket/global/common/HealthCheck.java +++ b/socket/src/main/java/Backend/socket/global/common/HealthCheck.java @@ -1,100 +1,16 @@ package Backend.socket.global.common; -import Backend.socket.infra.external.AwsService; import lombok.RequiredArgsConstructor; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Base64; -import java.util.List; -import java.util.Base64; @RestController @RequiredArgsConstructor @RequestMapping public class HealthCheck { - private final AwsService awsService; + @GetMapping("/") public String MeetUpServer() { return "test"; } - @GetMapping("/image") - public String uploadImage(@RequestParam(name = "image") String image) throws IOException { - String[] strings = image.split(" "); // ","을 기준으로 바이트 코드를 나눠준다 - String base64Image = strings[1]; - String extension = ""; // if 문을 통해 확장자명을 정해줌 - if (strings[0].equals("data:image/jpeg;base64")) { - extension = "jpeg"; - } else if (strings[0].equals("data:image/png;base64")){ - extension = "png"; - } else { - extension = "jpg"; - } - - -// ... - - byte[] imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64Image); // 바이트 코드를 // 바이트 코드를 - - File tempFile = File.createTempFile("image", "." + extension); // createTempFile을 통해 임시 파일을 생성해준다. (임시파일은 지워줘야함) - try (OutputStream outputStream = new FileOutputStream(tempFile)) { - outputStream.write(imageBytes); // OutputStream outputStream = new FileOutputStream(tempFile)을 통해 생성한 outputStream 객체에 imageBytes를 작성해준다. - } - // 문자열을 공백을 기준으로 분리하여 문자열 배열로 변환 - String[] byteStrings = image.split(" "); - // byte 배열 생성 - byte[] imageData = new byte[byteStrings.length]; - - for (int i = 0; i < byteStrings.length; i++) { - if (byteStrings[i].matches("-?[0-9]+")) { - imageData[i] = Byte.parseByte(byteStrings[i]); - } else if (byteStrings[i].matches("-?0x[0-9a-fA-F]+")) { - imageData[i] = (byte) Integer.parseInt(byteStrings[i].substring(2), 16); - } else { - // 잘못된 형식의 문자열인 경우 처리할 작업 - imageData[i] = 0; - } - } - - // 변환된 byte 배열을 사용하여 이미지 업로드 -// String imageUrl = awsService.uploadImageToS3(imageBytes); - return null; - } - @PostMapping("/images") - public List uploadImages(@RequestBody List imageDataList) { - List imageUrls = awsService.uploadImages(imageDataList); - return imageUrls; - } - - @PostMapping("/test") - public String uploadImagea(@RequestBody String image) throws IOException { - int size = image.length(); - // 대괄호 제거 및 공백으로 구분 - String modifiedImageString = image.replaceAll("[\\[\\]]", "").replaceAll(",", " "); -// System.out.println("Modified byte array: " + modifiedImageString); - - String imageUrl = awsService.uploadImageToS3(modifiedImageString); - return imageUrl; - } - - @GetMapping("/image/byte") - public ResponseEntity uploadImage(@RequestBody byte[] image) throws IOException { - - // Base64 인코딩 - String base64EncodedString = Base64.getEncoder().encodeToString(image); - int encodedSize = base64EncodedString.length(); - System.out.println("Base64 Encoded String: " + base64EncodedString); - System.out.println("Encoded size: " + encodedSize + " bytes"); - - // AWS S3 업로드 - String imageUrl = awsService.uploadImageToS3(base64EncodedString); - - return ResponseEntity.ok(imageUrl); - } } diff --git a/socket/src/main/java/Backend/socket/global/common/image.java b/socket/src/main/java/Backend/socket/global/common/image.java deleted file mode 100644 index e239804..0000000 --- a/socket/src/main/java/Backend/socket/global/common/image.java +++ /dev/null @@ -1,11 +0,0 @@ -package Backend.socket.global.common; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Getter -public class image { - private String image; -} diff --git a/socket/src/main/java/Backend/socket/global/common/imageList.java b/socket/src/main/java/Backend/socket/global/common/imageList.java deleted file mode 100644 index cbecacd..0000000 --- a/socket/src/main/java/Backend/socket/global/common/imageList.java +++ /dev/null @@ -1,4 +0,0 @@ -package Backend.socket.global.common; - -public class imageList { -} From 6904ffe41f57a17d79bc9866d63b3a6e97411be1 Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Thu, 23 May 2024 20:55:28 +0900 Subject: [PATCH 11/12] =?UTF-8?q?[refactor]:Socket=20sercurity=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../socket/infra/config/RedisConfig.java | 110 +----------------- .../config/auth/JwtAuthenticationFilter.java | 46 +------- .../infra/config/auth/SecurityConfig.java | 43 +++---- 3 files changed, 19 insertions(+), 180 deletions(-) diff --git a/socket/src/main/java/Backend/socket/infra/config/RedisConfig.java b/socket/src/main/java/Backend/socket/infra/config/RedisConfig.java index 536e3e4..6a70eb0 100644 --- a/socket/src/main/java/Backend/socket/infra/config/RedisConfig.java +++ b/socket/src/main/java/Backend/socket/infra/config/RedisConfig.java @@ -40,112 +40,4 @@ public RedisTemplate redisTemplate(RedisConnectionFactory connec public ChannelTopic channelTopic() { return new ChannelTopic("meetingRoom"); } -} -// -//import Backend.socket.domain.chat.service.RedisSubscriber; -//import org.springframework.beans.factory.annotation.Qualifier; -//import org.springframework.beans.factory.annotation.Value; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -//import org.springframework.data.redis.connection.RedisConnectionFactory; -//import org.springframework.data.redis.connection.RedisStandaloneConfiguration; -//import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; -//import org.springframework.data.redis.core.RedisTemplate; -//import org.springframework.data.redis.core.StringRedisTemplate; -//import org.springframework.data.redis.listener.ChannelTopic; -//import org.springframework.data.redis.listener.RedisMessageListenerContainer; -//import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; -//import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; -//import org.springframework.data.redis.serializer.StringRedisSerializer; -// -//@Configuration -//public class RedisConfig { -// @Value("${spring.redis.chat.host}") -// private String chatRedisHost; -// -// @Value("${spring.redis.chat.port}") -// private int chatRedisPort; -// -// @Value("${spring.redis.chat.password}") -// private String chatRedisPassword; -// -// @Value("${spring.redis.fcm.host}") -// private String fcmRedisHost; -// -// @Value("${spring.redis.fcm.port}") -// private int fcmRedisPort; -// -// @Value("${spring.redis.fcm.password}") -// private String fcmRedisPassword; -// -// @Bean -// public RedisTemplate redisTemplate(@Qualifier("chatRedisConnectionFactory") RedisConnectionFactory connectionFactory) { -// RedisTemplate template = new RedisTemplate<>(); -// template.setConnectionFactory(connectionFactory); -// return template; -// } -// @Bean -// public StringRedisTemplate stringRedisTemplate() { -// return new StringRedisTemplate(fcmRedisConnectionFactory()); -// } -// @Bean -// @Qualifier("chatRedisConnectionFactory") -// public RedisConnectionFactory chatRedisConnectionFactory() { -// RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(); -// config.setHostName(chatRedisHost); -// config.setPort(chatRedisPort); -// config.setPassword(chatRedisPassword); -// return new LettuceConnectionFactory(config); -// } -// -// @Bean -// @Qualifier("fcmRedisConnectionFactory") -// public RedisConnectionFactory fcmRedisConnectionFactory() { -// RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(); -// config.setHostName(fcmRedisHost); -// config.setPort(fcmRedisPort); -// config.setPassword(fcmRedisPassword); -// return new LettuceConnectionFactory(config); -// } -// -// @Bean -// public RedisMessageListenerContainer redisMessageListenerContainer( -// @Qualifier("chatRedisConnectionFactory") RedisConnectionFactory connectionFactory, -// MessageListenerAdapter listenerAdapter, -// ChannelTopic channelTopic) { -// RedisMessageListenerContainer container = new RedisMessageListenerContainer(); -// container.setConnectionFactory(connectionFactory); -// container.addMessageListener(listenerAdapter, channelTopic); -// return container; -// } -// -// @Bean -// public MessageListenerAdapter listenerAdapter(RedisSubscriber subscriber) { -// return new MessageListenerAdapter(subscriber, "onMessage"); -// } -// -// @Bean -// public RedisTemplate chatRedisTemplate( -// @Qualifier("chatRedisConnectionFactory") RedisConnectionFactory connectionFactory) { -// RedisTemplate redisTemplate = new RedisTemplate<>(); -// redisTemplate.setConnectionFactory(connectionFactory); -// redisTemplate.setKeySerializer(new StringRedisSerializer()); -// redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(String.class)); -// return redisTemplate; -// } -// -// @Bean -// public RedisTemplate fcmRedisTemplate( -// @Qualifier("fcmRedisConnectionFactory") RedisConnectionFactory connectionFactory) { -// RedisTemplate redisTemplate = new RedisTemplate<>(); -// redisTemplate.setConnectionFactory(connectionFactory); -// redisTemplate.setKeySerializer(new StringRedisSerializer()); -// redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(String.class)); -// return redisTemplate; -// } -// -// @Bean -// public ChannelTopic channelTopic() { -// return new ChannelTopic("meetingRoom"); -// } -//} \ No newline at end of file +} \ No newline at end of file diff --git a/socket/src/main/java/Backend/socket/infra/config/auth/JwtAuthenticationFilter.java b/socket/src/main/java/Backend/socket/infra/config/auth/JwtAuthenticationFilter.java index ea88c21..21fd824 100644 --- a/socket/src/main/java/Backend/socket/infra/config/auth/JwtAuthenticationFilter.java +++ b/socket/src/main/java/Backend/socket/infra/config/auth/JwtAuthenticationFilter.java @@ -24,52 +24,16 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { private static final String AUTHORIZATION = "Authorization"; private static final String BEARER = "Bearer "; private final JwtProvider jwtProvider; + @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { - - //url이 통과해도되는지 체크 (http 메서드와 함께 자료구조에 저장하여 검증) - String url = request.getRequestURI(); - String method = request.getMethod(); - - if(!IgnorePathConsts.isIgnorablePath(url, HttpMethod.valueOf(method))){ -// //위가 통과되면 토큰을 검출 -// String authorization = request.getHeader("Authorization"); -// -// /*//Authorization 헤더 검증 -// if (authorization == null || !authorization.startsWith("Bearer ")) { -// -// System.out.println("token null"); -// filterChain.doFilter(request, response); //doFilter를 통해 request와 response를 -// -// }*/ -// -// System.out.println("authorization now"); -// //Bearer 부분 제거 후 순수 토큰만 획득 -// String token = authorization.split(" ")[1]; -// -// //토큰이 유효한지 검증, 유효성 검증은 extract 메서드에서 처리 -// Long userId = jwtUtil.extractUserClaim(token).getUserId(); -// -// Authentication authToken = new JwtAuthentication(userId); -// -// //세션에 사용자 등록 -// SecurityContextHolder.getContext().setAuthentication(authToken); - } - - - + final String accessToken = getAccessTokenFromHttpServletRequest(request); + jwtProvider.validateAccessToken(accessToken); + final Long userId = jwtProvider.getSubject(accessToken); + setAuthentication(request, userId); filterChain.doFilter(request, response); } -// @Override -// protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { -// final String accessToken = getAccessTokenFromHttpServletRequest(request); -// jwtProvider.validateAccessToken(accessToken); -// final Long userId = jwtProvider.getSubject(accessToken); -// setAuthentication(request, userId); -// filterChain.doFilter(request, response); -// } - private String getAccessTokenFromHttpServletRequest(HttpServletRequest request) { String accessToken = request.getHeader(AUTHORIZATION); diff --git a/socket/src/main/java/Backend/socket/infra/config/auth/SecurityConfig.java b/socket/src/main/java/Backend/socket/infra/config/auth/SecurityConfig.java index f6d6bbd..18a37fe 100644 --- a/socket/src/main/java/Backend/socket/infra/config/auth/SecurityConfig.java +++ b/socket/src/main/java/Backend/socket/infra/config/auth/SecurityConfig.java @@ -28,38 +28,21 @@ public class SecurityConfig { // return web -> web.ignoring().requestMatchers(whiteList); // } -// @Bean -// public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { -// return http -// .formLogin(AbstractHttpConfigurer::disable) -// .httpBasic(AbstractHttpConfigurer::disable) -// .csrf(AbstractHttpConfigurer::disable) -// .sessionManagement(sessionManagementConfigurer -> -// sessionManagementConfigurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) -// .exceptionHandling(exceptionHandlingConfigurer -> -// exceptionHandlingConfigurer.authenticationEntryPoint(jwtAuthenticationEntryPoint)) -// .authorizeHttpRequests(authorizationManagerRequestMatcherRegistry -> -// authorizationManagerRequestMatcherRegistry.anyRequest().authenticated()) -// .addFilterBefore(new JwtAuthenticationFilter(jwtProvider), UsernamePasswordAuthenticationFilter.class) -// .addFilterBefore(new ExceptionHandlerFilter(), JwtAuthenticationFilter.class) -// .build(); -// } @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { - http.cors(AbstractHttpConfigurer::disable); - - http.csrf(AbstractHttpConfigurer::disable); - - http.authorizeHttpRequests(request ->{ - request.anyRequest().permitAll(); - }); - - http.formLogin(AbstractHttpConfigurer::disable); - http.httpBasic(AbstractHttpConfigurer::disable); - http.logout(AbstractHttpConfigurer::disable); - http.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)); - - return http.build(); + return http + .formLogin(AbstractHttpConfigurer::disable) + .httpBasic(AbstractHttpConfigurer::disable) + .csrf(AbstractHttpConfigurer::disable) + .sessionManagement(sessionManagementConfigurer -> + sessionManagementConfigurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) + .exceptionHandling(exceptionHandlingConfigurer -> + exceptionHandlingConfigurer.authenticationEntryPoint(jwtAuthenticationEntryPoint)) + .authorizeHttpRequests(authorizationManagerRequestMatcherRegistry -> + authorizationManagerRequestMatcherRegistry.requestMatchers("/ws/**").permitAll().anyRequest().authenticated()) + .addFilterBefore(new JwtAuthenticationFilter(jwtProvider), UsernamePasswordAuthenticationFilter.class) + .addFilterBefore(new ExceptionHandlerFilter(), JwtAuthenticationFilter.class) + .build(); } } From 67ffe3c51bb63454d14a10153a8c08df57cb0b0b Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Thu, 23 May 2024 21:20:37 +0900 Subject: [PATCH 12/12] =?UTF-8?q?[del]:Socket=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/chat/controller/ChatController.java | 38 +---- .../api/room/controller/RoomController.java | 1 - .../socket/infra/config/FCMConfig.java | 38 ----- .../socket/infra/config/WebConfig.java | 25 --- .../socket/infra/external/AwsService.java | 143 ------------------ 5 files changed, 1 insertion(+), 244 deletions(-) delete mode 100644 socket/src/main/java/Backend/socket/infra/config/FCMConfig.java delete mode 100644 socket/src/main/java/Backend/socket/infra/config/WebConfig.java delete mode 100644 socket/src/main/java/Backend/socket/infra/external/AwsService.java diff --git a/socket/src/main/java/Backend/socket/api/chat/controller/ChatController.java b/socket/src/main/java/Backend/socket/api/chat/controller/ChatController.java index fe664dd..5eae345 100644 --- a/socket/src/main/java/Backend/socket/api/chat/controller/ChatController.java +++ b/socket/src/main/java/Backend/socket/api/chat/controller/ChatController.java @@ -27,49 +27,13 @@ public ChatController(ChatService chatService, SimpMessagingTemplate template, this.template = template; this.redisTemplate = redisTemplate; } -// @MessageMapping("/chat/{sessionId}") -// public void sendChatMessage(@DestinationVariable("sessionId") final String sessionId, -// @RequestBody final ChatMessageRequestDto chatMessageRequestDto) { -// final ChatMessageResponseDto responseDto = chatService.createSendMessageContent(sessionId, chatMessageRequestDto); -// redisTemplate.convertAndSend("meetingRoom", responseDto); -// } + @MessageMapping("/room/{roomName}") @SendTo("/sub/room/{roomName}") public MessageSuccessResponse sendChatMessageInRoom(@DestinationVariable("roomName") final String roomName, @RequestBody final ChatMessageRoomRequestDto chatMessageRoomRequestDto) throws IOException { return MessageSuccessResponse.of(MessageSuccessCode.RECEIVED, chatService.createSendMessageContentInRoom(roomName, chatMessageRoomRequestDto).getMessage()); } -// @MessageMapping("/room/image/{roomName}") -// @SendTo("/sub/room/{roomName}") -// public MessageSuccessResponse sendImageMessageInRoom(@DestinationVariable("roomName") final String roomName, -// @RequestBody final ChatMessageRoomRequestDto chatMessageRoomRequestDto) throws IOException { -// return MessageSuccessResponse.of(MessageSuccessCode.RECEIVED, chatService.createSendMessageContentInRoom(roomName, chatMessageRoomRequestDto).getMessage()); -// } -// @MessageMapping("/room/image/{roomName}") -// @SendTo("/sub/room/{roomName}") -// public MessageSuccessResponse sendImageMessageInRoom(@DestinationVariable("roomName") final String roomName, -// @RequestBody final image image) throws IOException { -// return MessageSuccessResponse.of(MessageSuccessCode.RECEIVED, chatService.createSendImageContentInRoom(roomName, image).getMessage()); -// } -// @MessageMapping("/room/{roomName}") -// public void sendChatMessageInRoom(@DestinationVariable("roomName") final String roomName, -// @RequestBody final ChatMessageRoomRequestDto chatMessageRoomRequestDto) { -// final ChatMessageRoomResponseDto responseDto = chatService.createSendMessageContentInRoom(roomName, chatMessageRoomRequestDto); -// redisTemplate.convertAndSend("meetingRoom", responseDto); -// } -// @MessageMapping("/chat/detail/{sessionId}") -// public void sendChatDetailMessage(@DestinationVariable("sessionId") final String sessionId, -// @RequestBody final ChatMessageListRequestDto chatMessageListRequestDto) { -// final ChatMessageListResponseDto responseDto = chatService.sendChatDetailMessage(sessionId, chatMessageListRequestDto); -// template.convertAndSend("/sub/chat/" + sessionId, MessageSuccessResponse.of(MessageSuccessCode.MESSAGE, responseDto)); -// } -// -// @MessageMapping("/chat/all") -// public void sendUserChatListMessage(@Header("sessionId") final String sessionId, -// @RequestBody final ChatListRequestDto chatListRequestDto) { -// final ChatListResponseDto responseDto = chatService.sendUserChatListMessage(sessionId, chatListRequestDto); -// template.convertAndSend("/sub/chat/" + sessionId, MessageSuccessResponse.of(MessageSuccessCode.CHATLIST, responseDto)); -// } } diff --git a/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java b/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java index 9c7c2af..a7db8d1 100644 --- a/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java +++ b/socket/src/main/java/Backend/socket/api/room/controller/RoomController.java @@ -37,7 +37,6 @@ public void sendChatDetailMessage(@DestinationVariable("roomName") final String final RoomMessageListResponseDto responseDto = roomService.sendRoomDetailMessage(roomName); template.convertAndSend("/sub/room/" + roomName, MessageSuccessResponse.of(MessageSuccessCode.MESSAGE, responseDto)); } - // @MessageMapping("/room/all/{sessionId}") public void sendUserChatListMessage(@DestinationVariable("sessionId") final String sessionId) { final RoomListResponseDto responseDto = roomService.sendUserChatListMessage(sessionId); diff --git a/socket/src/main/java/Backend/socket/infra/config/FCMConfig.java b/socket/src/main/java/Backend/socket/infra/config/FCMConfig.java deleted file mode 100644 index 2ae8db7..0000000 --- a/socket/src/main/java/Backend/socket/infra/config/FCMConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -//package Backend.socket.infra.config; -// -//import com.google.auth.oauth2.GoogleCredentials; -//import com.google.firebase.FirebaseApp; -//import com.google.firebase.FirebaseOptions; -//import com.google.firebase.messaging.FirebaseMessaging; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -//import org.springframework.core.io.ClassPathResource; -// -//import java.io.IOException; -//import java.io.InputStream; -//import java.util.List; -// -//@Configuration -//public class FCMConfig { -// @Bean -// FirebaseMessaging firebaseMessaging() throws IOException { -// ClassPathResource resource = new ClassPathResource("firebase/AccountKey.json"); -// InputStream refreshToken = resource.getInputStream(); -// -// FirebaseApp firebaseApp = null; -// List firebaseAppList = FirebaseApp.getApps(); -// if(firebaseAppList != null && !firebaseAppList.isEmpty()) { -// for (FirebaseApp app : firebaseAppList){ -// if (app.getName().equals(FirebaseApp.DEFAULT_APP_NAME)) { -// firebaseApp = app; -// } -// } -// } else { -// FirebaseOptions options = FirebaseOptions.builder() -// .setCredentials(GoogleCredentials.fromStream(refreshToken)) -// .build(); -// firebaseApp = FirebaseApp.initializeApp(options); -// } -// return FirebaseMessaging.getInstance(firebaseApp); -// } -//} diff --git a/socket/src/main/java/Backend/socket/infra/config/WebConfig.java b/socket/src/main/java/Backend/socket/infra/config/WebConfig.java deleted file mode 100644 index 0207633..0000000 --- a/socket/src/main/java/Backend/socket/infra/config/WebConfig.java +++ /dev/null @@ -1,25 +0,0 @@ -//package Backend.socket.infra.config; -// -//import org.springframework.context.annotation.Configuration; -//import org.springframework.web.servlet.config.annotation.CorsRegistry; -//import org.springframework.web.servlet.config.annotation.EnableWebMvc; -//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -// -//@EnableWebMvc -//@Configuration -//public class WebConfig implements WebMvcConfigurer { -// @Override -// public void addCorsMappings(CorsRegistry registry) { -// registry.addMapping("/**") -// .allowedOrigins("*") -// .allowedMethods("*") -// .exposedHeaders("Access-Control-Allow-Origin", -// "Access-Control-Allow-Methods", -// "Access-Control-Allow-Headers", -// "Access-Control-Max-Age", -// "Access-Control-Request-Headers", -// "Access-Control-Request-Method") -// .allowCredentials(false) -// .maxAge(30000000); -// } -//} diff --git a/socket/src/main/java/Backend/socket/infra/external/AwsService.java b/socket/src/main/java/Backend/socket/infra/external/AwsService.java deleted file mode 100644 index 3c7f0b4..0000000 --- a/socket/src/main/java/Backend/socket/infra/external/AwsService.java +++ /dev/null @@ -1,143 +0,0 @@ -package Backend.socket.infra.external; - - -import Backend.socket.global.error.httpException.InternalServerException; -import Backend.socket.global.error.httpException.InvalidValueException; -import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.model.CannedAccessControlList; -import com.amazonaws.services.s3.model.DeleteObjectRequest; -import com.amazonaws.services.s3.model.ObjectMetadata; -import com.amazonaws.services.s3.model.PutObjectRequest; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.server.ResponseStatusException; - -import java.io.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -import static Backend.socket.global.error.ErrorCode.INVALID_IMAGE_TYPE; -import static Backend.socket.global.error.ErrorCode.S3_UPLOAD_ERROR; - - -@Slf4j -@RequiredArgsConstructor -@Transactional -@Service -public class AwsService { - @Value("${cloud.aws.s3.bucket}") - private String bucket; - - private final AmazonS3 amazonS3; - - public String uploadImageToS3(String image) throws IOException { - String[] strings = image.split(" "); // ","을 기준으로 바이트 코드를 나눠준다 - String base64Image = strings[1]; - String extension = ""; // if 문을 통해 확장자명을 정해줌 - if (strings[0].equals("data:image/jpeg;base64")) { - extension = "jpeg"; - } else if (strings[0].equals("data:image/png;base64")){ - extension = "png"; - } else { - extension = "jpg"; - } - - -// ... - - byte[] imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64Image); // 바이트 코드를 // 바이트 코드를 - - File tempFile = File.createTempFile("image", "." + extension); // createTempFile을 통해 임시 파일을 생성해준다. (임시파일은 지워줘야함) - try (OutputStream outputStream = new FileOutputStream(tempFile)) { - outputStream.write(imageBytes); // OutputStream outputStream = new FileOutputStream(tempFile)을 통해 생성한 outputStream 객체에 imageBytes를 작성해준다. - } - // 문자열을 공백을 기준으로 분리하여 문자열 배열로 변환 - String[] byteStrings = image.split(" "); - - // byte 배열 생성 - byte[] imageData = new byte[byteStrings.length]; - - for (int i = 0; i < byteStrings.length; i++) { - if (byteStrings[i].matches("-?[0-9]+")) { - imageData[i] = Byte.parseByte(byteStrings[i]); - } else if (byteStrings[i].matches("-?0x[0-9a-fA-F]+")) { - imageData[i] = (byte) Integer.parseInt(byteStrings[i].substring(2), 16); - } else { - // 잘못된 형식의 문자열인 경우 처리할 작업 - imageData[i] = 0; - } - } - - String fileName = UUID.randomUUID().toString(); - String fileUrl = ""; - - try { - ObjectMetadata objectMetadata = new ObjectMetadata(); - objectMetadata.setContentType("image/jpeg"); - objectMetadata.setContentLength(imageData.length); - - InputStream inputStream = new ByteArrayInputStream(imageData); - amazonS3.putObject(new PutObjectRequest(bucket, fileName, inputStream, objectMetadata) - .withCannedAcl(CannedAccessControlList.PublicRead)); - - fileUrl = amazonS3.getUrl(bucket, fileName).toString(); - } catch (Exception e) { - e.printStackTrace(); - } - - return fileUrl; - } - - public List uploadImages(List imageDataList) { - if (imageDataList.isEmpty()) - return null; - List fileUrlList = new ArrayList<>(); - - imageDataList.forEach(imageData -> { - String fileName = UUID.randomUUID().toString(); - String fileUrl = ""; - - try { - ObjectMetadata objectMetadata = new ObjectMetadata(); - objectMetadata.setContentType("image/jpeg"); - objectMetadata.setContentLength(imageData.length); - - InputStream inputStream = new ByteArrayInputStream(imageData); - amazonS3.putObject(new PutObjectRequest(bucket, fileName, inputStream, objectMetadata) - .withCannedAcl(CannedAccessControlList.PublicRead)); - - fileUrl = amazonS3.getUrl(bucket, fileName).toString(); - } catch (Exception e) { - log.error(e.getMessage()); - throw new InternalServerException(S3_UPLOAD_ERROR); - } - - fileUrlList.add(fileUrl); - }); - - return fileUrlList; - } - public void deleteImage(String fileName) { - amazonS3.deleteObject(new DeleteObjectRequest(bucket, fileName)); - } - public String createFileName(String fileName) { - return UUID.randomUUID().toString().concat(getFileExtension(fileName)); - } - - private String getFileExtension(String fileName) { - try { - return fileName.substring(fileName.lastIndexOf(".")); - } catch(StringIndexOutOfBoundsException e) { - throw new InvalidValueException(INVALID_IMAGE_TYPE); - } - } - -} -