diff --git a/src/main/java/com/moing/backend/domain/mission/application/service/SendMissionCreateAlarmUseCase.java b/src/main/java/com/moing/backend/domain/mission/application/service/SendMissionCreateAlarmUseCase.java index 3edc96e8..b0a82df3 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/service/SendMissionCreateAlarmUseCase.java +++ b/src/main/java/com/moing/backend/domain/mission/application/service/SendMissionCreateAlarmUseCase.java @@ -5,13 +5,16 @@ import com.moing.backend.domain.mission.domain.entity.Mission; 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.event.FcmEvent; import com.moing.backend.global.config.fcm.dto.request.MultiRequest; import com.moing.backend.global.config.fcm.service.FcmService; 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.EventListener; import java.util.List; import java.util.Optional; @@ -24,20 +27,16 @@ public class SendMissionCreateAlarmUseCase { private final TeamMemberGetService teamMemberGetService; - private final FcmService fcmService; + private final ApplicationEventPublisher eventPublisher; public void sendNewMissionUploadAlarm(Member member, Mission mission) { Team team = mission.getTeam(); - Optional> fcmTokensExceptMe = teamMemberGetService.getFcmTokensExceptMe(team.getTeamId(), member.getMemberId()); - String title = team.getName() + " " + NEW_SINGLE_MISSION_COMING.getTitle(); String message = mission.getTitle(); Optional> 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, message, fcmTokens.get())); } } } diff --git a/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepository.java b/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepository.java index ff212d46..89b22d3b 100644 --- a/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepository.java @@ -10,7 +10,6 @@ public interface TeamMemberCustomRepository { List findMemberIdsByTeamId(Long teamId); Optional> findFcmTokensByTeamIdAndMemberId(Long teamId, Long memberId); - Optional> findFcmTokensByTeamId(Long teamId); List findTeamMemberInfoByTeamId(Long teamId); List findTeamMemberByMemberId(Long memberId); } diff --git a/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepositoryImpl.java index b692fcee..7942c58f 100644 --- a/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepositoryImpl.java @@ -37,18 +37,8 @@ public Optional> findFcmTokensByTeamIdAndMemberId(Long teamId, Long .from(teamMember) .where(teamMember.team.teamId.eq(teamId) .and(teamMember.member.isNewUploadPush.eq(true)) - .and(teamMember.member.memberId.ne(memberId))) - .fetch(); - - return result.isEmpty() ? Optional.empty() : Optional.of(result); - } - - @Override - public Optional> findFcmTokensByTeamId(Long teamId) { - List result = queryFactory.select(teamMember.member.fcmToken) - .from(teamMember) - .where(teamMember.team.teamId.eq(teamId) - .and(teamMember.member.isNewUploadPush.eq(true))) + .and(teamMember.member.memberId.ne(memberId)) + .and(teamMember.isDeleted.eq(false))) .fetch(); return result.isEmpty() ? Optional.empty() : Optional.of(result); diff --git a/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberGetService.java b/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberGetService.java index 138d8d0f..2b9dfee2 100644 --- a/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberGetService.java +++ b/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberGetService.java @@ -29,10 +29,6 @@ public Optional> getFcmTokensExceptMe(Long teamId, Long memberId) { return teamMemberRepository.findFcmTokensByTeamIdAndMemberId(teamId, memberId); } - public Optional> getFcmTokens(Long teamId) { - return teamMemberRepository.findFcmTokensByTeamId(teamId); - } - public List getTeamMemberInfo(Long teamId){ return teamMemberRepository.findTeamMemberInfoByTeamId(teamId); }