-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
YEL-88 [feat] 푸시 알림 구현
- Loading branch information
Showing
35 changed files
with
516 additions
and
67 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
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
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
14 changes: 12 additions & 2 deletions
14
src/main/java/com/yello/server/domain/vote/dto/response/VoteCreateResponse.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
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
44 changes: 44 additions & 0 deletions
44
...in/java/com/yello/server/infrastructure/firebase/configuration/FirebaseConfiguration.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,44 @@ | ||
package com.yello.server.infrastructure.firebase.configuration; | ||
|
||
import com.google.auth.oauth2.GoogleCredentials; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.FirebaseOptions; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import javax.annotation.PostConstruct; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.ClassPathResource; | ||
|
||
@Log4j2 | ||
@Configuration | ||
public class FirebaseConfiguration { | ||
|
||
@Value("${firebase.config-path}") | ||
private String firebaseConfigPath; | ||
|
||
@Value("${firebase.scope}") | ||
private String scope; | ||
|
||
@PostConstruct | ||
public void initialize() throws IOException { | ||
ClassPathResource resource = new ClassPathResource(firebaseConfigPath); | ||
|
||
try (InputStream inputStream = resource.getInputStream()) { | ||
FirebaseOptions options = FirebaseOptions.builder() | ||
.setCredentials(GoogleCredentials.fromStream(inputStream)) | ||
.build(); | ||
|
||
if (FirebaseApp.getApps().isEmpty()) { | ||
FirebaseApp.initializeApp(options); | ||
log.info("Successfully firebase application initialized!"); | ||
} | ||
} catch (FileNotFoundException e) { | ||
log.error("Firebase ServiceAccountKey FileNotFoundException" + e.getMessage()); | ||
} catch (IOException e) { | ||
log.error("FirebaseOptions IOException" + e.getMessage()); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/yello/server/infrastructure/firebase/dto/request/NotificationMessage.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,43 @@ | ||
package com.yello.server.infrastructure.firebase.dto.request; | ||
|
||
import com.google.firebase.messaging.Notification; | ||
import com.yello.server.domain.user.entity.Gender; | ||
import com.yello.server.domain.user.entity.User; | ||
import java.text.MessageFormat; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record NotificationMessage( | ||
String title, | ||
String message | ||
) { | ||
|
||
public static NotificationMessage toVoteAvailableNotificationContent() { | ||
return NotificationMessage.builder() | ||
.title("친구에게 쪽지 보내고 포인트 받기") | ||
.message("대기시간이 다 지났어요. 친구들에게 투표해봐요!") | ||
.build(); | ||
} | ||
|
||
public static NotificationMessage toFriendNotificationContent(User user) { | ||
return NotificationMessage.builder() | ||
.title(MessageFormat.format("{0}님이 회원님과 친구가 되었어요", user.getName())) | ||
.message("친구와 쪽지를 주고받아 보세요!") | ||
.build(); | ||
} | ||
|
||
public static NotificationMessage toYelloNotificationContent(User user) { | ||
final String target = Gender.MALE.getIntial().equals(user.getGender().getIntial()) ? "남학생" : "여학생"; | ||
return NotificationMessage.builder() | ||
.title(MessageFormat.format("{0}이 쪽지를 보냈어요!", target)) | ||
.message("나는 너가 ...") | ||
.build(); | ||
} | ||
|
||
public Notification toNotification() { | ||
return Notification.builder() | ||
.setTitle(title) | ||
.setBody(message) | ||
.build(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/yello/server/infrastructure/firebase/manager/FCMManager.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.yello.server.infrastructure.firebase.manager; | ||
|
||
import com.google.firebase.messaging.Message; | ||
import com.google.firebase.messaging.Notification; | ||
|
||
public interface FCMManager { | ||
|
||
void send(Message message); | ||
|
||
Message createMessage(String deviceToken, Notification notification); | ||
|
||
Message createMessage(String deviceToken, Notification notification, String path); | ||
|
||
} |
Oops, something went wrong.