From 08a5111a920459fb3c57ef6ec8d5af8868989061 Mon Sep 17 00:00:00 2001 From: Hong0329 Date: Mon, 18 Nov 2024 01:47:25 +0900 Subject: [PATCH] feat : childComment like api --- .../service/CommentCommendService.java | 95 +++++++++++++------ .../service/NotificationQueryService.java | 3 +- 2 files changed, 67 insertions(+), 31 deletions(-) diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/comment/service/CommentCommendService.java b/WableServer/src/main/java/com/wable/www/WableServer/api/comment/service/CommentCommendService.java index e2c9ca3..407e429 100644 --- a/WableServer/src/main/java/com/wable/www/WableServer/api/comment/service/CommentCommendService.java +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/comment/service/CommentCommendService.java @@ -199,40 +199,75 @@ public void likeComment(Long memberId, Long commentId, CommentLikedRequestDto co .build(); CommentLiked savedCommentLiked = commentLikedRepository.save(commentLiked); - if(triggerMember != targetMember) { ////자신 게시물에 대한 좋아요 누르면 알림 발생 x - //노티 엔티티와 연결 - Notification notification = Notification.builder() - .notificationTargetMember(targetMember) - .notificationTriggerMemberId(triggerMember.getId()) - .notificationTriggerType(commentLikedRequestDto.notificationTriggerType()) - .notificationTriggerId(commentId) //에러수정을 위한 notificationTriggerId에 답글id 저장, 알림 조회시 답글id로 게시글id 반환하도록하기 - .isNotificationChecked(false) - .notificationText(comment.getCommentText()) - .build(); - Notification savedNotification = notificationRepository.save(notification); + if(triggerMember != targetMember) { + if(comment.getParentCommentId().equals(-1L)) { + Notification notification = Notification.builder() + .notificationTargetMember(targetMember) + .notificationTriggerMemberId(triggerMember.getId()) + .notificationTriggerType(commentLikedRequestDto.notificationTriggerType()) + .notificationTriggerId(commentId) //에러수정을 위한 notificationTriggerId에 답글id 저장, 알림 조회시 답글id로 게시글id 반환하도록하기 + .isNotificationChecked(false) + .notificationText(comment.getCommentText()) + .build(); + Notification savedNotification = notificationRepository.save(notification); - if (Boolean.TRUE.equals(targetMember.getIsPushAlarmAllowed())) { - String FcmMessageTitle = triggerMember.getNickname() + "님이 " + targetMember.getNickname() + "님의 답글을 좋아합니다."; - targetMember.increaseFcmBadge(); - FcmMessageDto commentLikeFcmMessage = FcmMessageDto.builder() - .validateOnly(false) - .message(FcmMessageDto.Message.builder() - .notificationDetails(FcmMessageDto.NotificationDetails.builder() - .title(FcmMessageTitle) - .body("") - .build()) - .token(targetMember.getFcmToken()) - .data(FcmMessageDto.Data.builder() - .name("commentLike") - .description("답글 좋아요 푸시 알림") - .relateContentId(String.valueOf(contentId)) - .build()) - .badge(targetMember.getFcmBadge()) - .build()) + if (Boolean.TRUE.equals(targetMember.getIsPushAlarmAllowed())) { + String FcmMessageTitle = triggerMember.getNickname() + "님이 " + targetMember.getNickname() + "님의 댓글을 좋아합니다."; + targetMember.increaseFcmBadge(); + FcmMessageDto commentLikeFcmMessage = FcmMessageDto.builder() + .validateOnly(false) + .message(FcmMessageDto.Message.builder() + .notificationDetails(FcmMessageDto.NotificationDetails.builder() + .title(FcmMessageTitle) + .body("") + .build()) + .token(targetMember.getFcmToken()) + .data(FcmMessageDto.Data.builder() + .name("commentLike") + .description("댓글 좋아요 푸시 알림") + .relateContentId(String.valueOf(contentId)) + .build()) + .badge(targetMember.getFcmBadge()) + .build()) + .build(); + + fcmService.sendMessage(commentLikeFcmMessage); + } + } else { + Notification notification = Notification.builder() + .notificationTargetMember(targetMember) + .notificationTriggerMemberId(triggerMember.getId()) + .notificationTriggerType("childCommentLiked") + .notificationTriggerId(commentId) + .isNotificationChecked(false) + .notificationText(comment.getCommentText()) .build(); + Notification savedNotification = notificationRepository.save(notification); + - fcmService.sendMessage(commentLikeFcmMessage); + if (Boolean.TRUE.equals(targetMember.getIsPushAlarmAllowed())) { + String FcmMessageTitle = triggerMember.getNickname() + "님이 " + targetMember.getNickname() + "님의 답글을 좋아합니다."; + targetMember.increaseFcmBadge(); + FcmMessageDto commentLikeFcmMessage = FcmMessageDto.builder() + .validateOnly(false) + .message(FcmMessageDto.Message.builder() + .notificationDetails(FcmMessageDto.NotificationDetails.builder() + .title(FcmMessageTitle) + .body("") + .build()) + .token(targetMember.getFcmToken()) + .data(FcmMessageDto.Data.builder() + .name("childCommentLike") + .description("답글 좋아요 푸시 알림") + .relateContentId(String.valueOf(contentId)) + .build()) + .badge(targetMember.getFcmBadge()) + .build()) + .build(); + + fcmService.sendMessage(commentLikeFcmMessage); + } } } } diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/notification/service/NotificationQueryService.java b/WableServer/src/main/java/com/wable/www/WableServer/api/notification/service/NotificationQueryService.java index 0f80c13..8adb850 100644 --- a/WableServer/src/main/java/com/wable/www/WableServer/api/notification/service/NotificationQueryService.java +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/notification/service/NotificationQueryService.java @@ -126,7 +126,8 @@ private long refineNotificationTriggerId (String triggerType, Long triggerId, No } //todo 추후에 인기글 -> 불꽃, 정보 -> 확성기, 시스템 -> wable로고, 사용자 -> 프로필 사진 private String profileUrl(Long notificationId, String triggerType){ - if(triggerType.equals("comment") || triggerType.equals("commentLiked") || triggerType.equals("contentLiked")){ + if(triggerType.equals("comment") || triggerType.equals("commentLiked") || triggerType.equals("contentLiked") + || triggerType.equals("childCommentLiked") || triggerType.equals("childComment")){ Notification notification = notificationRepository.findNotificationById(notificationId); Member triggerMember = memberRepository.findMemberByIdOrThrow(notification.getNotificationTriggerMemberId()); return triggerMember.getProfileUrl();