261102_01_ENH: 알림톡 발신 프로필 목록 조회 추가 및 템플릿 API senderKey 필수 검증 적용

This commit is contained in:
2026-11-02 12:08:12 +09:00
parent 9f0a06bfae
commit e6b9760594
9 changed files with 77 additions and 15 deletions

View File

@@ -33,8 +33,9 @@ public class KkoTemplateApiClient {
this.externalApiClient = externalApiClient;
}
public JsonNode list(String keyword, String templateStatus) {
public JsonNode list(String senderKey, String keyword, String templateStatus) {
Map<String, Object> request = credentials();
request.put("senderKey", senderKey);
request.put("templateStatus", templateStatus);
if (keyword == null || keyword.isBlank()) {
request.put("page", 1);
@@ -45,17 +46,21 @@ public class KkoTemplateApiClient {
return post("/template/list", request);
}
public JsonNode detail(String templateCode) {
public JsonNode detail(String senderKey, String templateCode) {
Map<String, Object> request = credentials();
request.put("senderKey", senderKey);
request.put("templateCode", templateCode);
return post("/template/detail", request);
}
public JsonNode profiles() {
return post("/profile/use", credentials());
}
private Map<String, Object> credentials() {
Map<String, Object> request = new LinkedHashMap<>();
request.put("bizId", properties.getBizId());
request.put("apiKey", properties.getApiKey());
request.put("senderKey", properties.getSenderKey());
return request;
}

View File

@@ -24,8 +24,6 @@ public class KkoTemplateProperties {
private String bizId;
@NotBlank
private String apiKey;
@NotBlank
private String senderKey;
@NotEmpty
private List<@NotBlank String> templateStatuses;

View File

@@ -4,6 +4,7 @@ import com.kri.common.feature.web.RequestUserContext;
import com.kri.notihub.server.common.enums.ChannelType;
import com.kri.notihub.server.dto.email.EmailAttachmentDto;
import com.kri.notihub.server.dto.template.KkoTemplateDetailDto;
import com.kri.notihub.server.dto.template.KkoProfileDto;
import com.kri.notihub.server.dto.template.KkoTemplateDetailRequestDto;
import com.kri.notihub.server.dto.template.KkoTemplateListRequestDto;
import com.kri.notihub.server.dto.template.KkoTemplateListResponseDto;
@@ -46,12 +47,18 @@ public class TemplateController {
private final FileService fileService;
private final KkoTemplateService kkoTemplateService;
@Operation(summary = "사용 가능한 알림톡 발신 프로필 조회")
@GetMapping("/kko/profiles")
public List<KkoProfileDto> getKkoProfiles() {
return kkoTemplateService.getProfiles();
}
@Operation(summary = "외부 알림톡 템플릿 목록 조회")
@PostMapping(value = "/kko/list", consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public KkoTemplateListResponseDto getKkoTemplateList(
@Valid @RequestBody KkoTemplateListRequestDto request) {
return kkoTemplateService.getList(request.keyword());
return kkoTemplateService.getList(request.senderKey(), request.keyword());
}
@Operation(summary = "외부 알림톡 템플릿 상세 조회")
@@ -59,7 +66,7 @@ public class TemplateController {
produces = MediaType.APPLICATION_JSON_VALUE)
public KkoTemplateDetailDto getKkoTemplateDetail(
@Valid @RequestBody KkoTemplateDetailRequestDto request) {
return kkoTemplateService.getDetail(request.templateCode());
return kkoTemplateService.getDetail(request.senderKey(), request.templateCode());
}

View File

@@ -0,0 +1,4 @@
package com.kri.notihub.server.dto.template;
public record KkoProfileDto(String senderKey, String name, String uuid) {
}

View File

@@ -5,6 +5,9 @@ import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
public record KkoTemplateDetailRequestDto(
@NotBlank
@Size(max = 40)
String senderKey,
@NotBlank
@Size(max = 30)
@Pattern(regexp = "[A-Za-z0-9_-]+")

View File

@@ -1,8 +1,12 @@
package com.kri.notihub.server.dto.template;
import jakarta.validation.constraints.Size;
import jakarta.validation.constraints.NotBlank;
public record KkoTemplateListRequestDto(
@NotBlank
@Size(max = 40)
String senderKey,
@Size(min = 2, max = 50)
String keyword
) {

View File

@@ -8,12 +8,14 @@ import com.kri.notihub.server.common.consts.NotihubConst;
import com.kri.notihub.server.common.external.kakao.KkoTemplateApiClient;
import com.kri.notihub.server.config.KkoTemplateProperties;
import com.kri.notihub.server.dto.template.KkoTemplateDetailDto;
import com.kri.notihub.server.dto.template.KkoProfileDto;
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.LinkedHashMap;
import java.util.Map;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@@ -25,7 +27,8 @@ public class KkoTemplateService {
private final KkoTemplateProperties properties;
private final ObjectMapper objectMapper;
public KkoTemplateListResponseDto getList(String keyword) {
public KkoTemplateListResponseDto getList(String senderKey, String keyword) {
validateSenderKey(senderKey);
String normalized = keyword == null || keyword.isBlank() ? null : keyword.trim();
if (normalized != null && (normalized.length() < 2 || normalized.length() > 50)) {
throw BusinessException.badRequest("KKO_TEMPLATE_INVALID_KEYWORD",
@@ -36,7 +39,7 @@ public class KkoTemplateService {
int totalPage = 0;
int currentPage = 0;
for (String templateStatus : properties.getTemplateStatuses()) {
JsonNode root = apiClient.list(normalized, templateStatus);
JsonNode root = apiClient.list(senderKey, normalized, templateStatus);
JsonNode items = root.path("data").path("list");
if (!items.isArray()) {
throw KkoTemplateApiClient.invalidResponse();
@@ -64,11 +67,12 @@ public class KkoTemplateService {
new ArrayList<>(templates.values()));
}
public KkoTemplateDetailDto getDetail(String templateCode) {
public KkoTemplateDetailDto getDetail(String senderKey, String templateCode) {
validateSenderKey(senderKey);
validateCode(templateCode);
JsonNode data = apiClient.detail(templateCode).path("data");
JsonNode data = apiClient.detail(senderKey, templateCode).path("data");
if (!templateCode.equals(data.path("templateCode").asText())
|| !properties.getSenderKey().equals(data.path("senderKey").asText())
|| !senderKey.equals(data.path("senderKey").asText())
|| !data.path("templateContent").isTextual()
|| data.path("templateContent").asText().isBlank()) {
throw KkoTemplateApiClient.invalidResponse();
@@ -81,7 +85,7 @@ public class KkoTemplateService {
}
public void synchronize(TemplateBasicDto template) {
KkoTemplateDetailDto detail = getDetail(template.getKkoTmplatCd());
KkoTemplateDetailDto detail = getDetail(template.getSenderKey(), template.getKkoTmplatCd());
validateAvailable(detail);
validateBasicTextFormat(detail);
if (detail.templatePreviewMessage() != null
@@ -90,7 +94,6 @@ public class KkoTemplateService {
}
template.setTmplatBody(detail.templateContent());
template.setTmplatTitle(detail.templatePreviewMessage());
template.setSenderKey(properties.getSenderKey());
}
private void validateAvailable(KkoTemplateDetailDto detail) {
@@ -119,6 +122,43 @@ public class KkoTemplateService {
}
}
public List<KkoProfileDto> getProfiles() {
JsonNode data = apiClient.profiles().path("data");
JsonNode success = data.path("success");
JsonNode fail = data.path("fail");
if (!success.isArray() || !fail.isArray() || !fail.isEmpty()) {
throw KkoTemplateApiClient.invalidResponse();
}
var profiles = new ArrayList<KkoProfileDto>();
for (JsonNode item : success) {
if (!item.isObject() || !item.path("profileStatus").isTextual()) {
throw KkoTemplateApiClient.invalidResponse();
}
if (!"A".equals(item.path("profileStatus").asText())) {
continue;
}
for (String field : List.of("senderKey", "name", "uuid")) {
if (!item.path(field).isTextual() || item.path(field).asText().isBlank()) {
throw KkoTemplateApiClient.invalidResponse();
}
}
if (item.path("senderKey").asText().length() > 40) {
throw KkoTemplateApiClient.invalidResponse();
}
profiles.add(new KkoProfileDto(
item.path("senderKey").asText(), item.path("name").asText(),
item.path("uuid").asText()));
}
return profiles;
}
private static void validateSenderKey(String senderKey) {
if (senderKey == null || senderKey.isBlank() || senderKey.length() > 40) {
throw BusinessException.badRequest("KKO_TEMPLATE_INVALID_SENDER_KEY",
"발신 프로필 키는 필수이며 40자 이하여야 합니다.");
}
}
private static void validateCode(String templateCode) {
if (templateCode == null || !templateCode.matches("[A-Za-z0-9_-]{1,30}")) {
throw BusinessException.badRequest("EMPTY_KKO_TMPLAT_CD",