Skip to content

Commit

Permalink
Merge pull request #96 from Modagbul/feat/alarm_minsu
Browse files Browse the repository at this point in the history
fix: 공지 알림 문구 수정
  • Loading branch information
minsu20 authored Nov 29, 2023
2 parents b23bcd1 + e76f9e0 commit 89acd6c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,36 @@
import com.moing.backend.domain.member.domain.entity.Member;
import com.moing.backend.domain.team.domain.entity.Team;
import com.moing.backend.domain.teamMember.domain.service.TeamMemberGetService;
import com.moing.backend.global.config.fcm.dto.request.MultiRequest;
import com.moing.backend.global.config.fcm.service.FcmService;
import com.moing.backend.global.config.fcm.dto.event.FcmEvent;
import com.moing.backend.global.response.BaseServiceResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;

import static com.moing.backend.global.config.fcm.constant.NewUploadTitle.UPLOAD_NOTICE_NEW_TITLE;
import static com.moing.backend.global.config.fcm.constant.NewNoticeUploadMessage.NEW_NOTICE_UPLOAD_MESSAGE;

@Service
@RequiredArgsConstructor
@Transactional
public class SendBoardAlarmUseCase {

private final TeamMemberGetService teamMemberGetService;
private final FcmService fcmService;
private final ApplicationEventPublisher eventPublisher;

public void sendNewUploadAlarm(BaseServiceResponse baseServiceResponse, Board board) {
Member member = baseServiceResponse.getMember();
Team team = baseServiceResponse.getTeam();

if (board.isNotice() && member.isNewUploadPush()) {
String title = team.getName() + " " + UPLOAD_NOTICE_NEW_TITLE.getTitle();
String message = board.getTitle();
String title = NEW_NOTICE_UPLOAD_MESSAGE.title(team.getName());
String body = NEW_NOTICE_UPLOAD_MESSAGE.body(board.getTitle());
Optional<List<String>> fcmTokens = teamMemberGetService.getFcmTokensExceptMe(team.getTeamId(), member.getMemberId());
if (fcmTokens.isPresent() && !fcmTokens.get().isEmpty()) {
MultiRequest toMultiRequest = new MultiRequest(fcmTokens.get(), title, message);
fcmService.sendMultipleDevices(toMultiRequest);
eventPublisher.publishEvent(new FcmEvent(title, body, fcmTokens.get()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.moing.backend.global.config.fcm.constant;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum NewNoticeUploadMessage {

NEW_NOTICE_UPLOAD_MESSAGE("%s에 새로 올라온 공지를 확인하세요!", "%s");

private final String title;
private final String body;

public String title(String teamName) {
return String.format(title, teamName);
}

public String body(String noticeTitle) {
return String.format(title, noticeTitle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.moing.backend.global.config.fcm.exception.NotificationException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
Expand All @@ -23,6 +25,7 @@ public class FcmService {
private final FirebaseMessaging firebaseMessaging;


@Retryable(value = FirebaseMessagingException.class, maxAttempts = 3, backoff = @Backoff(delay = 1000))
public SingleResponse sendSingleDevice(SingleRequest toSingleRequest) {

Notification notification = Notification.builder()
Expand Down Expand Up @@ -67,6 +70,7 @@ public SingleResponse sendSingleDevice(SingleRequest toSingleRequest) {
}


@Retryable(value = FirebaseMessagingException.class, maxAttempts = 3, backoff = @Backoff(delay = 1000))
public MultiResponse sendMultipleDevices(MultiRequest toMultiRequest) {

Notification notification = Notification.builder()
Expand Down

0 comments on commit 89acd6c

Please sign in to comment.