261020_01_ENH: KKO 템플릿 리스트 조회에 RDY에 대한 조회도 추가
This commit is contained in:
@@ -38,7 +38,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "com.kri.common:starter:beta.1.6.7"
|
implementation "com.kri.common:starter:beta.1.7.0"
|
||||||
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||||
|
|||||||
@@ -33,9 +33,9 @@ public class KkoTemplateApiClient {
|
|||||||
this.externalApiClient = externalApiClient;
|
this.externalApiClient = externalApiClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonNode list(String keyword) {
|
public JsonNode list(String keyword, String templateStatus) {
|
||||||
Map<String, Object> request = credentials();
|
Map<String, Object> request = credentials();
|
||||||
request.put("templateStatus", "ACT");
|
request.put("templateStatus", templateStatus);
|
||||||
if (keyword == null || keyword.isBlank()) {
|
if (keyword == null || keyword.isBlank()) {
|
||||||
request.put("page", 1);
|
request.put("page", 1);
|
||||||
request.put("count", 10);
|
request.put("count", 10);
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package com.kri.notihub.server.config;
|
package com.kri.notihub.server.config;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.AssertTrue;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
@@ -22,4 +26,13 @@ public class KkoTemplateProperties {
|
|||||||
private String apiKey;
|
private String apiKey;
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String senderKey;
|
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.KkoTemplateSummaryDto;
|
||||||
import com.kri.notihub.server.dto.template.TemplateBasicDto;
|
import com.kri.notihub.server.dto.template.TemplateBasicDto;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -29,21 +30,34 @@ public class KkoTemplateService {
|
|||||||
throw BusinessException.badRequest("KKO_TEMPLATE_INVALID_KEYWORD",
|
throw BusinessException.badRequest("KKO_TEMPLATE_INVALID_KEYWORD",
|
||||||
"검색어는 2자 이상 50자 이하여야 합니다.");
|
"검색어는 2자 이상 50자 이하여야 합니다.");
|
||||||
}
|
}
|
||||||
JsonNode root = apiClient.list(normalized);
|
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");
|
JsonNode items = root.path("data").path("list");
|
||||||
if (!items.isArray()) {
|
if (!items.isArray()) {
|
||||||
throw KkoTemplateApiClient.invalidResponse();
|
throw KkoTemplateApiClient.invalidResponse();
|
||||||
}
|
}
|
||||||
List<KkoTemplateSummaryDto> list = new ArrayList<>();
|
|
||||||
for (JsonNode item : items) {
|
for (JsonNode item : items) {
|
||||||
if (!item.isObject() || !item.path("templateCode").isTextual()
|
if (!item.isObject() || !item.path("templateCode").isTextual()
|
||||||
|| !item.path("templateName").isTextual()) {
|
|| !item.path("templateName").isTextual()) {
|
||||||
throw KkoTemplateApiClient.invalidResponse();
|
throw KkoTemplateApiClient.invalidResponse();
|
||||||
}
|
}
|
||||||
list.add(read(item, KkoTemplateSummaryDto.class));
|
KkoTemplateSummaryDto template = read(item, KkoTemplateSummaryDto.class);
|
||||||
|
templates.putIfAbsent(template.getTemplateCode(), template);
|
||||||
}
|
}
|
||||||
return new KkoTemplateListResponseDto(nonNegativeInt(root, "totalCount"),
|
int count = nonNegativeInt(root, "totalCount");
|
||||||
nonNegativeInt(root, "totalPage"), nonNegativeInt(root, "currentPage"), list);
|
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(totalCount, totalPage, currentPage,
|
||||||
|
new ArrayList<>(templates.values()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public KkoTemplateDetailDto getDetail(String templateCode) {
|
public KkoTemplateDetailDto getDetail(String templateCode) {
|
||||||
|
|||||||
@@ -127,6 +127,9 @@ kri:
|
|||||||
|
|
||||||
notihub:
|
notihub:
|
||||||
kakao:
|
kakao:
|
||||||
|
template-statuses:
|
||||||
|
- ACT
|
||||||
|
- RDY
|
||||||
base-url: https://kapi.ppurio.com/v3/kakao
|
base-url: https://kapi.ppurio.com/v3/kakao
|
||||||
biz-id: kri_notihub
|
biz-id: kri_notihub
|
||||||
api-key: weMdoq0nCGHA
|
api-key: weMdoq0nCGHA
|
||||||
|
|||||||
Reference in New Issue
Block a user