Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,12 @@ public VoteResponse manageVoteOnDiscussion(Long problemId, Long discussionId, Vo
protected void afterVote(User voter, Long targetId) {

notificationExecutor.execute(() -> {
Discussion discussion = discussionDomainService.getDiscussionById(targetId);

try {
Discussion discussion = discussionDomainService.getDiscussionById(targetId);
Optional<NotificationCreateEvent> notificationEvent = voteDomainService.createDiscussionVoteNotification(
voter, discussion);

Optional<NotificationCreateEvent> notificationEvent = voteDomainService.createDiscussionVoteNotification(voter, discussion);

return notificationEvent.map(List::of).orElse(Collections.emptyList());
} catch (Exception ex) {
log.error("토론글 추천 알림 생성 중 에러 발생 : {}", ex.getMessage());
return Collections.emptyList();
}
return notificationEvent.map(List::of).orElse(Collections.emptyList());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,11 @@ public ReplyResponse createReply(

Reply reply = replyDomainService.createReply(discussion, user, request.parentReplyId(), request.content());

notificationExecutor.execute(() -> {
try {
List<User> notificationTargets = reply.generateNotificationTargets();

if (notificationTargets.isEmpty()) {
return Collections.emptyList();
}

return notificationTargets.stream()
.map(target -> replyDomainService.createReplyNotification(target, reply))
.toList();
} catch (Exception ex) {
log.error("댓글 알림 생성 중 에러 발생 : {}", ex.getMessage());
return Collections.emptyList();
}
});
notificationExecutor.execute(() ->
reply.generateNotificationTargets().stream()
.map(target -> replyDomainService.createReplyNotification(target, reply))
.toList()
);

return ReplyResponse.fromEntity(reply);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,12 @@ public VoteResponse manageVoteOnReply(Long problemId, Long discussionId, Long re
protected void afterVote(User voter, Long targetId) {

notificationExecutor.execute(() -> {
Reply reply = replyDomainService.getReplyById(targetId);

try {
Reply reply = replyDomainService.getReplyById(targetId);
Optional<NotificationCreateEvent> notificationEvent = voteDomainService.createReplyVoteNotification(voter,
reply);

Optional<NotificationCreateEvent> notificationEvent = voteDomainService.createReplyVoteNotification(voter, reply);

return notificationEvent.map(List::of).orElse(Collections.emptyList());
} catch (Exception ex) {
log.error("댓글 추천 알림 생성 중 에러 발생 : {}", ex.getMessage());
return Collections.emptyList();
}
return notificationEvent.map(List::of).orElse(Collections.emptyList());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
@Getter
public enum NotificationType {
/* 커뮤니티 */
COMMUNITY_REPLY("새로운 댓글이 달렸습니다.", "/problems/{problemId}/discussions/{discussionId}"),
COMMUNITY_DISCUSSION_REPLY("작성하신 토론글에 새로운 댓글이 달렸습니다.", "/problems/{problemId}/discussions/{discussionId}"),
COMMUNITY_CHILD_REPLY("작성하신 댓글에 새로운 대댓글이 달렸습니다.", "/problems/{problemId}/discussions/{discussionId}"),
COMMUNITY_DISCUSSION_VOTED_UP("토론글에 추천을 받았습니다.", "/problems/{problemId}/discussions/{discussionId}"),
COMMUNITY_REPLY_VOTED_UP("댓글에 추천을 받았습니다.", "/problems/{problemId}/discussions/{discussionId}/replies/{replyId}"),
COMMUNITY_MENTIONED("멘션", ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public record DiscussionVotePayload(
Long problemId,
Long discussionId,
Long voterId,
String voterNickname
) implements NotificationPayload {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

public record ReplyCreatePayload(
Long problemId,
Long replyId,
Long discussionId,
Long replyId,
Long parentReplyId,
Long authorId,
String authorNickname,
String content
) implements NotificationPayload {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public record ReplyVotePayload(
Long problemId,
Long replyId,
Long voterId,
String voterNickname
) implements NotificationPayload {
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Long getProblemId() {

public List<User> generateNotificationTargets() {

Set<User> targets = new HashSet<>(); // 중복 방지를 위해 Set 사용
Set<User> targets = new HashSet<>();

User discussionAuthor = discussion.getUser();
User parentAuthor = this.getParentReplyUser();
Expand All @@ -108,4 +108,9 @@ public List<User> generateNotificationTargets() {

return new ArrayList<>(targets);
}

public Long getParentReplyId() {

return this.getParent() != null ? this.getParent().getId() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public Optional<NotificationCreateEvent> createDiscussionVoteNotification(User v
DiscussionVotePayload payload = new DiscussionVotePayload(
discussion.getProblemId(),
discussion.getId(),
voter.getId(),
voter.getNickname()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,24 @@ public void validateIsAuthor(Reply reply, Long userId) {

public NotificationCreateEvent createReplyNotification(User target, Reply reply) {

Long parentReplyId = reply.getParentReplyId();
User author = reply.getUser();

ReplyCreatePayload payload = new ReplyCreatePayload(
reply.getProblemId(),
reply.getId(),
reply.getDiscussionId(),
reply.getId(),
parentReplyId,
author.getId(),
author.getNickname(),
reply.getContent()
);

return NotificationCreateEvent.of(
target.getEmail(),
NotificationType.COMMUNITY_REPLY,
parentReplyId == null
? NotificationType.COMMUNITY_DISCUSSION_REPLY
: NotificationType.COMMUNITY_CHILD_REPLY,
payload
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public Optional<NotificationCreateEvent> createReplyVoteNotification(User voter,
ReplyVotePayload payload = new ReplyVotePayload(
reply.getProblemId(),
reply.getId(),
voter.getId(),
voter.getNickname()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public record NotificationResponse(

NotificationType notificationType,

String message,

String redirectUrl,

NotificationPayload payload,

boolean isRead,
Expand All @@ -25,6 +29,8 @@ public static NotificationResponse from(NotificationDocument document) {
return new NotificationResponse(
document.getId(),
document.getNotificationType(),
document.getNotificationType().getMessage(),
document.getNotificationType().getRedirectUrl(),
document.getPayload(),
document.isRead(),
document.getCreatedAt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ public class NotificationController {

@Operation(
summary = "알림 목록 조회",
description = "현재 사용자(authUser)의 알림을 페이징하여 조회 요청을 보냅니다.",
description = """
현재 사용자(authUser)의 알림을 페이징하여 조회 요청을 보냅니다.
해당 API는 요청만 날릴 뿐 실제 알림 데이터는 웹소켓을 통해 전달 받습니다.
웹소켓 구독 경로는 다음과 같습니다.

- 신규 알림 : /user/queue/notification
- 알림 목록 : /user/queue/notifications

자세한 내용은 다음 [링크](https://www.notion.so/teamsparta/1-5-2002dc3ef51481e7afbec86e90d0010e?p=2232dc3ef51480638fd9eecc3b90a0fc&pm=s) 참고
""",
parameters = {
@Parameter(name = "pageable", description = "페이징 정보 (page, size, sort)")
}
Expand Down