diff --git a/src/main/java/site/billbill/apiserver/api/chat/dto/response/ChatResponse.java b/src/main/java/site/billbill/apiserver/api/chat/dto/response/ChatResponse.java index 05f2619..b0290a0 100644 --- a/src/main/java/site/billbill/apiserver/api/chat/dto/response/ChatResponse.java +++ b/src/main/java/site/billbill/apiserver/api/chat/dto/response/ChatResponse.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.annotation.JsonFormat; import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.List; import lombok.Builder; import lombok.Getter; @@ -33,6 +32,7 @@ public static class ViewChatInfoResponse { private int unreadCount; private String lastChat; private String lastSender; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS") private LocalDateTime updatedAt; private String opponentId; private String opponentNickname; diff --git a/src/main/java/site/billbill/apiserver/api/chat/service/ChatServiceImpl.java b/src/main/java/site/billbill/apiserver/api/chat/service/ChatServiceImpl.java index a788033..7615f59 100644 --- a/src/main/java/site/billbill/apiserver/api/chat/service/ChatServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/chat/service/ChatServiceImpl.java @@ -103,6 +103,10 @@ public List getChatList(String beforeTimestamp, String use } ChatInfoList webhookResult = webhookService.sendWebhookForChatList(activeChatIdsByUserId, beforeTimestamp); + if (webhookResult == null || webhookResult.getChatInfoList() == null || webhookResult.getChatInfoList().isEmpty()) { + return Collections.emptyList(); + } + List chatInfoList = webhookResult.getChatInfoList(); return chatInfoList.stream().map(chatInfo -> { diff --git a/src/main/java/site/billbill/apiserver/api/chat/service/WebhookServiceImpl.java b/src/main/java/site/billbill/apiserver/api/chat/service/WebhookServiceImpl.java index c73f03e..3fba597 100644 --- a/src/main/java/site/billbill/apiserver/api/chat/service/WebhookServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/chat/service/WebhookServiceImpl.java @@ -2,6 +2,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -23,10 +25,11 @@ public class WebhookServiceImpl implements WebhookService { @Autowired public WebhookServiceImpl(@Value("${webhook.url}") String webhookUrl, - WebClient.Builder webClientBuilder, - ObjectMapper objectMapper) { + WebClient.Builder webClientBuilder) { this.webClient = webClientBuilder.baseUrl(webhookUrl).build(); - this.objectMapper = objectMapper; + this.objectMapper = new ObjectMapper(); + this.objectMapper.registerModule(new JavaTimeModule()); // Java 8 시간 타입 지원 + this.objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // 배열 대신 ISO-8601 사용 } public void sendWebhookForChatRoomCreate(String channelId, String contact, String owner) { @@ -49,6 +52,9 @@ public void sendWebhookForChatRoomCreate(String channelId, String contact, Strin } public WebhookRequest.ChatInfoList sendWebhookForChatList(List chatRoomIds, String beforeTimestamp) { + if (beforeTimestamp == null) { + beforeTimestamp = ""; + } String jsonResponse = webClient.post() .uri("/chat/list") .bodyValue(Map.of( @@ -58,10 +64,13 @@ public WebhookRequest.ChatInfoList sendWebhookForChatList(List chatRoomI .retrieve() .bodyToMono(String.class) .block(); + log.info(jsonResponse.toString()); try { - return objectMapper.readValue(jsonResponse, WebhookRequest.ChatInfoList.class); + WebhookRequest.ChatInfoList result = objectMapper.readValue(jsonResponse, WebhookRequest.ChatInfoList.class); + return result; } catch (JsonProcessingException e) { - throw new RuntimeException(e); + throw new RuntimeException("JSON Parsing Error", e); } + } }