From b72e2695b9413d30ab033b3749c08c759d8fa42d Mon Sep 17 00:00:00 2001 From: Lemonade255 Date: Wed, 15 Nov 2023 21:34:51 +0900 Subject: [PATCH] =?UTF-8?q?hotfix(BE):=20=EC=B1=84=ED=8C=85=20=EC=A0=84?= =?UTF-8?q?=EC=86=A1=20=EC=8B=9C=EA=B0=84=20=EC=98=A4=EB=A5=98=20BUS-209-M?= =?UTF-8?q?VP1-bugfix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/api/auth/service/JwtUtilService.java | 4 ++-- .../api/chat/adapter/in/rest/ChatController.java | 4 ++-- .../chat/adapter/out/persistence/ChatMapper.java | 2 +- .../out/persistence/ChatPersistentAdapter.java | 2 +- .../chat/application/port/in/SendChatUsecase.java | 2 +- .../java/com/example/api/chat/domain/Chat.java | 3 ++- .../example/api/chat/service/ChatAsyncService.java | 14 ++++++-------- .../com/example/api/chat/service/ChatService.java | 2 +- .../example/api/chat/service/KafkaSendService.java | 9 +++++---- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/example/api/auth/service/JwtUtilService.java b/src/main/java/com/example/api/auth/service/JwtUtilService.java index 4b9ccf7..5ecfe06 100644 --- a/src/main/java/com/example/api/auth/service/JwtUtilService.java +++ b/src/main/java/com/example/api/auth/service/JwtUtilService.java @@ -17,8 +17,8 @@ import java.util.Date; @Service -@Slf4j @RequiredArgsConstructor +@Slf4j public class JwtUtilService { private final JwtProperties jwtProperties; private final RefreshTokenService refreshTokenService; @@ -70,7 +70,7 @@ public boolean verifyToken(String token) { Jws claimsJws = Jwts.parserBuilder() .setSigningKey(secretKey) .build().parseClaimsJws(token); - return claimsJws.getBody().getExpiration().after(new Date()); // 만료 시간 유혀성 검사 + return claimsJws.getBody().getExpiration().after(new Date()); // 만료 시간 유효성 검사 } catch (Exception e) { log.error(e.getMessage()); return false; diff --git a/src/main/java/com/example/api/chat/adapter/in/rest/ChatController.java b/src/main/java/com/example/api/chat/adapter/in/rest/ChatController.java index 3e815e9..c8c4f27 100644 --- a/src/main/java/com/example/api/chat/adapter/in/rest/ChatController.java +++ b/src/main/java/com/example/api/chat/adapter/in/rest/ChatController.java @@ -31,8 +31,8 @@ @Slf4j @Tag(name = "Chat", description = "Chat API") public class ChatController { - private final SendChatUsecase sendChatUsecase; private final SubscribeRoomUsecase subscribeRoomUsecase; + private final SendChatUsecase sendChatUsecase; private final GetChatListUsecase getChatListUsecase; private final FileUploadUsecase fileUploadUsecase; @@ -78,7 +78,7 @@ public void subscribe(@DestinationVariable String roomId) { * 채팅 내역 불러오기 * @param roomId (ID) * @param pageable (데이터) - * @return List + * @return chat list */ @Operation(summary = "Get chat list", description = "채팅 목록을 불러온다.") @GetMapping("/chat") diff --git a/src/main/java/com/example/api/chat/adapter/out/persistence/ChatMapper.java b/src/main/java/com/example/api/chat/adapter/out/persistence/ChatMapper.java index 7bcadfb..7e2598f 100644 --- a/src/main/java/com/example/api/chat/adapter/out/persistence/ChatMapper.java +++ b/src/main/java/com/example/api/chat/adapter/out/persistence/ChatMapper.java @@ -11,7 +11,7 @@ unmappedTargetPolicy = ReportingPolicy.IGNORE) // 스프링과 사용할 때는 필수적으로 붙여주자, 일치하지 않는 필드는 무ㅡ public interface ChatMapper { @Mapping(source = "roomId", target = "roomId.chatroomId") - @Mapping(source = "senderId",target = "senderId.userId") + @Mapping(source = "senderId", target = "senderId.userId") ChatEntity toEntity(AddChatDto addChatDto); @Mapping(source = "createdAt", target = "createdAt") diff --git a/src/main/java/com/example/api/chat/adapter/out/persistence/ChatPersistentAdapter.java b/src/main/java/com/example/api/chat/adapter/out/persistence/ChatPersistentAdapter.java index e0e0be2..778c85e 100644 --- a/src/main/java/com/example/api/chat/adapter/out/persistence/ChatPersistentAdapter.java +++ b/src/main/java/com/example/api/chat/adapter/out/persistence/ChatPersistentAdapter.java @@ -31,7 +31,7 @@ public void addChat(AddChatDto addChatDto) { @Override public List getChatList(UUID roomId, Pageable pageable) { Page ret = chatRepository.findAllByRoomId_ChatroomId(roomId, pageable); - if (ret != null && ret.hasContent()){ + if (ret != null && ret.hasContent()) { return chatMapper.toDomainList(ret.getContent()); } return new ArrayList<>(); diff --git a/src/main/java/com/example/api/chat/application/port/in/SendChatUsecase.java b/src/main/java/com/example/api/chat/application/port/in/SendChatUsecase.java index bd58de5..3199344 100644 --- a/src/main/java/com/example/api/chat/application/port/in/SendChatUsecase.java +++ b/src/main/java/com/example/api/chat/application/port/in/SendChatUsecase.java @@ -9,4 +9,4 @@ public interface SendChatUsecase { * @param message Message */ void send(String roomNumber, AddChatDto message); -} +} \ No newline at end of file diff --git a/src/main/java/com/example/api/chat/domain/Chat.java b/src/main/java/com/example/api/chat/domain/Chat.java index d8bdbb1..cfa87fa 100644 --- a/src/main/java/com/example/api/chat/domain/Chat.java +++ b/src/main/java/com/example/api/chat/domain/Chat.java @@ -7,9 +7,10 @@ import java.util.UUID; @Getter +@Setter @Builder -@AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor public class Chat { private UUID roomId; private ChatUser senderId; diff --git a/src/main/java/com/example/api/chat/service/ChatAsyncService.java b/src/main/java/com/example/api/chat/service/ChatAsyncService.java index bd2ec66..b5b182b 100644 --- a/src/main/java/com/example/api/chat/service/ChatAsyncService.java +++ b/src/main/java/com/example/api/chat/service/ChatAsyncService.java @@ -1,6 +1,5 @@ package com.example.api.chat.service; - import com.example.api.chat.application.port.out.AddChatPort; import com.example.api.chat.dto.AddChatDto; import lombok.RequiredArgsConstructor; @@ -11,25 +10,24 @@ import java.util.concurrent.CompletableFuture; @Service -@Slf4j @RequiredArgsConstructor +@Slf4j public class ChatAsyncService { private final AddChatPort addChatPort; /** * 비동기 작업 처리 -> 디비 저장 - * @param addChatDto - * @return + * @param addChatDto (데이터) + * @return CompletableFuture */ @Async - public CompletableFuture saveChat(AddChatDto addChatDto){ + public CompletableFuture saveChat(AddChatDto addChatDto) { try { addChatPort.addChat(addChatDto); - }catch (Exception e){ //혹시라도 문제 생겼을 경우 + } catch (Exception e) { // 혹시라도 문제 생겼을 경우 log.error(e.getMessage()); Thread.currentThread().interrupt(); } return CompletableFuture.completedFuture(null); } - -} +} \ No newline at end of file diff --git a/src/main/java/com/example/api/chat/service/ChatService.java b/src/main/java/com/example/api/chat/service/ChatService.java index d429b12..2f12e26 100644 --- a/src/main/java/com/example/api/chat/service/ChatService.java +++ b/src/main/java/com/example/api/chat/service/ChatService.java @@ -13,8 +13,8 @@ import java.util.UUID; @Service -@Slf4j @RequiredArgsConstructor +@Slf4j @Transactional(readOnly = true) public class ChatService implements GetChatListUsecase { private final GetChatListPort getChatListPort; diff --git a/src/main/java/com/example/api/chat/service/KafkaSendService.java b/src/main/java/com/example/api/chat/service/KafkaSendService.java index 5a89a3e..a0107c7 100644 --- a/src/main/java/com/example/api/chat/service/KafkaSendService.java +++ b/src/main/java/com/example/api/chat/service/KafkaSendService.java @@ -11,22 +11,24 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.concurrent.CompletableFuture; -@Slf4j @Service @RequiredArgsConstructor +@Slf4j @Transactional(readOnly = true) public class KafkaSendService implements SendChatUsecase { - private final KafkaTemplate kafkaTemplate; private final ChatMapper chatMapper; private final ChatAsyncService chatService; private final KafkaConsumerConfig kafkaConsumerConfig; + private final KafkaTemplate kafkaTemplate; @Override @Transactional public void send(String roomId, AddChatDto message) { Chat sendChat = chatMapper.toDomain(message); + sendChat.setCreatedAt(LocalDateTime.now()); final CompletableFuture chatResult = chatService.saveChat(message); // 비동기 작업으로 디비 저장 chatResult.thenAccept( @@ -38,6 +40,5 @@ public void send(String roomId, AddChatDto message) { kafkaConsumerConfig.createListenerContainerForRoom(roomId); // 혹시 몰라 컨슈머가 없을 수도 있어 추가 kafkaTemplate.send(roomId, sendChat); log.info("kafka send FINISH"); - } -} +} \ No newline at end of file