-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT] FCM 푸시 알림 및 이메일 알림 기본 설계 구현 #340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0712cfc
feat(#218): FCM 푸시 알림 및 이메일 알림 기본 설계 구현
1000hyehyang 4895f10
Merge branch 'dev' into feat/218-notification
1000hyehyang e93073a
chore(#218): pr-check 더미 환경변수 추가
1000hyehyang 139748d
fix(#218): 코드리뷰 반영
1000hyehyang f61e3a3
fix(#218): HTML Injection 방지
1000hyehyang c4fdd0a
chore(#218): 이메일 알림 버튼 색상 변경
1000hyehyang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/example/RealMatch/business/application/event/AutoConfirmedEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.example.RealMatch.business.application.event; | ||
|
|
||
| /** | ||
| * 캠페인이 자동으로 확정되었을 때 발행되는 이벤트 | ||
| */ | ||
| public record AutoConfirmedEvent( | ||
| Long campaignId, | ||
| Long brandUserId, | ||
| Long creatorUserId, | ||
| String campaignName | ||
| ) { | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/example/RealMatch/business/application/event/CampaignCompletedEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.example.RealMatch.business.application.event; | ||
|
|
||
| /** | ||
| * 캠페인이 완료되었을 때 발행되는 이벤트 | ||
| */ | ||
| public record CampaignCompletedEvent( | ||
| Long campaignId, | ||
| Long brandUserId, | ||
| Long creatorUserId, | ||
| String campaignName | ||
| ) { | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/example/RealMatch/business/application/event/SettlementReadyEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.example.RealMatch.business.application.event; | ||
|
|
||
| /** | ||
| * 정산이 가능한 상태가 되었을 때 발행되는 이벤트 | ||
| */ | ||
| public record SettlementReadyEvent( | ||
| Long campaignId, | ||
| Long creatorUserId, | ||
| Long brandUserId, | ||
| String campaignName, | ||
| Long settlementAmount | ||
| ) { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/com/example/RealMatch/notification/application/service/FcmTokenService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.example.RealMatch.notification.application.service; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import com.example.RealMatch.notification.domain.entity.FcmToken; | ||
| import com.example.RealMatch.notification.domain.repository.FcmTokenRepository; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| public class FcmTokenService { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(FcmTokenService.class); | ||
|
|
||
| private final FcmTokenRepository fcmTokenRepository; | ||
|
|
||
| /** | ||
| * FCM 토큰을 등록한다. | ||
| * 동일한 토큰이 이미 존재하면 소유자를 현재 유저로 재할당한다 (디바이스 로그아웃→재로그인 대응). | ||
| */ | ||
| public void registerToken(Long userId, String token, String deviceInfo) { | ||
| Optional<FcmToken> existing = fcmTokenRepository.findByToken(token); | ||
|
|
||
| if (existing.isPresent()) { | ||
| FcmToken fcmToken = existing.get(); | ||
| if (!fcmToken.getUserId().equals(userId)) { | ||
| fcmToken.reassignTo(userId); | ||
| LOG.info("[FCM] Token reassigned. token={}..., newUserId={}", token.substring(0, Math.min(token.length(), 10)), userId); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| FcmToken fcmToken = FcmToken.builder() | ||
| .userId(userId) | ||
| .token(token) | ||
| .deviceInfo(deviceInfo) | ||
| .build(); | ||
| fcmTokenRepository.save(fcmToken); | ||
| LOG.info("[FCM] Token registered. userId={}, deviceInfo={}", userId, deviceInfo); | ||
| } | ||
|
|
||
| /** | ||
| * FCM 토큰을 삭제한다 (로그아웃 시 호출). | ||
| */ | ||
| public void removeToken(String token) { | ||
| fcmTokenRepository.deleteByToken(token); | ||
| LOG.info("[FCM] Token removed. token={}...", token.substring(0, Math.min(10, token.length()))); | ||
| } | ||
|
|
||
| /** | ||
| * 유저의 모든 FCM 토큰을 삭제한다 (회원 탈퇴 시 호출). | ||
| */ | ||
| public void removeAllTokensByUserId(Long userId) { | ||
| fcmTokenRepository.deleteByUserId(userId); | ||
| LOG.info("[FCM] All tokens removed. userId={}", userId); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.