Skip to content

Commit

Permalink
#323 [refactor] fcm, slack 관련 서비스 알림 모듈로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
orijoon98 committed Apr 28, 2023
1 parent 035b099 commit 26e0000
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hous.api.service.firebase;
package hous.notification.service.firebase;

import static hous.common.exception.ErrorCode.*;

Expand All @@ -11,12 +11,12 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.auth.oauth2.GoogleCredentials;

import hous.api.service.firebase.dto.request.FcmMessage;
import hous.api.service.jwt.JwtService;
import hous.common.exception.InternalServerException;
import hous.common.util.HttpHeaderUtils;
import hous.common.util.JwtUtils;
import hous.core.domain.user.User;
import hous.external.client.firebase.FirebaseApiClient;
import hous.notification.service.firebase.dto.request.FcmMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -30,15 +30,15 @@ public class FirebaseCloudMessageService {

private final ObjectMapper objectMapper;
private final FirebaseApiClient firebaseApiCaller;
private final JwtService jwtService;
private final JwtUtils jwtUtils;

public void sendMessageTo(User to, String title, String body) {
try {
String targetToken = to.getFcmToken();
String message = makeMessage(targetToken, title, body);
firebaseApiCaller.requestFcmMessaging(HttpHeaderUtils.withBearerToken(getAccessToken()), message);
} catch (Exception exception) {
jwtService.expireRefreshToken(to.getId());
jwtUtils.expireRefreshToken(to.getId());
to.resetFcmToken();
log.error(exception.getMessage(), exception);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hous.api.service.firebase.dto.request;
package hous.notification.service.firebase.dto.request;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hous.api.service.slack;
package hous.notification.service.slack;

import java.io.IOException;
import java.util.List;
Expand All @@ -11,7 +11,7 @@
import com.slack.api.model.Attachment;
import com.slack.api.model.block.LayoutBlock;

import hous.api.service.slack.dto.response.UserDeleteResponse;
import hous.notification.service.slack.dto.response.UserDeleteResponse;
import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package hous.api.service.slack;
package hous.notification.service.slack;

import static com.slack.api.model.block.Blocks.*;
import static com.slack.api.model.block.composition.BlockCompositions.*;

import java.util.ArrayList;
import java.util.List;

import com.slack.api.model.Attachment;
import com.slack.api.model.block.Blocks;
import com.slack.api.model.block.LayoutBlock;
import com.slack.api.model.block.composition.BlockCompositions;
import com.slack.api.model.block.composition.TextObject;

import hous.api.service.slack.dto.response.UserDelete;
import hous.api.service.slack.dto.response.UserDeleteResponse;
import hous.notification.service.slack.dto.response.UserDelete;
import hous.notification.service.slack.dto.response.UserDeleteResponse;

public class SlackServiceUtils {

Expand All @@ -33,7 +34,7 @@ public static List<Attachment> createAttachments(String color, List<LayoutBlock>

public static List<LayoutBlock> createUserDeleteMessage(UserDeleteResponse userDeleteResponse) {
List<LayoutBlock> layoutBlockList = new ArrayList<>();
layoutBlockList.add(section(section ->
layoutBlockList.add(Blocks.section(section ->
section.text(
markdownText(PROD_USER_DELETE_TOTAL_COUNT_MESSAGE + userDeleteResponse.getTotalDeleteUserCount()))));

Expand All @@ -42,11 +43,11 @@ public static List<LayoutBlock> createUserDeleteMessage(UserDeleteResponse userD
stringBuilder.append(userDelete.toString());
stringBuilder.append('\n');
}
layoutBlockList.add(section(section ->
section.text(markdownText(PROD_USER_DELETE_MESSAGE + stringBuilder.toString()))));
layoutBlockList.add(Blocks.section(section ->
section.text(BlockCompositions.markdownText(PROD_USER_DELETE_MESSAGE + stringBuilder.toString()))));

if (!userDeleteResponse.getComment().isBlank()) {
layoutBlockList.add(section(section ->
layoutBlockList.add(Blocks.section(section ->
section.text(markdownText(PROD_NOW_USER_DELETE_COMMENT + userDeleteResponse.getComment()))));
}

Expand All @@ -59,12 +60,13 @@ public static List<LayoutBlock> createProdErrorMessage(Exception exception) {
List<LayoutBlock> layoutBlockList = new ArrayList<>();

List<TextObject> sectionInFields = new ArrayList<>();
sectionInFields.add(markdownText(PROD_ERROR_MESSAGE + exception.getMessage()));
sectionInFields.add(markdownText(PROD_ERROR_STACK + exception));
layoutBlockList.add(section(section -> section.fields(sectionInFields)));
sectionInFields.add(BlockCompositions.markdownText(PROD_ERROR_MESSAGE + exception.getMessage()));
sectionInFields.add(BlockCompositions.markdownText(PROD_ERROR_STACK + exception));
layoutBlockList.add(Blocks.section(section -> section.fields(sectionInFields)));

layoutBlockList.add(divider());
layoutBlockList.add(section(section -> section.text(markdownText(filterErrorStack(stacks)))));
layoutBlockList.add(Blocks.divider());
layoutBlockList.add(
Blocks.section(section -> section.text(BlockCompositions.markdownText(filterErrorStack(stacks)))));
return layoutBlockList;
}

Expand Down

0 comments on commit 26e0000

Please sign in to comment.