Skip to content

Commit

Permalink
[FIX] 슬랙 관련 변수들 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
wlwpfh committed Dec 19, 2023
1 parent 8a28727 commit 589b866
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/main/java/com/sopterm/makeawish/service/WishService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sopterm.makeawish.common.message.slack.SlackErrorMessage;
import com.sopterm.makeawish.common.message.slack.SlackSuccessMessage;
import com.sopterm.makeawish.domain.user.User;
import com.sopterm.makeawish.domain.wish.Wish;
import com.sopterm.makeawish.dto.wish.*;
import com.sopterm.makeawish.external.SlackClient;
import com.sopterm.makeawish.external.SlackWishClient;
import com.sopterm.makeawish.repository.PresentRepository;
import com.sopterm.makeawish.repository.UserRepository;
Expand All @@ -23,10 +24,10 @@
import java.io.IOException;
import java.nio.file.AccessDeniedException;
import java.time.LocalDateTime;
import java.util.Objects;

import static com.sopterm.makeawish.common.Util.convertToDate;
import static com.sopterm.makeawish.common.message.ErrorMessage.*;
import static com.sopterm.makeawish.common.message.slack.SlackField.*;
import static com.sopterm.makeawish.domain.wish.WishStatus.*;
import static java.util.Objects.nonNull;

Expand Down Expand Up @@ -60,7 +61,7 @@ public Long createWish(Long userId, WishRequestDTO requestDTO) {
val wishSlackRequest = createSlackWishRequest(wish);
slackWishClient.postWishMessage(wishSlackRequest.toString());
} catch (RuntimeException e) {
log.error("슬랙 요청이 실패했습니다. : " + e.getMessage());
log.error(SlackErrorMessage.POST_REQUEST_ERROR.getMessage() + e.getMessage());
}
return wishRepository.save(wish).getId();
}
Expand Down Expand Up @@ -185,30 +186,30 @@ private Wish getUserMainWish(User user) {

private JsonNode createSlackWishRequest(Wish wish) {
val rootNode = jsonMapper.createObjectNode();
rootNode.put("text", "새로운 소원이 생성되었어요!");
rootNode.put(TEXT, SlackSuccessMessage.SUCCESS_CREATE_WISH.getMessage());
val blocks = jsonMapper.createArrayNode();

val textField = jsonMapper.createObjectNode();
textField.put("type", "section");
textField.set("text", createTextFieldNode("새로운 소원이 생성되었어요!"));
textField.put(TYPE, SECTION);
textField.set(TEXT, createTextFieldNode(SlackSuccessMessage.SUCCESS_CREATE_WISH.getMessage()));

val contentNode = jsonMapper.createObjectNode();
contentNode.put("type", "section");
contentNode.put(TYPE, SECTION);
val fields = jsonMapper.createArrayNode();
fields.add(createTextFieldNode("*이름:*"+ StringUtils.LF + wish.getWisher().getNickname()));
fields.add(createTextFieldNode("*생일 주간 기간:*"+ StringUtils.LF + wish.getStartAt() + " ~ " + wish.getEndAt()));
contentNode.set("fields", fields);
fields.add(createTextFieldNode(USER_NAME + StringUtils.LF + wish.getWisher().getNickname()));
fields.add(createTextFieldNode(USER_WISH_PERIOD + StringUtils.LF + wish.getStartAt() + " ~ " + wish.getEndAt()));
contentNode.set(FIELDS, fields);

blocks.add(textField);
blocks.add(contentNode);
rootNode.set("blocks", blocks);
rootNode.set(BLOCKS, blocks);
return rootNode;
}

private JsonNode createTextFieldNode (String text) {
val textField = jsonMapper.createObjectNode();
textField.put("type", "mrkdwn");
textField.put("text", text);
textField.put(TYPE, MARKDOWN);
textField.put(TEXT, text);
return textField;
}

Expand Down

0 comments on commit 589b866

Please sign in to comment.