-
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.
- Loading branch information
Showing
14 changed files
with
167 additions
and
47 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
14 changes: 9 additions & 5 deletions
14
src/main/java/igoMoney/BE/dto/request/AuthAppleLoginRequest.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 |
---|---|---|
@@ -1,15 +1,19 @@ | ||
package igoMoney.BE.dto.request; | ||
|
||
//import jakarta.validation.constraints.NotNull; | ||
import lombok.*; | ||
|
||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@Getter | ||
@Setter | ||
public class AuthAppleLoginRequest { | ||
|
||
private String id; | ||
private String email; | ||
private String nickname; | ||
private String picture ; | ||
private String state; | ||
private String code; | ||
private String id_token; | ||
private String user; | ||
private String refresh_token; | ||
private Long userId; | ||
private String FCMToken; | ||
} |
18 changes: 0 additions & 18 deletions
18
src/main/java/igoMoney/BE/dto/request/FromAppleService.java
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package igoMoney.BE.service; | ||
|
||
import com.google.firebase.messaging.FirebaseMessaging; | ||
import com.google.firebase.messaging.Message; | ||
import igoMoney.BE.domain.Notification; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.redis.core.StringRedisTemplate; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class FCMTokenService { | ||
|
||
private final StringRedisTemplate tokenRedisTemplate; | ||
|
||
public void sendNotification(Notification notification) { | ||
Long userId = notification.getUser().getId(); | ||
if(!hasKey(userId)){ return;} | ||
String token = getToken(userId); | ||
Message message = Message.builder() | ||
.putData("title", notification.getTitle()) | ||
.putData("content", notification.getMessage()) | ||
.putData("userId", String.valueOf(userId)) | ||
.setToken(token) | ||
.build(); | ||
sendMessage(message); | ||
} | ||
|
||
public void saveToken(Long userId, String FCMToken){ | ||
tokenRedisTemplate.opsForValue() | ||
.set(String.valueOf(userId), FCMToken); | ||
} | ||
|
||
private String getToken(Long userId) { | ||
return tokenRedisTemplate.opsForValue().get(userId); | ||
} | ||
|
||
public void deleteToken(Long userId) { | ||
tokenRedisTemplate.delete(String.valueOf(userId)); | ||
} | ||
|
||
public boolean hasKey(Long userId){ | ||
return tokenRedisTemplate.hasKey(String.valueOf(userId)); | ||
} | ||
|
||
private void sendMessage(Message message) { | ||
FirebaseMessaging.getInstance().sendAsync(message); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/igoMoney/BE/service/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,24 @@ | ||
package igoMoney.BE.service; | ||
|
||
import igoMoney.BE.domain.Notification; | ||
import igoMoney.BE.repository.NotificationRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@Transactional | ||
public class NotificationService { | ||
|
||
private final NotificationRepository notificationRepository; | ||
private final FCMTokenService fcmTokenService; | ||
|
||
public void makeNotification(Notification notification){ | ||
notificationRepository.save(notification); | ||
fcmTokenService.sendNotification(notification); | ||
} | ||
|
||
} |
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
Oops, something went wrong.