From 93fd3ddf19d357539871da143d9c6e287747eb40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8C=E1=85=B5=E1=84=92?= =?UTF-8?q?=E1=85=A7=E1=86=A8?= Date: Mon, 2 Sep 2024 15:04:26 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Refactor:=20CORS=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 어노테이션 기반 -> 설정 클래스로 변경 --- .../kaboochat/chat/config/WebConfig.java | 24 +++++++++++++++++++ .../chat/controller/ChatController.java | 2 -- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/main/java/kaboo/kaboochat/chat/config/WebConfig.java diff --git a/src/main/java/kaboo/kaboochat/chat/config/WebConfig.java b/src/main/java/kaboo/kaboochat/chat/config/WebConfig.java new file mode 100644 index 0000000..9ac44a1 --- /dev/null +++ b/src/main/java/kaboo/kaboochat/chat/config/WebConfig.java @@ -0,0 +1,24 @@ +package kaboo.kaboochat.chat.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * CORS 설정 등 웹 설정 클래스 + * + * @author : parkjihyeok + * @since : 2024/09/02 + */ +@Configuration +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOriginPatterns("*") // “*“같은 와일드카드를 사용 + .allowedMethods("GET", "POST") // 허용할 HTTP method + .allowCredentials(true); // 쿠키 인증 요청 허용 + } +} + diff --git a/src/main/java/kaboo/kaboochat/chat/controller/ChatController.java b/src/main/java/kaboo/kaboochat/chat/controller/ChatController.java index 24b5a10..1a41eed 100644 --- a/src/main/java/kaboo/kaboochat/chat/controller/ChatController.java +++ b/src/main/java/kaboo/kaboochat/chat/controller/ChatController.java @@ -6,7 +6,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.messaging.handler.annotation.MessageMapping; -import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -27,7 +26,6 @@ * @author : parkjihyeok * @since : 2024/08/18 */ -@CrossOrigin(origins = "http://localhost:5173", allowCredentials = "true") @RestController @RequestMapping("/chat") @RequiredArgsConstructor From 5d897785bceb9fdd2a8f385063a195732bfa214e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8C=E1=85=B5=E1=84=92?= =?UTF-8?q?=E1=85=A7=E1=86=A8?= Date: Tue, 10 Sep 2024 13:11:44 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Refactor:=20=EC=9D=B8=EC=A6=9D=EC=84=9C?= =?UTF-8?q?=EB=B2=84=EC=99=80=20=EC=97=94=ED=8B=B0=ED=8B=B0=EB=A5=BC=20?= =?UTF-8?q?=EB=A7=9E=EC=B6=94=EA=B8=B0=EC=9C=84=ED=95=9C=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/domain/dto/request/ChatMessageRequest.java | 2 +- .../chat/domain/dto/response/ChatMessageResponse.java | 4 ++-- .../kaboochat/chat/domain/entity/ChatMessage.java | 4 ++-- .../kaboochat/chat/controller/ChatControllerTest.java | 2 +- .../chat/repository/ChatMemberRepositoryTest.java | 10 +++++----- .../chat/repository/ChatMessageRepositoryTest.java | 2 +- .../chat/repository/ChatRoomRepositoryTest.java | 8 ++++---- .../kaboo/kaboochat/chat/service/ChatServiceTest.java | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/kaboo/kaboochat/chat/domain/dto/request/ChatMessageRequest.java b/src/main/java/kaboo/kaboochat/chat/domain/dto/request/ChatMessageRequest.java index 9b955c6..e57490f 100644 --- a/src/main/java/kaboo/kaboochat/chat/domain/dto/request/ChatMessageRequest.java +++ b/src/main/java/kaboo/kaboochat/chat/domain/dto/request/ChatMessageRequest.java @@ -17,6 +17,6 @@ public class ChatMessageRequest { private String chatRoomUUID; // 채팅방 UUID private String username; // 전송한 사용자의 ID - private String nickname; // 전송한 사용자의 닉네임 + private String koreaName; // 전송한 사용자의 닉네임 private String message; // 메시지 내용 } diff --git a/src/main/java/kaboo/kaboochat/chat/domain/dto/response/ChatMessageResponse.java b/src/main/java/kaboo/kaboochat/chat/domain/dto/response/ChatMessageResponse.java index bf6ed6d..49f589d 100644 --- a/src/main/java/kaboo/kaboochat/chat/domain/dto/response/ChatMessageResponse.java +++ b/src/main/java/kaboo/kaboochat/chat/domain/dto/response/ChatMessageResponse.java @@ -20,14 +20,14 @@ public class ChatMessageResponse { private String username; // 전송한 사용자의 ID - private String nickname; // 전송한 사용자의 닉네임 + private String koreaName; // 전송한 사용자의 닉네임 private String message; // 메시지 내용 private LocalDateTime sendAt; // 메시지 전송시간 public static ChatMessageResponse fromEntity(ChatMessage chatMessage) { return ChatMessageResponse.builder() .username(chatMessage.getUsername()) - .nickname(chatMessage.getNickname()) + .koreaName(chatMessage.getKoreaName()) .message(chatMessage.getMessage()) .sendAt(chatMessage.getSendAt()) .build(); diff --git a/src/main/java/kaboo/kaboochat/chat/domain/entity/ChatMessage.java b/src/main/java/kaboo/kaboochat/chat/domain/entity/ChatMessage.java index a1eb8f4..b7758b0 100644 --- a/src/main/java/kaboo/kaboochat/chat/domain/entity/ChatMessage.java +++ b/src/main/java/kaboo/kaboochat/chat/domain/entity/ChatMessage.java @@ -29,7 +29,7 @@ public class ChatMessage { private String chatRoomUUID; // 채팅방 UUID private String username; // 전송한 사용자의 ID - private String nickname; // 전송한 사용자의 닉네임 + private String koreaName; // 전송한 사용자의 닉네임 private String message; // 메시지 내용 private LocalDateTime sendAt; // 메시지 전송시간 @@ -37,7 +37,7 @@ public static ChatMessage createMessage(ChatMessageRequest dto) { return ChatMessage.builder() .chatRoomUUID(dto.getChatRoomUUID()) .username(dto.getUsername()) - .nickname(dto.getNickname()) + .koreaName(dto.getKoreaName()) .message(dto.getMessage()) .sendAt(LocalDateTime.now()) .build(); diff --git a/src/test/java/kaboo/kaboochat/chat/controller/ChatControllerTest.java b/src/test/java/kaboo/kaboochat/chat/controller/ChatControllerTest.java index 1753bc4..3721bd4 100644 --- a/src/test/java/kaboo/kaboochat/chat/controller/ChatControllerTest.java +++ b/src/test/java/kaboo/kaboochat/chat/controller/ChatControllerTest.java @@ -230,7 +230,7 @@ void findChatMessageTest() throws Exception { fieldWithPath("message").description("응답 메시지"), fieldWithPath("data[]").description("채팅내역 리스트"), fieldWithPath("data[].username").description("참여자 ID"), - fieldWithPath("data[].nickname").description("참여자 닉네임"), + fieldWithPath("data[].koreaName").description("참여자 닉네임"), fieldWithPath("data[].message").description("채팅 내용"), fieldWithPath("data[].sendAt").description("전송 시간") ))); diff --git a/src/test/java/kaboo/kaboochat/chat/repository/ChatMemberRepositoryTest.java b/src/test/java/kaboo/kaboochat/chat/repository/ChatMemberRepositoryTest.java index 3fc3980..77ca747 100644 --- a/src/test/java/kaboo/kaboochat/chat/repository/ChatMemberRepositoryTest.java +++ b/src/test/java/kaboo/kaboochat/chat/repository/ChatMemberRepositoryTest.java @@ -44,10 +44,10 @@ void setUp() { chatRoom = ChatRoom.createRoom("채팅방1"); chatRoomRepository.save(chatRoom); JdbcTemplate jdbc = new JdbcTemplate(dataSource); - String sql1 = "insert into member(username, nickname, password) values ('pjh1', '1111', 'pw111')"; - String sql2 = "insert into member(username, nickname, password) values ('pjh2', '2222', 'pw222')"; - String sql3 = "insert into member(username, nickname, password) values ('pjh3', '3333', 'pw333')"; - String sql4 = "insert into member(username, nickname, password) values ('pjh4', '4444', 'pw444')"; + String sql1 = "insert into member (username, email, korea_name, english_name, password, introduce, class_num) values ('pjh1', 'pjh1@example.com', '1111', 'User One', 'password1', '안녕하세요. 유저1입니다.', 101)"; + String sql2 = "insert into member (username, email, korea_name, english_name, password, introduce, class_num) values ('pjh2', 'pjh2@example.com', '2222', 'User Two', 'password2', '안녕하세요. 유저2입니다.', 102)"; + String sql3 = "insert into member (username, email, korea_name, english_name, password, introduce, class_num) values ('pjh3', 'pjh3@example.com', '3333', 'User Three', 'password3', '안녕하세요. 유저3입니다.', 103)"; + String sql4 = "insert into member (username, email, korea_name, english_name, password, introduce, class_num) values ('pjh4', 'pjh4@example.com', '4444', 'User Four', 'password4', '안녕하세요. 유저4입니다.', 104)"; jdbc.execute(sql1); jdbc.execute(sql2); jdbc.execute(sql3); @@ -77,6 +77,6 @@ void findByChatUUIDTest() { assertEquals(4, result.size()); assertEquals("pjh3", result.get(2).getMember().getUsername()); assertEquals("2222", result.get(1).getMember().getKoreaName()); - assertEquals("pw444", result.get(3).getMember().getPassword()); + assertEquals("password4", result.get(3).getMember().getPassword()); } } diff --git a/src/test/java/kaboo/kaboochat/chat/repository/ChatMessageRepositoryTest.java b/src/test/java/kaboo/kaboochat/chat/repository/ChatMessageRepositoryTest.java index afbeb39..90a004e 100644 --- a/src/test/java/kaboo/kaboochat/chat/repository/ChatMessageRepositoryTest.java +++ b/src/test/java/kaboo/kaboochat/chat/repository/ChatMessageRepositoryTest.java @@ -96,6 +96,6 @@ void findByUUIDTest() { assertEquals(3, result.getTotalPages()); assertEquals("안녕6!", result.getContent().get(0).getMessage()); assertEquals("user3", result.getContent().get(1).getUsername()); - assertEquals("nick2", result.getContent().get(2).getNickname()); + assertEquals("nick2", result.getContent().get(2).getKoreaName()); } } diff --git a/src/test/java/kaboo/kaboochat/chat/repository/ChatRoomRepositoryTest.java b/src/test/java/kaboo/kaboochat/chat/repository/ChatRoomRepositoryTest.java index 905cd10..1c78915 100644 --- a/src/test/java/kaboo/kaboochat/chat/repository/ChatRoomRepositoryTest.java +++ b/src/test/java/kaboo/kaboochat/chat/repository/ChatRoomRepositoryTest.java @@ -45,10 +45,10 @@ void setUp() { chatRoom = ChatRoom.createRoom("채팅방1"); chatRoomRepository.save(chatRoom); JdbcTemplate jdbc = new JdbcTemplate(dataSource); - String sql1 = "insert into member(username, nickname, password) values ('pjh1', '1111', 'pw111')"; - String sql2 = "insert into member(username, nickname, password) values ('pjh2', '2222', 'pw222')"; - String sql3 = "insert into member(username, nickname, password) values ('pjh3', '3333', 'pw333')"; - String sql4 = "insert into member(username, nickname, password) values ('pjh4', '4444', 'pw444')"; + String sql1 = "insert into member (username, email, korea_name, english_name, password, introduce, class_num) values ('pjh1', 'pjh1@example.com', '1111', 'User One', 'password1', '안녕하세요. 유저1입니다.', 101)"; + String sql2 = "insert into member (username, email, korea_name, english_name, password, introduce, class_num) values ('pjh2', 'pjh2@example.com', '2222', 'User Two', 'password2', '안녕하세요. 유저2입니다.', 102)"; + String sql3 = "insert into member (username, email, korea_name, english_name, password, introduce, class_num) values ('pjh3', 'pjh3@example.com', '3333', 'User Three', 'password3', '안녕하세요. 유저3입니다.', 103)"; + String sql4 = "insert into member (username, email, korea_name, english_name, password, introduce, class_num) values ('pjh4', 'pjh4@example.com', '4444', 'User Four', 'password4', '안녕하세요. 유저4입니다.', 104)"; jdbc.execute(sql1); jdbc.execute(sql2); jdbc.execute(sql3); diff --git a/src/test/java/kaboo/kaboochat/chat/service/ChatServiceTest.java b/src/test/java/kaboo/kaboochat/chat/service/ChatServiceTest.java index b52c4a8..0734c5b 100644 --- a/src/test/java/kaboo/kaboochat/chat/service/ChatServiceTest.java +++ b/src/test/java/kaboo/kaboochat/chat/service/ChatServiceTest.java @@ -195,7 +195,7 @@ void findMessageTest1() { assertEquals(4, result.size()); assertEquals("메시지1", result.get(0).getMessage()); assertEquals("user2", result.get(2).getUsername()); - assertEquals("nick1", result.get(3).getNickname()); + assertEquals("nick1", result.get(3).getKoreaName()); verify(chatMessageRepository).findByChatRoomUUIDOrderBySendAtDesc(any(), any()); }