261020_01_ENH: KKO 템플릿 리스트 조회에 RDY에 대한 조회도 추가
This commit is contained in:
@@ -33,9 +33,9 @@ public class KkoTemplateApiClient {
|
||||
this.externalApiClient = externalApiClient;
|
||||
}
|
||||
|
||||
public JsonNode list(String keyword) {
|
||||
public JsonNode list(String keyword, String templateStatus) {
|
||||
Map<String, Object> request = credentials();
|
||||
request.put("templateStatus", "ACT");
|
||||
request.put("templateStatus", templateStatus);
|
||||
if (keyword == null || keyword.isBlank()) {
|
||||
request.put("page", 1);
|
||||
request.put("count", 10);
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.kri.notihub.server.config;
|
||||
|
||||
import jakarta.validation.constraints.AssertTrue;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@@ -22,4 +26,13 @@ public class KkoTemplateProperties {
|
||||
private String apiKey;
|
||||
@NotBlank
|
||||
private String senderKey;
|
||||
|
||||
@NotEmpty
|
||||
private List<@NotBlank String> templateStatuses;
|
||||
|
||||
@AssertTrue(message = "template-statuses must not contain duplicate values")
|
||||
public boolean isTemplateStatusesUnique() {
|
||||
return templateStatuses == null
|
||||
|| new HashSet<>(templateStatuses).size() == templateStatuses.size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ import com.kri.notihub.server.dto.template.KkoTemplateListResponseDto;
|
||||
import com.kri.notihub.server.dto.template.KkoTemplateSummaryDto;
|
||||
import com.kri.notihub.server.dto.template.TemplateBasicDto;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -29,21 +30,34 @@ public class KkoTemplateService {
|
||||
throw BusinessException.badRequest("KKO_TEMPLATE_INVALID_KEYWORD",
|
||||
"검색어는 2자 이상 50자 이하여야 합니다.");
|
||||
}
|
||||
JsonNode root = apiClient.list(normalized);
|
||||
JsonNode items = root.path("data").path("list");
|
||||
if (!items.isArray()) {
|
||||
throw KkoTemplateApiClient.invalidResponse();
|
||||
}
|
||||
List<KkoTemplateSummaryDto> list = new ArrayList<>();
|
||||
for (JsonNode item : items) {
|
||||
if (!item.isObject() || !item.path("templateCode").isTextual()
|
||||
|| !item.path("templateName").isTextual()) {
|
||||
Map<String, KkoTemplateSummaryDto> templates = new LinkedHashMap<>();
|
||||
int totalCount = 0;
|
||||
int totalPage = 0;
|
||||
int currentPage = 0;
|
||||
for (String templateStatus : properties.getTemplateStatuses()) {
|
||||
JsonNode root = apiClient.list(normalized, templateStatus);
|
||||
JsonNode items = root.path("data").path("list");
|
||||
if (!items.isArray()) {
|
||||
throw KkoTemplateApiClient.invalidResponse();
|
||||
}
|
||||
list.add(read(item, KkoTemplateSummaryDto.class));
|
||||
for (JsonNode item : items) {
|
||||
if (!item.isObject() || !item.path("templateCode").isTextual()
|
||||
|| !item.path("templateName").isTextual()) {
|
||||
throw KkoTemplateApiClient.invalidResponse();
|
||||
}
|
||||
KkoTemplateSummaryDto template = read(item, KkoTemplateSummaryDto.class);
|
||||
templates.putIfAbsent(template.getTemplateCode(), template);
|
||||
}
|
||||
int count = nonNegativeInt(root, "totalCount");
|
||||
if (count > Integer.MAX_VALUE - totalCount) {
|
||||
throw KkoTemplateApiClient.invalidResponse();
|
||||
}
|
||||
totalCount += count;
|
||||
totalPage = Math.max(totalPage, nonNegativeInt(root, "totalPage"));
|
||||
currentPage = Math.max(currentPage, nonNegativeInt(root, "currentPage"));
|
||||
}
|
||||
return new KkoTemplateListResponseDto(nonNegativeInt(root, "totalCount"),
|
||||
nonNegativeInt(root, "totalPage"), nonNegativeInt(root, "currentPage"), list);
|
||||
return new KkoTemplateListResponseDto(totalCount, totalPage, currentPage,
|
||||
new ArrayList<>(templates.values()));
|
||||
}
|
||||
|
||||
public KkoTemplateDetailDto getDetail(String templateCode) {
|
||||
|
||||
Reference in New Issue
Block a user