261102_01_ENH: 알림톡 발신 프로필 목록 조회 추가 및 템플릿 API senderKey 필수 검증 적용
This commit is contained in:
@@ -33,8 +33,9 @@ public class KkoTemplateApiClient {
|
|||||||
this.externalApiClient = externalApiClient;
|
this.externalApiClient = externalApiClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonNode list(String keyword, String templateStatus) {
|
public JsonNode list(String senderKey, String keyword, String templateStatus) {
|
||||||
Map<String, Object> request = credentials();
|
Map<String, Object> request = credentials();
|
||||||
|
request.put("senderKey", senderKey);
|
||||||
request.put("templateStatus", templateStatus);
|
request.put("templateStatus", templateStatus);
|
||||||
if (keyword == null || keyword.isBlank()) {
|
if (keyword == null || keyword.isBlank()) {
|
||||||
request.put("page", 1);
|
request.put("page", 1);
|
||||||
@@ -45,17 +46,21 @@ public class KkoTemplateApiClient {
|
|||||||
return post("/template/list", request);
|
return post("/template/list", request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonNode detail(String templateCode) {
|
public JsonNode detail(String senderKey, String templateCode) {
|
||||||
Map<String, Object> request = credentials();
|
Map<String, Object> request = credentials();
|
||||||
|
request.put("senderKey", senderKey);
|
||||||
request.put("templateCode", templateCode);
|
request.put("templateCode", templateCode);
|
||||||
return post("/template/detail", request);
|
return post("/template/detail", request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JsonNode profiles() {
|
||||||
|
return post("/profile/use", credentials());
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String, Object> credentials() {
|
private Map<String, Object> credentials() {
|
||||||
Map<String, Object> request = new LinkedHashMap<>();
|
Map<String, Object> request = new LinkedHashMap<>();
|
||||||
request.put("bizId", properties.getBizId());
|
request.put("bizId", properties.getBizId());
|
||||||
request.put("apiKey", properties.getApiKey());
|
request.put("apiKey", properties.getApiKey());
|
||||||
request.put("senderKey", properties.getSenderKey());
|
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ public class KkoTemplateProperties {
|
|||||||
private String bizId;
|
private String bizId;
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String apiKey;
|
private String apiKey;
|
||||||
@NotBlank
|
|
||||||
private String senderKey;
|
|
||||||
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private List<@NotBlank String> templateStatuses;
|
private List<@NotBlank String> templateStatuses;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.kri.common.feature.web.RequestUserContext;
|
|||||||
import com.kri.notihub.server.common.enums.ChannelType;
|
import com.kri.notihub.server.common.enums.ChannelType;
|
||||||
import com.kri.notihub.server.dto.email.EmailAttachmentDto;
|
import com.kri.notihub.server.dto.email.EmailAttachmentDto;
|
||||||
import com.kri.notihub.server.dto.template.KkoTemplateDetailDto;
|
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.KkoTemplateDetailRequestDto;
|
||||||
import com.kri.notihub.server.dto.template.KkoTemplateListRequestDto;
|
import com.kri.notihub.server.dto.template.KkoTemplateListRequestDto;
|
||||||
import com.kri.notihub.server.dto.template.KkoTemplateListResponseDto;
|
import com.kri.notihub.server.dto.template.KkoTemplateListResponseDto;
|
||||||
@@ -46,12 +47,18 @@ public class TemplateController {
|
|||||||
private final FileService fileService;
|
private final FileService fileService;
|
||||||
private final KkoTemplateService kkoTemplateService;
|
private final KkoTemplateService kkoTemplateService;
|
||||||
|
|
||||||
|
@Operation(summary = "사용 가능한 알림톡 발신 프로필 조회")
|
||||||
|
@GetMapping("/kko/profiles")
|
||||||
|
public List<KkoProfileDto> getKkoProfiles() {
|
||||||
|
return kkoTemplateService.getProfiles();
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "외부 알림톡 템플릿 목록 조회")
|
@Operation(summary = "외부 알림톡 템플릿 목록 조회")
|
||||||
@PostMapping(value = "/kko/list", consumes = MediaType.APPLICATION_JSON_VALUE,
|
@PostMapping(value = "/kko/list", consumes = MediaType.APPLICATION_JSON_VALUE,
|
||||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
public KkoTemplateListResponseDto getKkoTemplateList(
|
public KkoTemplateListResponseDto getKkoTemplateList(
|
||||||
@Valid @RequestBody KkoTemplateListRequestDto request) {
|
@Valid @RequestBody KkoTemplateListRequestDto request) {
|
||||||
return kkoTemplateService.getList(request.keyword());
|
return kkoTemplateService.getList(request.senderKey(), request.keyword());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "외부 알림톡 템플릿 상세 조회")
|
@Operation(summary = "외부 알림톡 템플릿 상세 조회")
|
||||||
@@ -59,7 +66,7 @@ public class TemplateController {
|
|||||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
public KkoTemplateDetailDto getKkoTemplateDetail(
|
public KkoTemplateDetailDto getKkoTemplateDetail(
|
||||||
@Valid @RequestBody KkoTemplateDetailRequestDto request) {
|
@Valid @RequestBody KkoTemplateDetailRequestDto request) {
|
||||||
return kkoTemplateService.getDetail(request.templateCode());
|
return kkoTemplateService.getDetail(request.senderKey(), request.templateCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package com.kri.notihub.server.dto.template;
|
||||||
|
|
||||||
|
public record KkoProfileDto(String senderKey, String name, String uuid) {
|
||||||
|
}
|
||||||
@@ -5,6 +5,9 @@ import jakarta.validation.constraints.Pattern;
|
|||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
|
||||||
public record KkoTemplateDetailRequestDto(
|
public record KkoTemplateDetailRequestDto(
|
||||||
|
@NotBlank
|
||||||
|
@Size(max = 40)
|
||||||
|
String senderKey,
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@Size(max = 30)
|
@Size(max = 30)
|
||||||
@Pattern(regexp = "[A-Za-z0-9_-]+")
|
@Pattern(regexp = "[A-Za-z0-9_-]+")
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
package com.kri.notihub.server.dto.template;
|
package com.kri.notihub.server.dto.template;
|
||||||
|
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
|
||||||
public record KkoTemplateListRequestDto(
|
public record KkoTemplateListRequestDto(
|
||||||
|
@NotBlank
|
||||||
|
@Size(max = 40)
|
||||||
|
String senderKey,
|
||||||
@Size(min = 2, max = 50)
|
@Size(min = 2, max = 50)
|
||||||
String keyword
|
String keyword
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -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.common.external.kakao.KkoTemplateApiClient;
|
||||||
import com.kri.notihub.server.config.KkoTemplateProperties;
|
import com.kri.notihub.server.config.KkoTemplateProperties;
|
||||||
import com.kri.notihub.server.dto.template.KkoTemplateDetailDto;
|
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.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.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.List;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -25,7 +27,8 @@ public class KkoTemplateService {
|
|||||||
private final KkoTemplateProperties properties;
|
private final KkoTemplateProperties properties;
|
||||||
private final ObjectMapper objectMapper;
|
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();
|
String normalized = keyword == null || keyword.isBlank() ? null : keyword.trim();
|
||||||
if (normalized != null && (normalized.length() < 2 || normalized.length() > 50)) {
|
if (normalized != null && (normalized.length() < 2 || normalized.length() > 50)) {
|
||||||
throw BusinessException.badRequest("KKO_TEMPLATE_INVALID_KEYWORD",
|
throw BusinessException.badRequest("KKO_TEMPLATE_INVALID_KEYWORD",
|
||||||
@@ -36,7 +39,7 @@ public class KkoTemplateService {
|
|||||||
int totalPage = 0;
|
int totalPage = 0;
|
||||||
int currentPage = 0;
|
int currentPage = 0;
|
||||||
for (String templateStatus : properties.getTemplateStatuses()) {
|
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");
|
JsonNode items = root.path("data").path("list");
|
||||||
if (!items.isArray()) {
|
if (!items.isArray()) {
|
||||||
throw KkoTemplateApiClient.invalidResponse();
|
throw KkoTemplateApiClient.invalidResponse();
|
||||||
@@ -64,11 +67,12 @@ public class KkoTemplateService {
|
|||||||
new ArrayList<>(templates.values()));
|
new ArrayList<>(templates.values()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public KkoTemplateDetailDto getDetail(String templateCode) {
|
public KkoTemplateDetailDto getDetail(String senderKey, String templateCode) {
|
||||||
|
validateSenderKey(senderKey);
|
||||||
validateCode(templateCode);
|
validateCode(templateCode);
|
||||||
JsonNode data = apiClient.detail(templateCode).path("data");
|
JsonNode data = apiClient.detail(senderKey, templateCode).path("data");
|
||||||
if (!templateCode.equals(data.path("templateCode").asText())
|
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").isTextual()
|
||||||
|| data.path("templateContent").asText().isBlank()) {
|
|| data.path("templateContent").asText().isBlank()) {
|
||||||
throw KkoTemplateApiClient.invalidResponse();
|
throw KkoTemplateApiClient.invalidResponse();
|
||||||
@@ -81,7 +85,7 @@ public class KkoTemplateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void synchronize(TemplateBasicDto template) {
|
public void synchronize(TemplateBasicDto template) {
|
||||||
KkoTemplateDetailDto detail = getDetail(template.getKkoTmplatCd());
|
KkoTemplateDetailDto detail = getDetail(template.getSenderKey(), template.getKkoTmplatCd());
|
||||||
validateAvailable(detail);
|
validateAvailable(detail);
|
||||||
validateBasicTextFormat(detail);
|
validateBasicTextFormat(detail);
|
||||||
if (detail.templatePreviewMessage() != null
|
if (detail.templatePreviewMessage() != null
|
||||||
@@ -90,7 +94,6 @@ public class KkoTemplateService {
|
|||||||
}
|
}
|
||||||
template.setTmplatBody(detail.templateContent());
|
template.setTmplatBody(detail.templateContent());
|
||||||
template.setTmplatTitle(detail.templatePreviewMessage());
|
template.setTmplatTitle(detail.templatePreviewMessage());
|
||||||
template.setSenderKey(properties.getSenderKey());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateAvailable(KkoTemplateDetailDto detail) {
|
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) {
|
private static void validateCode(String templateCode) {
|
||||||
if (templateCode == null || !templateCode.matches("[A-Za-z0-9_-]{1,30}")) {
|
if (templateCode == null || !templateCode.matches("[A-Za-z0-9_-]{1,30}")) {
|
||||||
throw BusinessException.badRequest("EMPTY_KKO_TMPLAT_CD",
|
throw BusinessException.badRequest("EMPTY_KKO_TMPLAT_CD",
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ kri:
|
|||||||
username: kriit
|
username: kriit
|
||||||
password: it#51304
|
password: it#51304
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
scheduling:
|
||||||
|
enabled: false
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
|
|||||||
@@ -133,4 +133,3 @@ notihub:
|
|||||||
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
|
||||||
sender-key: 370c42bb833e0e3174ba47a2210ea32850349806
|
|
||||||
|
|||||||
Reference in New Issue
Block a user