-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notification): add push notification feature (#167)
* build(gradle): add expo-server-sdk dependency * feat(notification): add push notification sending service * feat(notification): modify meeting events to include push notification events * feat(notification): add scheduler for recommended push notifications * test(notification): add notification scheduler test * test(notification): add NotificationHandleServiceTest * test(notification): add NotificationServiceTest * test(notification): rename NotificationServiceTest functions * fix(notification): modify query's where condition * test(notification): add PushTokenRepositoryTest * chore: add jackson dependencies * docs: add swagger api --------- Co-authored-by: KAispread <[email protected]>
- Loading branch information
1 parent
6e85e09
commit 1efbe26
Showing
20 changed files
with
621 additions
and
146 deletions.
There are no files selected for viewing
This file contains 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
10 changes: 10 additions & 0 deletions
10
src/main/java/com/e2i/wemeet/config/common/SchedulerConfig.java
This file contains 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,10 @@ | ||
package com.e2i.wemeet.config.common; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
|
||
@Configuration | ||
@EnableScheduling | ||
public class SchedulerConfig { | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/e2i/wemeet/config/notification/NotificationConfig.java
This file contains 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,15 @@ | ||
package com.e2i.wemeet.config.notification; | ||
|
||
import io.github.jav.exposerversdk.PushClient; | ||
import io.github.jav.exposerversdk.PushClientException; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class NotificationConfig { | ||
|
||
@Bean | ||
public PushClient pushClient() throws PushClientException { | ||
return new PushClient(); | ||
} | ||
} |
This file contains 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 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 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 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
18 changes: 18 additions & 0 deletions
18
src/main/java/com/e2i/wemeet/service/notification/NotificationHandleService.java
This file contains 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,18 @@ | ||
package com.e2i.wemeet.service.notification; | ||
|
||
|
||
import java.util.List; | ||
|
||
public interface NotificationHandleService { | ||
|
||
/* | ||
* Body 미포함 푸시 알림 전송 | ||
*/ | ||
void sendPushNotification(List<String> tokens, String title); | ||
|
||
/* | ||
* Body 포함 푸시 알림 전송 | ||
*/ | ||
void sendPushNotification(List<String> tokens, String title, String body); | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/e2i/wemeet/service/notification/NotificationHandleServiceImpl.java
This file contains 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,38 @@ | ||
package com.e2i.wemeet.service.notification; | ||
|
||
import io.github.jav.exposerversdk.ExpoPushMessage; | ||
import io.github.jav.exposerversdk.PushClient; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class NotificationHandleServiceImpl implements NotificationHandleService { | ||
|
||
private final PushClient client; | ||
|
||
@Override | ||
public void sendPushNotification(List<String> tokens, String title) { | ||
sendPushNotification(tokens, title, null); | ||
} | ||
|
||
@Override | ||
public void sendPushNotification(List<String> tokens, String title, String body) { | ||
ExpoPushMessage expoPushMessage = createExpoPushMessage(tokens, title, body); | ||
client.sendPushNotificationsAsync(List.of(expoPushMessage)); | ||
} | ||
|
||
private ExpoPushMessage createExpoPushMessage(List<String> tokens, String title, String body) { | ||
ExpoPushMessage expoPushMessage = new ExpoPushMessage(); | ||
expoPushMessage.setTo(tokens); | ||
expoPushMessage.setTitle(title); | ||
|
||
if (body != null && !body.isBlank()) { | ||
expoPushMessage.setBody(body); | ||
} | ||
|
||
return expoPushMessage; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/e2i/wemeet/service/notification/NotificationScheduler.java
This file contains 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,22 @@ | ||
package com.e2i.wemeet.service.notification; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class NotificationScheduler { | ||
|
||
private final NotificationService notificationService; | ||
private static final String TITLE = "기다리고 기다리던 11시 11분이야!"; | ||
private static final String BODY = "오늘의 추천 친구들을 확인해 봐! 🤩"; | ||
|
||
// 매일 23시 11분에 실행 | ||
@Scheduled(cron = "0 11 23 * * ?") | ||
public void sendPushNotificationForSuggestion() { | ||
notificationService.sendToAllMembers(TITLE, BODY); | ||
} | ||
} | ||
|
||
|
14 changes: 14 additions & 0 deletions
14
src/main/java/com/e2i/wemeet/service/notification/NotificationService.java
This file contains 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,14 @@ | ||
package com.e2i.wemeet.service.notification; | ||
|
||
public interface NotificationService { | ||
|
||
/* | ||
* 전체 사용자 푸시 알림 전송 | ||
*/ | ||
void sendToAllMembers(String title, String body); | ||
|
||
/* | ||
* 팀이 없는 사용자 푸시 알림 전송 | ||
*/ | ||
void sendToMembersWithoutTeam(String title, String body); | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/e2i/wemeet/service/notification/NotificationServiceImpl.java
This file contains 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,26 @@ | ||
package com.e2i.wemeet.service.notification; | ||
|
||
import com.e2i.wemeet.domain.notification.PushTokenRepository; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class NotificationServiceImpl implements NotificationService { | ||
|
||
private final NotificationHandleService notificationHandleService; | ||
private final PushTokenRepository pushTokenRepository; | ||
|
||
@Override | ||
public void sendToAllMembers(String title, String body) { | ||
List<String> tokens = pushTokenRepository.findAllMemberTokens(); | ||
notificationHandleService.sendPushNotification(tokens, title, body); | ||
} | ||
|
||
@Override | ||
public void sendToMembersWithoutTeam(String title, String body) { | ||
List<String> tokens = pushTokenRepository.findTokensOfMemberWithoutTeam(); | ||
notificationHandleService.sendPushNotification(tokens, title, body); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/e2i/wemeet/service/notification/event/NotificatioEventService.java
This file contains 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,9 @@ | ||
package com.e2i.wemeet.service.notification.event; | ||
|
||
public interface NotificatioEventService { | ||
|
||
/* | ||
* 이벤트 전용 푸시 알림 전송 | ||
*/ | ||
void sendForNotificationEvent(NotificationEvent notificationEvent); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/e2i/wemeet/service/notification/event/NotificationEvent.java
This file contains 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,8 @@ | ||
package com.e2i.wemeet.service.notification.event; | ||
|
||
public record NotificationEvent(String token, String title) { | ||
|
||
public static NotificationEvent of(String token, String title) { | ||
return new NotificationEvent(token, title); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/e2i/wemeet/service/notification/event/NotificationEventServiceImpl.java
This file contains 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,31 @@ | ||
package com.e2i.wemeet.service.notification.event; | ||
|
||
import com.e2i.wemeet.service.meeting.MeetingEvent; | ||
import com.e2i.wemeet.service.notification.NotificationHandleService; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class NotificationEventServiceImpl implements NotificatioEventService { | ||
|
||
private final NotificationHandleService notificationHandleService; | ||
|
||
@EventListener(classes = MeetingEvent.class) | ||
public void sendForNotificationEvent(final MeetingEvent event) { | ||
sendForNotificationEvent(event.notificationEvent()); | ||
} | ||
|
||
@EventListener(classes = NotificationEvent.class) | ||
@Override | ||
public void sendForNotificationEvent(final NotificationEvent notificationEvent) { | ||
if (notificationEvent.token() == null) { | ||
return; | ||
} | ||
|
||
notificationHandleService.sendPushNotification(List.of(notificationEvent.token()), | ||
notificationEvent.title()); | ||
} | ||
} |
Oops, something went wrong.