Skip to content

Commit

Permalink
Merge pull request #95 from billbill-project/feature/chat
Browse files Browse the repository at this point in the history
[fix] JsonFormat , null 방지 코드 추가
  • Loading branch information
jimmy0524 authored Dec 24, 2024
2 parents 01869fb + 9d753bf commit 7fd0c5c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
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 7fd0c5c

Please sign in to comment.