-
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: #39 notification service 내 send notification 정의
- Loading branch information
1 parent
49f5bc4
commit f047af4
Showing
5 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
fitapet-infra/src/main/java/kr/co/fitapet/infra/client/fcm/FcmNotificationServiceImpl.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,25 @@ | ||
package kr.co.fitapet.infra.client.fcm; | ||
|
||
import com.google.firebase.messaging.FirebaseMessaging; | ||
import com.google.firebase.messaging.FirebaseMessagingException; | ||
import com.google.firebase.messaging.Message; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class FcmNotificationServiceImpl implements NotificationService { | ||
private final FirebaseMessaging firebaseMessaging; | ||
|
||
@Override | ||
public void sendNotification(NotificationRequest request) throws FirebaseMessagingException { | ||
Message message = Message.builder() | ||
.setToken(request.token()) | ||
.setNotification(request.toNotification()) | ||
.build(); | ||
|
||
firebaseMessaging.send(message); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
fitapet-infra/src/main/java/kr/co/fitapet/infra/client/fcm/NotificationRequest.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,34 @@ | ||
package kr.co.fitapet.infra.client.fcm; | ||
|
||
import com.google.firebase.messaging.Notification; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record NotificationRequest( | ||
String token, | ||
String title, | ||
String body | ||
) { | ||
public NotificationRequest { | ||
if (token == null || token.isBlank()) { | ||
throw new IllegalArgumentException("token must not be null or empty"); | ||
} | ||
if (title == null || title.isBlank()) { | ||
throw new IllegalArgumentException("title must not be null or empty"); | ||
} | ||
if (body == null || body.isBlank()) { | ||
throw new IllegalArgumentException("body must not be null or empty"); | ||
} | ||
} | ||
|
||
public static NotificationRequest valueOf(String token, String title, String body) { | ||
return new NotificationRequest(token, title, body); | ||
} | ||
|
||
public Notification toNotification() { | ||
return Notification.builder() | ||
.setTitle(title) | ||
.setBody(body) | ||
.build(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
fitapet-infra/src/main/java/kr/co/fitapet/infra/client/fcm/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,7 @@ | ||
package kr.co.fitapet.infra.client.fcm; | ||
|
||
import com.google.firebase.messaging.FirebaseMessagingException; | ||
|
||
public interface NotificationService { | ||
void sendNotification(NotificationRequest request) throws FirebaseMessagingException; | ||
} |
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