Skip to content

Commit e36f591

Browse files
committed
:spakrles:Feat: 대댓글 알림 기능 구현
1 parent 5e857f0 commit e36f591

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

src/main/java/com/be/sportizebe/domain/comment/service/CommentServiceImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,14 @@ public CommentResponse createComment(Long postId, CreateCommentRequest request,
6666
Comment comment = request.toEntity(post, user, parent);
6767
Comment savedComment = commentRepository.save(comment);
6868

69-
// 게시글 작성자에게 알림 전송
70-
notificationService.createCommentNotification(savedComment);
69+
// 알림 전송
70+
if (savedComment.getParent() != null) {
71+
// 대댓글인 경우: 부모 댓글 작성자에게 알림
72+
notificationService.createReplyNotification(savedComment);
73+
} else {
74+
// 일반 댓글인 경우: 게시글 작성자에게 알림
75+
notificationService.createCommentNotification(savedComment);
76+
}
7177

7278
return CommentResponse.from(savedComment);
7379
}

src/main/java/com/be/sportizebe/domain/notification/entity/Notification.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
})
2121
public class Notification extends BaseTimeEntity {
2222

23-
// TODO : 알람 종류 구체화해서 수정
2423
public enum NotificationType {
2524
JOIN_REQUEST, // 가입 신청 (동호회장에게)
2625
JOIN_APPROVED, // 가입 승인 (신청자에게)
2726
JOIN_REJECTED, // 가입 거절 (신청자에게)
2827
CHAT, // 새 채팅 메시지
29-
COMMENT // 새 댓글
28+
COMMENT, // 새 댓글 (게시글 작성자에게)
29+
REPLY // 대댓글 (부모 댓글 작성자에게)
3030
}
3131

3232
@Id

src/main/java/com/be/sportizebe/domain/notification/service/NotificationService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ public interface NotificationService {
1919
// 가입 거절 알림 생성 및 웹소켓 전송
2020
void createJoinRejectedNotification(JoinClubRequest joinRequest);
2121

22-
// 댓글 알림 생성 및 웹소켓 전송
22+
// 댓글 알림 생성 및 웹소켓 전송 (게시글 작성자에게)
2323
void createCommentNotification(Comment comment);
2424

25+
// 대댓글 알림 생성 및 웹소켓 전송 (부모 댓글 작성자에게)
26+
void createReplyNotification(Comment reply);
27+
2528
// 사용자의 모든 알림 조회
2629
List<NotificationResponse> getNotifications(User user);
2730

src/main/java/com/be/sportizebe/domain/notification/service/NotificationServiceImpl.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,32 @@ public void createCommentNotification(Comment comment) {
119119
sendNotificationToUser(postAuthor.getId(), notification);
120120
}
121121

122+
@Override
123+
@Transactional
124+
public void createReplyNotification(Comment reply) {
125+
Comment parentComment = reply.getParent();
126+
if (parentComment == null) {
127+
return;
128+
}
129+
130+
User parentAuthor = parentComment.getUser();
131+
User replier = reply.getUser();
132+
133+
// 자신의 댓글에 자신이 대댓글을 단 경우 알림 생성하지 않음
134+
if (parentAuthor.getId() == replier.getId()) {
135+
return;
136+
}
137+
138+
Notification notification = Notification.builder()
139+
.receiver(parentAuthor)
140+
.type(Notification.NotificationType.REPLY)
141+
.comment(reply)
142+
.build();
143+
144+
notificationRepository.save(notification);
145+
sendNotificationToUser(parentAuthor.getId(), notification);
146+
}
147+
122148
/**
123149
* 웹소켓으로 알림 전송
124150
*/

0 commit comments

Comments
 (0)