Skip to content

Commit b3f59af

Browse files
authored
Merge pull request #315 from THIP-TextHip/refactor/#314-notification-redirect-data-structure
[refactor] 알림 리다이렉트를 위한 데이터 구조 수정
2 parents 0913cfb + a9145c7 commit b3f59af

10 files changed

Lines changed: 99 additions & 105 deletions

File tree

src/main/java/konkuk/thip/comment/application/service/CommentCreateService.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,34 @@ public CommentCreateResponse createComment(CommentCreateCommand command) {
9393
private void sendNotificationsToPostWriter(PostQueryDto postQueryDto, User actorUser) {
9494
if (postQueryDto.creatorId().equals(actorUser.getId())) return; // 자신이 작성한 게시글 제외
9595

96-
if (postQueryDto.postType().equals(FEED.getType())) {
97-
// 피드 댓글 알림 이벤트 발행
98-
feedNotificationOrchestrator.notifyFeedCommented(postQueryDto.creatorId(), actorUser.getId(), actorUser.getNickname(), postQueryDto.postId());
99-
} else if (postQueryDto.postType().equals(RECORD.getType()) || postQueryDto.postType().equals(VOTE.getType())) {
100-
// 모임방 게시글 댓글 알림 이벤트 발행
101-
roomNotificationOrchestrator.notifyRoomPostCommented(postQueryDto.creatorId(), actorUser.getId(), actorUser.getNickname(), postQueryDto.roomId(), postQueryDto.page(), postQueryDto.postId(), postQueryDto.postType());
96+
PostType postType = PostType.from(postQueryDto.postType());
97+
switch (postType) {
98+
case FEED -> // 피드 댓글 알림 이벤트 발행
99+
feedNotificationOrchestrator.notifyFeedCommented(
100+
postQueryDto.creatorId(), actorUser.getId(), actorUser.getNickname(), postQueryDto.postId()
101+
);
102+
case RECORD, VOTE -> // 모임방 게시글 댓글 알림 이벤트 발행
103+
roomNotificationOrchestrator.notifyRoomPostCommented(
104+
postQueryDto.creatorId(), actorUser.getId(), actorUser.getNickname(),
105+
postQueryDto.roomId(), postQueryDto.page(), postQueryDto.postId(), postType
106+
);
102107
}
103108
}
104109

105110
private void sendNotificationsToParentCommentWriter(PostQueryDto postQueryDto, CommentQueryDto parentCommentDto, User actorUser) {
106111
if (parentCommentDto.creatorId().equals(actorUser.getId())) return; // 자신이 작성한 댓글 제외
107112

108-
if (postQueryDto.postType().equals(FEED.getType())) {
109-
// 피드 답글 알림 이벤트 발행
110-
feedNotificationOrchestrator.notifyFeedReplied(parentCommentDto.creatorId(), actorUser.getId(), actorUser.getNickname(), postQueryDto.postId());
111-
} else if (postQueryDto.postType().equals(RECORD.getType()) || postQueryDto.postType().equals(VOTE.getType())) {
112-
// 모임방 게시글 답글 알림 이벤트 발행
113-
roomNotificationOrchestrator.notifyRoomPostCommentReplied(parentCommentDto.creatorId(), actorUser.getId(), actorUser.getNickname(), postQueryDto.roomId(), postQueryDto.page(), postQueryDto.postId(), postQueryDto.postType());
113+
PostType postType = PostType.from(postQueryDto.postType());
114+
switch (postType) {
115+
case FEED -> // 피드 답글 알림 이벤트 발행
116+
feedNotificationOrchestrator.notifyFeedReplied(
117+
parentCommentDto.creatorId(), actorUser.getId(), actorUser.getNickname(), postQueryDto.postId()
118+
);
119+
case RECORD, VOTE -> // 모임방 게시글 답글 알림 이벤트 발행
120+
roomNotificationOrchestrator.notifyRoomPostCommentReplied(
121+
parentCommentDto.creatorId(), actorUser.getId(), actorUser.getNickname(),
122+
postQueryDto.roomId(), postQueryDto.page(), postQueryDto.postId(), postType
123+
);
114124
}
115125
}
116126

src/main/java/konkuk/thip/comment/application/service/CommentLikeService.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,19 @@ private void sendNotifications(CommentIsLikeCommand command, Comment comment) {
7171
if (command.userId().equals(comment.getCreatorId())) return; // 자신의 댓글에 좋아요 누르는 경우 제외
7272

7373
User actorUser = userCommandPort.findById(command.userId());
74-
// 좋아요 푸쉬알림 전송
75-
if (comment.getPostType() == PostType.FEED) {
76-
feedNotificationOrchestrator.notifyFeedCommentLiked(comment.getCreatorId(), actorUser.getId(), actorUser.getNickname(), comment.getTargetPostId());
77-
}
78-
if (comment.getPostType() == PostType.RECORD || comment.getPostType() == PostType.VOTE) {
79-
PostQueryDto postQueryDto = postHandler.getPostQueryDto(comment.getPostType(), comment.getTargetPostId());
80-
roomNotificationOrchestrator.notifyRoomCommentLiked(comment.getCreatorId(), actorUser.getId(), actorUser.getNickname(), postQueryDto.roomId(), postQueryDto.page(), postQueryDto.postId(), postQueryDto.postType());
74+
PostType postType = comment.getPostType();
75+
76+
switch (postType) {
77+
case FEED ->
78+
feedNotificationOrchestrator.notifyFeedCommentLiked(
79+
comment.getCreatorId(), actorUser.getId(), actorUser.getNickname(),comment.getTargetPostId()
80+
);
81+
case RECORD, VOTE -> {
82+
PostQueryDto postQueryDto = postHandler.getPostQueryDto(comment.getPostType(), comment.getTargetPostId());
83+
roomNotificationOrchestrator.notifyRoomCommentLiked(
84+
comment.getCreatorId(), actorUser.getId(), actorUser.getNickname(), postQueryDto.roomId(), postQueryDto.page(), postQueryDto.postId(), postType
85+
);
86+
}
8187
}
8288
}
8389
}

src/main/java/konkuk/thip/notification/application/port/in/RoomNotificationOrchestrator.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package konkuk.thip.notification.application.port.in;
22

3+
import konkuk.thip.post.domain.PostType;
4+
35
public interface RoomNotificationOrchestrator {
46

57
/**
@@ -9,7 +11,7 @@ public interface RoomNotificationOrchestrator {
911

1012
// ===== Room 영역 =====
1113
void notifyRoomPostCommented(Long targetUserId, Long actorUserId, String actorUsername,
12-
Long roomId, Integer page, Long postId, String postType);
14+
Long roomId, Integer page, Long postId, PostType postType);
1315

1416
void notifyRoomVoteStarted(Long targetUserId, Long roomId, String roomTitle, Integer page, Long postId);
1517

@@ -24,11 +26,11 @@ void notifyRoomJoinToHost(Long hostUserId, Long roomId, String roomTitle,
2426
Long actorUserId, String actorUsername);
2527

2628
void notifyRoomCommentLiked(Long targetUserId, Long actorUserId, String actorUsername,
27-
Long roomId, Integer page, Long postId, String postType);
29+
Long roomId, Integer page, Long postId, PostType postType);
2830

2931
void notifyRoomPostLiked(Long targetUserId, Long actorUserId, String actorUsername,
30-
Long roomId, Integer page, Long postId, String postType);
32+
Long roomId, Integer page, Long postId, PostType postType);
3133

3234
void notifyRoomPostCommentReplied(Long targetUserId, Long actorUserId, String actorUsername,
33-
Long roomId, Integer page, Long postId, String postType);
35+
Long roomId, Integer page, Long postId, PostType postType);
3436
}

src/main/java/konkuk/thip/notification/application/service/RoomNotificationOrchestratorSyncImpl.java

Lines changed: 37 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import konkuk.thip.notification.application.service.template.room.*;
77
import konkuk.thip.notification.domain.value.MessageRoute;
88
import konkuk.thip.notification.domain.value.NotificationRedirectSpec;
9+
import konkuk.thip.post.domain.PostType;
910
import lombok.RequiredArgsConstructor;
1011
import org.springframework.transaction.annotation.Propagation;
1112
import org.springframework.transaction.annotation.Transactional;
@@ -30,18 +31,10 @@ public class RoomNotificationOrchestratorSyncImpl implements RoomNotificationOrc
3031
@Override
3132
@Transactional(propagation = Propagation.MANDATORY)
3233
public void notifyRoomPostCommented(Long targetUserId, Long actorUserId, String actorUsername,
33-
Long roomId, Integer page, Long postId, String postType) {
34+
Long roomId, Integer page, Long postId, PostType postType) {
3435
var args = new RoomPostCommentedTemplate.Args(actorUsername);
3536

36-
NotificationRedirectSpec redirectSpec = new NotificationRedirectSpec(
37-
MessageRoute.ROOM_POST_DETAIL,
38-
Map.of(
39-
"roomId", roomId,
40-
"page", page,
41-
"postId", postId,
42-
"postType", postType
43-
)
44-
);
37+
NotificationRedirectSpec redirectSpec = createRoomPostWithCommentsRedirectSpec(roomId, page, postId, postType);
4538

4639
notificationSyncExecutor.execute(
4740
RoomPostCommentedTemplate.INSTANCE,
@@ -59,15 +52,7 @@ public void notifyRoomPostCommented(Long targetUserId, Long actorUserId, String
5952
public void notifyRoomVoteStarted(Long targetUserId, Long roomId, String roomTitle, Integer page, Long postId) {
6053
var args = new RoomVoteStartedTemplate.Args(roomTitle);
6154

62-
NotificationRedirectSpec redirectSpec = new NotificationRedirectSpec(
63-
MessageRoute.ROOM_VOTE_DETAIL,
64-
Map.of(
65-
"roomId", roomId,
66-
"page", page,
67-
"postId", postId,
68-
"postType", "VOTE"
69-
)
70-
);
55+
NotificationRedirectSpec redirectSpec = createRoomPostRedirectSpec(roomId, page, postId, PostType.VOTE);
7156

7257
notificationSyncExecutor.execute(
7358
RoomVoteStartedTemplate.INSTANCE,
@@ -86,15 +71,7 @@ public void notifyRoomRecordCreated(Long targetUserId, Long actorUserId, String
8671
Long roomId, String roomTitle, Integer page, Long postId) {
8772
var args = new RoomRecordCreatedTemplate.Args(roomTitle, actorUsername);
8873

89-
NotificationRedirectSpec redirectSpec = new NotificationRedirectSpec(
90-
MessageRoute.ROOM_RECORD_DETAIL,
91-
Map.of(
92-
"roomId", roomId,
93-
"page", page,
94-
"postId", postId,
95-
"postType", "RECORD"
96-
)
97-
);
74+
NotificationRedirectSpec redirectSpec = createRoomPostRedirectSpec(roomId, page, postId, PostType.RECORD);
9875

9976
notificationSyncExecutor.execute(
10077
RoomRecordCreatedTemplate.INSTANCE,
@@ -173,18 +150,10 @@ public void notifyRoomJoinToHost(Long hostUserId, Long roomId, String roomTitle,
173150
@Override
174151
@Transactional(propagation = Propagation.MANDATORY)
175152
public void notifyRoomCommentLiked(Long targetUserId, Long actorUserId, String actorUsername,
176-
Long roomId, Integer page, Long postId, String postType) {
153+
Long roomId, Integer page, Long postId, PostType postType) {
177154
var args = new RoomCommentLikedTemplate.Args(actorUsername);
178155

179-
NotificationRedirectSpec redirectSpec = new NotificationRedirectSpec(
180-
MessageRoute.ROOM_POST_DETAIL,
181-
Map.of(
182-
"roomId", roomId,
183-
"page", page,
184-
"postId", postId,
185-
"postType", postType
186-
)
187-
);
156+
NotificationRedirectSpec redirectSpec = createRoomPostWithCommentsRedirectSpec(roomId, page, postId, postType);
188157

189158
notificationSyncExecutor.execute(
190159
RoomCommentLikedTemplate.INSTANCE,
@@ -200,18 +169,10 @@ public void notifyRoomCommentLiked(Long targetUserId, Long actorUserId, String a
200169
@Override
201170
@Transactional(propagation = Propagation.MANDATORY)
202171
public void notifyRoomPostLiked(Long targetUserId, Long actorUserId, String actorUsername,
203-
Long roomId, Integer page, Long postId, String postType) {
172+
Long roomId, Integer page, Long postId, PostType postType) {
204173
var args = new RoomPostLikedTemplate.Args(actorUsername);
205174

206-
NotificationRedirectSpec redirectSpec = new NotificationRedirectSpec(
207-
MessageRoute.ROOM_POST_DETAIL,
208-
Map.of(
209-
"roomId", roomId,
210-
"page", page,
211-
"postId", postId,
212-
"postType", postType
213-
)
214-
);
175+
NotificationRedirectSpec redirectSpec = createRoomPostRedirectSpec(roomId, page, postId, postType);
215176

216177
notificationSyncExecutor.execute(
217178
RoomPostLikedTemplate.INSTANCE,
@@ -227,18 +188,10 @@ public void notifyRoomPostLiked(Long targetUserId, Long actorUserId, String acto
227188
@Override
228189
@Transactional(propagation = Propagation.MANDATORY)
229190
public void notifyRoomPostCommentReplied(Long targetUserId, Long actorUserId, String actorUsername,
230-
Long roomId, Integer page, Long postId, String postType) {
191+
Long roomId, Integer page, Long postId, PostType postType) {
231192
var args = new RoomPostCommentRepliedTemplate.Args(actorUsername);
232193

233-
NotificationRedirectSpec redirectSpec = new NotificationRedirectSpec(
234-
MessageRoute.ROOM_POST_DETAIL,
235-
Map.of(
236-
"roomId", roomId,
237-
"page", page,
238-
"postId", postId,
239-
"postType", postType
240-
)
241-
);
194+
NotificationRedirectSpec redirectSpec = createRoomPostWithCommentsRedirectSpec(roomId, page, postId, postType);
242195

243196
notificationSyncExecutor.execute(
244197
RoomPostCommentRepliedTemplate.INSTANCE,
@@ -250,4 +203,30 @@ public void notifyRoomPostCommentReplied(Long targetUserId, Long actorUserId, St
250203
)
251204
);
252205
}
206+
207+
private NotificationRedirectSpec createRoomPostWithCommentsRedirectSpec(Long roomId, Integer page, Long postId, PostType postType) {
208+
return new NotificationRedirectSpec(
209+
MessageRoute.ROOM_POST_DETAIL,
210+
Map.of(
211+
"roomId", roomId,
212+
"page", page,
213+
"postId", postId,
214+
"postType", postType,
215+
"openComments", true
216+
)
217+
);
218+
}
219+
220+
private NotificationRedirectSpec createRoomPostRedirectSpec(Long roomId, Integer page, Long postId, PostType postType) {
221+
return new NotificationRedirectSpec(
222+
MessageRoute.ROOM_POST_DETAIL,
223+
Map.of(
224+
"roomId", roomId,
225+
"page", page,
226+
"postId", postId,
227+
"postType", postType,
228+
"openComments", false
229+
)
230+
);
231+
}
253232
}

src/main/java/konkuk/thip/notification/domain/value/MessageRoute.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,5 @@ public enum MessageRoute {
1616
// ROOM
1717
ROOM_MAIN, // 특정 모임방 메인 화면으로 이동
1818
ROOM_DETAIL, // 특정 모임 상세정보 화면으로 이동
19-
ROOM_POST_DETAIL, // 특정 모임 게시글 상세 화면으로 이동 -> PostType으로 투표인지 기록인지 판단
20-
ROOM_RECORD_DETAIL, // 특정 모임 기록 상세 화면으로 이동 (기록장 조회 - 페이지 필터 걸린채로)
21-
ROOM_VOTE_DETAIL; // 특정 모임 투표 상세 화면으로 이동 (투표 조회 - 페이지 필터 걸린채로)
19+
ROOM_POST_DETAIL, // 특정 모임 게시글 상세 화면으로 이동 -> PostType으로 투표(VOTE)인지 기록(RECORD)인지 판단
2220
}

src/main/java/konkuk/thip/post/adapter/out/persistence/PostLikeCommandPersistenceAdapter.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,19 @@
22

33
import konkuk.thip.common.exception.EntityNotFoundException;
44
import konkuk.thip.post.adapter.out.persistence.repository.PostLikeJpaRepository;
5-
import konkuk.thip.feed.adapter.out.jpa.FeedJpaEntity;
65
import konkuk.thip.post.domain.PostType;
76
import konkuk.thip.feed.adapter.out.persistence.repository.FeedJpaRepository;
87
import konkuk.thip.post.adapter.out.jpa.PostJpaEntity;
98
import konkuk.thip.post.adapter.out.mapper.PostLikeMapper;
109
import konkuk.thip.post.application.port.out.PostLikeCommandPort;
11-
import konkuk.thip.roompost.adapter.out.jpa.RecordJpaEntity;
12-
import konkuk.thip.roompost.adapter.out.jpa.VoteJpaEntity;
1310
import konkuk.thip.roompost.adapter.out.persistence.repository.record.RecordJpaRepository;
1411
import konkuk.thip.user.adapter.out.jpa.UserJpaEntity;
1512
import konkuk.thip.user.adapter.out.persistence.repository.UserJpaRepository;
1613
import konkuk.thip.roompost.adapter.out.persistence.repository.vote.VoteJpaRepository;
1714
import lombok.RequiredArgsConstructor;
1815
import org.springframework.stereotype.Repository;
1916

20-
import java.util.ArrayList;
21-
import java.util.HashMap;
2217
import java.util.List;
23-
import java.util.Map;
24-
import java.util.stream.Collectors;
2518

2619
import static konkuk.thip.common.exception.code.ErrorCode.*;
2720
import static konkuk.thip.common.exception.code.ErrorCode.RECORD_NOT_FOUND;

src/main/java/konkuk/thip/post/application/service/PostLikeService.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import konkuk.thip.post.application.port.out.PostLikeCommandPort;
1212
import konkuk.thip.post.application.port.out.PostLikeQueryPort;
1313
import konkuk.thip.post.application.service.validator.PostLikeAuthorizationValidator;
14-
import konkuk.thip.post.domain.PostType;
1514
import konkuk.thip.post.domain.service.PostCountService;
1615
import konkuk.thip.user.application.port.out.UserCommandPort;
1716
import konkuk.thip.user.domain.User;
@@ -69,15 +68,20 @@ public PostIsLikeResult changeLikeStatusPost(PostIsLikeCommand command) {
6968
private void sendNotifications(PostIsLikeCommand command) {
7069
PostQueryDto postQueryDto = postHandler.getPostQueryDto(command.postType(), command.postId());
7170

72-
if(command.userId().equals(postQueryDto.creatorId())) return; // 자신의 게시글에 좋아요 누르는 경우 제외
71+
if (command.userId().equals(postQueryDto.creatorId())) return; // 자신의 게시글에 좋아요 누르는 경우 제외
7372

7473
User actorUser = userCommandPort.findById(command.userId());
75-
// 좋아요 푸쉬알림 전송
76-
if (command.postType() == PostType.FEED) {
77-
feedNotificationOrchestrator.notifyFeedLiked(postQueryDto.creatorId(), actorUser.getId(), actorUser.getNickname(), postQueryDto.postId());
78-
}
79-
if (command.postType() == PostType.RECORD || command.postType() == PostType.VOTE) {
80-
roomNotificationOrchestrator.notifyRoomPostLiked(postQueryDto.creatorId(), actorUser.getId(), actorUser.getNickname(), postQueryDto.roomId(), postQueryDto.page(), postQueryDto.postId(), postQueryDto.postType());
74+
75+
switch (command.postType()) {
76+
case FEED ->
77+
feedNotificationOrchestrator.notifyFeedLiked(
78+
postQueryDto.creatorId(), actorUser.getId(), actorUser.getNickname(), postQueryDto.postId()
79+
);
80+
case RECORD, VOTE ->
81+
roomNotificationOrchestrator.notifyRoomPostLiked(
82+
postQueryDto.creatorId(), actorUser.getId(), actorUser.getNickname(), postQueryDto.roomId(), postQueryDto.page(), postQueryDto.postId(), command.postType()
83+
);
84+
8185
}
8286
}
8387
}

src/main/java/konkuk/thip/roompost/application/service/RoomPostSearchService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class RoomPostSearchService implements RoomPostSearchUseCase {
4848
private final RoomPostAccessValidator roomPostAccessValidator;
4949
private final RoomPostQueryMapper roomPostQueryMapper;
5050

51-
private static final int DEFAULT_PAGE_SIZE = 10;
51+
private static final int DEFAULT_PAGE_SIZE = 20;
5252

5353
@Override
5454
@Transactional(readOnly = true)

0 commit comments

Comments
 (0)