Skip to content

Commit

Permalink
Merge pull request #215 from bankidz/feature/notificationLink
Browse files Browse the repository at this point in the history
feat: notification 테이블 및 dto에 linkUrl 추가 #211
  • Loading branch information
sanbonai06 authored Sep 9, 2022
2 parents 95517dc + 0825deb commit d1fcda1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public CommonResponse<AchievedChallengeListDTO> getAchievedListChallenge(
}

@ApiOperation(value = "완주한 돈길에 이자 지급하기")
@PatchMapping(value = "/interest_payment/{challengeId}", produces = "application/json; charset=utf-8")
@PatchMapping(value = "/interest-payment/{challengeId}", produces = "application/json; charset=utf-8")
public CommonResponse<AchievedChallengeDTO> patchInterestPayment(
@AuthenticationPrincipal User authUser,
@PathVariable Long challengeId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class NotificationController {
private final NotificationRepository notificationRepository;

@ApiOperation(value = "모든 유저에게 알림")
@PostMapping(value = "/all_user", produces = "application/json; charset=utf-8")
@PostMapping(produces = "application/json; charset=utf-8")
public CommonResponse<String> allSendNotification(
@RequestBody AllSendNotificationDTO allSendNotificationRequest,
@AuthenticationPrincipal User authUser) {
Expand All @@ -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 @@ -389,7 +389,8 @@ public ChallengeDTO updateChallengeStatus(User user, Long challengeId,
challengeRepository.save(challenge);
progressDTOList = null;
}
notificationController.notification(challenge, user);

notificationController.notification(challenge, cUser);
return new ChallengeDTO(challenge, progressDTOList, challenge.getComment());
}

Expand Down Expand Up @@ -549,7 +550,7 @@ private void sundayValidation() {
nowCal.setTime(nowTimestamp);
DayOfWeek dayOfWeek = now.getDayOfWeek();
int value = dayOfWeek.getValue();
if (value == 8) { // test환경에선 접근이 안되는 8로 실환경에선 일요일인 7로 설정
if (value == 7) { // test환경에선 접근이 안되는 8로 실환경에선 일요일인 7로 설정
throw new ForbiddenException(ErrorCode.SUNDAY_ERROR.getErrorCode());
}
}
Expand Down Expand Up @@ -626,7 +627,7 @@ public void challengeCompleteDeleteByKid(User user, FamilyRequest familyRequest)
kid.setSavings(0L);
kid.setTotalChallenge(0L);
kid.setAchievedChallenge(0L);
kid.setLevel(0L);
kid.setLevel(1L);
kidRepository.save(kid);
Family family = familyRepository.findByCode(familyRequest.getCode())
.orElseThrow(() -> new ForbiddenException(ErrorCode.FAMILY_NOT_EXISTS.getErrorCode()));
Expand Down
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 d1fcda1

Please sign in to comment.