Skip to content

Commit

Permalink
[fix] beforeTimestamp null 방지 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy0524 committed Dec 24, 2024
1 parent e9d97f0 commit dde18a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public List<ViewChatInfoResponse> getChatList(String beforeTimestamp, String use
}

ChatInfoList webhookResult = webhookService.sendWebhookForChatList(activeChatIdsByUserId, beforeTimestamp);
if (webhookResult == null || webhookResult.getChatInfoList() == null || webhookResult.getChatInfoList().isEmpty()) {
return Collections.emptyList();
}

List<ChatInfo> chatInfoList = webhookResult.getChatInfoList();

return chatInfoList.stream().map(chatInfo -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -49,6 +52,9 @@ public void sendWebhookForChatRoomCreate(String channelId, String contact, Strin
}

public WebhookRequest.ChatInfoList sendWebhookForChatList(List<String> chatRoomIds, String beforeTimestamp) {
if (beforeTimestamp == null) {
beforeTimestamp = "";
}
String jsonResponse = webClient.post()
.uri("/chat/list")
.bodyValue(Map.of(
Expand All @@ -58,10 +64,13 @@ public WebhookRequest.ChatInfoList sendWebhookForChatList(List<String> 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);
}

}
}

0 comments on commit dde18a7

Please sign in to comment.