Skip to content

Commit

Permalink
feat: notification에 연결 url 컬럼 추가 #211
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbonai06 committed Sep 9, 2022
1 parent 8966440 commit 615b3e4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ public CommonResponse<String> allSendNotification(
.forEach(user -> {
if (user.getNoticeOptIn()) {
expoNotificationService.sendMessage(user, title, message,
allSendNotificationRequest.getNewMap(), notificationCategory);
allSendNotificationRequest.getNewMap(), notificationCategory, "/");
} else {
Notification notification = Notification.builder().user(user).title(title)
.message(message).notificationCategory(notificationCategory).build();
.message(message).notificationCategory(notificationCategory).linkUrl("/")
.build();
notificationRepository.save(notification);
}
});
Expand Down Expand Up @@ -126,10 +127,10 @@ public void notification(Challenge challenge, User authUser) {
newMap.put("userId", authUser.getId());
NotificationCategory notificationCategory = NotificationCategory.CHALLENGE;
Boolean checkServiceOptIn = checkServiceOptIn(authUser, title, notificationBody,
notificationCategory);
notificationCategory, "/");
if (checkServiceOptIn) {
expoNotificationService.sendMessage(authUser, title, notificationBody, newMap,
notificationCategory);
notificationCategory, "/");
}
log.info("유저 {}의 돈길 {}의 {} 상태변경 알림", authUser.getId(), challenge.getId(),
challenge.getChallengeStatus());
Expand All @@ -145,10 +146,10 @@ public void userLevelUpMinusOne(User authUser) {
newMap.put("userId", authUser.getId());
NotificationCategory notificationCategory = NotificationCategory.LEVEL;
Boolean checkServiceOptIn = checkServiceOptIn(authUser, title, notificationBody,
notificationCategory);
notificationCategory, "/mypage");
if (checkServiceOptIn) {
expoNotificationService.sendMessage(authUser, title, notificationBody, newMap,
notificationCategory);
notificationCategory, "/mypage");
}
log.info("유저 id = {}의 레벨업 직전 알림", authUser.getId());
}
Expand All @@ -164,10 +165,10 @@ public void userLevelUpHalf(User authUser) {
newMap.put("userId", authUser.getId());
NotificationCategory notificationCategory = NotificationCategory.LEVEL;
Boolean checkServiceOptIn = checkServiceOptIn(authUser, title, notificationBody,
notificationCategory);
notificationCategory, "/mypage");
if (checkServiceOptIn) {
expoNotificationService.sendMessage(authUser, title, notificationBody, newMap,
notificationCategory);
notificationCategory, "/mypage");
}
log.info("유저 id = {}의 레벨업 절반 달성 알림", authUser.getId());
}
Expand All @@ -184,10 +185,10 @@ public void createPendingChallengeNotification(User contractUser, ChallengeUser
newMap.put("challenge", challengeUser.getChallenge().getId());
NotificationCategory notificationCategory = NotificationCategory.CHALLENGE;
Boolean checkServiceOptIn = checkServiceOptIn(contractUser, title, notificationBody,
notificationCategory);
notificationCategory, "");
if (checkServiceOptIn) {
expoNotificationService.sendMessage(contractUser, title, notificationBody, newMap,
notificationCategory);
notificationCategory, "");
}
log.info("부모 유저 id = {}에게 유저 id = {} 돈길 id = {} 의 돈길 제안", contractUser.getId(),
challengeUser.getUser().getId(), challengeUser.getChallenge().getId());
Expand All @@ -205,10 +206,10 @@ public void runProgressNotification(User contractUser, ChallengeUser challengeUs
newMap.put("challenge", challengeUser.getChallenge().getId());
NotificationCategory notificationCategory = NotificationCategory.CHALLENGE;
Boolean checkServiceOptIn = checkServiceOptIn(contractUser, title, notificationBody,
notificationCategory);
notificationCategory, "/");
if (checkServiceOptIn) {
expoNotificationService.sendMessage(contractUser, title, notificationBody, newMap,
notificationCategory);
notificationCategory, "/");
}
log.info("부모 유저 id = {}에게 유저 id = {}의 돈길 id = {} 돈길 걷기 알림 전송", contractUser.getId(),
challengeUser.getUser().getId(), challengeUser.getChallenge().getId());
Expand All @@ -227,10 +228,10 @@ public void achieveChallengeNotification(User contractUser, ChallengeUser challe
newMap.put("challenge", challengeUser.getChallenge().getId());
NotificationCategory notificationCategory = NotificationCategory.CHALLENGE;
Boolean checkServiceOptIn = checkServiceOptIn(contractUser, title, notificationBody,
notificationCategory);
notificationCategory, "/");
if (checkServiceOptIn) {
expoNotificationService.sendMessage(contractUser, title, notificationBody, newMap,
notificationCategory);
notificationCategory, "/");
}
log.info("부모 유저 id = {}에게 유저 id = {}의 돈길 id = {} 돈길 완주 알림 전송", contractUser.getId(),
challengeUser.getUser().getId(), challengeUser.getChallenge().getId());
Expand All @@ -247,10 +248,10 @@ public void kidLevelUpNotification(User contractUser, User user, Long level, Lon
newMap.put("user", user.getId());
NotificationCategory notificationCategory = NotificationCategory.LEVEL;
Boolean checkServiceOptIn = checkServiceOptIn(contractUser, title, notificationBody,
notificationCategory);
notificationCategory, "");
if (checkServiceOptIn) {
expoNotificationService.sendMessage(contractUser, title, notificationBody, newMap,
notificationCategory);
notificationCategory, "");
}
log.info("부모 유저 id = {}에게 유저 id = {}의 레벨업 알림 전송", contractUser.getId(), user.getId());
}
Expand All @@ -266,10 +267,10 @@ public void challengeFailedNotification(User contractUser, ChallengeUser challen
newMap.put("challenge", challengeUser.getChallenge().getId());
NotificationCategory notificationCategory = NotificationCategory.CHALLENGE;
Boolean checkServiceOptIn = checkServiceOptIn(contractUser, title, notificationBody,
notificationCategory);
notificationCategory, "/");
if (checkServiceOptIn) {
expoNotificationService.sendMessage(contractUser, title, notificationBody, newMap,
notificationCategory);
notificationCategory, "/");
}
log.info("부모 유저 id = {}에게 유저 id = {}의 돈길 id = {} 돈길 실패 알림 전송", contractUser.getId(),
challengeUser.getChallenge().getId(), challengeUser.getChallenge().getId());
Expand All @@ -286,21 +287,21 @@ public void newFamilyUserNotification(User newFamilyUser, List<FamilyUser> famil
familyUserList.forEach(familyUser -> {
User user = familyUser.getUser();
Boolean checkServiceOptIn = checkServiceOptIn(user, title, notificationBody,
notificationCategory);
notificationCategory, "");
if (checkServiceOptIn) {
expoNotificationService.sendMessage(user, title, notificationBody, newMap,
notificationCategory);
notificationCategory, "");
}
log.info("기존 가족 구성원 id = {}에게 유저 id = {}의 가족 참여 알림 전송", familyUser.getUser().getId(),
newFamilyUser.getId());
});
}

