Skip to content

Commit

Permalink
[FEAT] 템플릿 가져오기 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
wlwpfh committed Nov 5, 2024
1 parent af8788c commit 359a172
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/sopterm/makeawish/domain/AlarmTemplate.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sopterm.makeawish.domain;

import io.micrometer.common.util.StringUtils;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand Down Expand Up @@ -36,4 +37,16 @@ public class AlarmTemplate {

@Column(name = "template_name")
private String name;

public String replaceContent(String...params){
if(StringUtils.isEmpty(variables)){
return content;
}
int index = 0;
String[] replaceWords = variables.split(",");
for(String param: params) {
content = content.replace(replaceWords[index], param);
}
return content;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public record AlarmRequestDTO(
, String altSendType
, KakaoButton[] kakaoButtons
) {
public static AlarmRequestDTO of(AlarmTemplate alarmTemplate){
public static AlarmRequestDTO of(AlarmTemplate alarmTemplate, String...params){
KakaoButton[] buttons = initButtons(alarmTemplate.getButton(), "WL" ,alarmTemplate.getButtonUrl());
return AlarmRequestDTO.builder()
.code(alarmTemplate.getCode())
.content(alarmTemplate.getContent())
.content(alarmTemplate.replaceContent(params))
.altSubject(StringUtils.EMPTY)
.altContent(StringUtils.EMPTY)
.altSendType("C")
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/sopterm/makeawish/service/AlarmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public class AlarmService {
private final AlarmRepository alarmRepository;

@Transactional
public void sendAlarmTalk(User user, String templateName) {
public void sendAlarmTalk(User user, String templateName, String...params) {
if(isUseKkoTalk.equals("false")) {
return;
}
AlarmRequestDTO template = AlarmRequestDTO.of(findByTemplateName(templateName));
AlarmRequestDTO template = AlarmRequestDTO.of(findByTemplateName(templateName), params);
try {
String response = kakaoService.sendATS(corpNum, template.code(), senderNum, template.content(), template.altSubject(), template.altContent(), template.altSendType() ,user.getPhoneNumber(), user.getNickname(), Util.getCurrentTime(), linkId, user.getId()+"_"+ templateName + Util.getCurrentTime(), template.kakaoButtons());
} catch(PopbillException e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public Long createWish(Long userId, WishRequestDTO requestDTO) {
}
Long wishId = wishRepository.save(wish).getId();
presentRepository.save(Present.initAdminPresent(wish));
alarmService.sendAlarmTalk(wisher, "CREATE_WISH");
alarmService.sendAlarmTalk(wisher, "CREATE_WISH", wisher.getNickname());
return wishId;
}

Expand Down

0 comments on commit 359a172

Please sign in to comment.