private Boolean checkServiceOptIn(User user, String title, String body,
NotificationCategory notificationCategory) {
NotificationCategory notificationCategory, String linkUrl) {
if (!user.getServiceOptIn()) {
Notification notification = Notification.builder().user(user).title(title).message(body)
.notificationCategory(notificationCategory)
.notificationCategory(notificationCategory).linkUrl(linkUrl)
.build();
notificationRepository.save(notification);
return false;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/ceos/bankids/domain/Notification.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public class Notification extends AbstractTimestamp {
@Enumerated(EnumType.STRING)
private NotificationCategory notificationCategory;

@Column(nullable = false)
private String linkUrl;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "userId", nullable = false)
private User user;
Expand All @@ -58,6 +61,7 @@ public Notification(
String message,
Boolean isRead,
NotificationCategory notificationCategory,
String linkUrl,
User user
) {

Expand All @@ -66,6 +70,7 @@ public Notification(
this.message = message;
this.isRead = isRead;
this.notificationCategory = notificationCategory;
this.linkUrl = linkUrl;
this.user = user;
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/ceos/bankids/dto/NotificationDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class NotificationDTO {
@ApiModelProperty(example = "CHALLENGE")
private NotificationCategory notificationCategory;

@ApiModelProperty(example = "/")
private String linkUrl;

@ApiModelProperty(example = "2022/07/05 05:05:05")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy/MM/dd hh:mm:ss", timezone = "Asia/Seoul")
private Timestamp createdAt;
Expand All @@ -41,6 +44,7 @@ public NotificationDTO(Notification notification) {
this.message = notification.getMessage();
this.isRead = notification.getIsRead();
this.notificationCategory = notification.getNotificationCategory();
this.linkUrl = notification.getLinkUrl();
this.createdAt = notification.getCreatedAt();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void deleteAllNotification(User user) {
}

public void sendMessage(User user, String title, String body, Map<String, Object> data,
NotificationCategory notificationCategory) {
NotificationCategory notificationCategory, String linkUrl) {

String token = user.getExpoToken();
if (token == null) {
Expand Down Expand Up @@ -143,7 +143,7 @@ public void sendMessage(User user, String title, String body, Map<String, Object
}
//Todo 메서드 인자가 user로 바뀌면 데이터 베이스에 꽂기
Notification notification = Notification.builder().title(title).message(body).user(user)
.notificationCategory(notificationCategory).build();
.notificationCategory(notificationCategory).linkUrl(linkUrl).build();
notificationRepository.save(notification);
List<ExpoPushTicket> allTickets = new ArrayList<>();
for (CompletableFuture<List<ExpoPushTicket>> messageReplyFuture : messageRepliesFutures) {
Expand Down

0 comments on commit 615b3e4

Please sign in to comment.