-
Notifications
You must be signed in to change notification settings - Fork 1
[LNK-71] domain/notification 코틀린 마이그레이션 #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
The head ref may contain hidden characters: "LNK-71-Leenk-domain-notification-\uCF54\uD2C0\uB9B0-\uB9C8\uC774\uADF8\uB808\uC774\uC158"
Changes from 23 commits
2bbe0d6
5e78777
e957861
3a186b7
f9cae6f
fd0b3eb
78df67d
a4713ff
4c3d8ed
2756c0b
7ba0535
b0a2cb1
af84645
1f4fa72
e973728
e1ad234
01d2b01
8a8687a
cb055bd
7760fdc
23f21ef
1cee64a
0a2450e
0ecce79
2c27215
904a626
135491a
16b3f1a
6cbcb68
18099c3
5172409
29eb1e5
b7c8449
a12e2a9
80e8843
7be63af
1e83fe0
b8dde76
6a8f274
7ef2c53
5bd6876
8194de3
d585c83
cddb6d6
6bae775
c2fa607
74559ae
72e3936
e215a3c
8780959
e51b6fe
98c051a
dbfd30d
3ce17aa
16cdcdf
0d291b2
5da3012
4697206
11b5758
1880574
1027e22
28c2769
ff92ce1
7334555
871db61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import leets.leenk.domain.feed.application.mapper.ReactionMapper | |
| import leets.leenk.domain.feed.domain.entity.Comment | ||
| import leets.leenk.domain.feed.domain.entity.Feed | ||
| import leets.leenk.domain.feed.domain.entity.LinkedUser | ||
| import leets.leenk.domain.feed.domain.event.FeedDomainEvent | ||
| import leets.leenk.domain.feed.domain.service.CommentDeleteService | ||
| import leets.leenk.domain.feed.domain.service.CommentGetService | ||
| import leets.leenk.domain.feed.domain.service.CommentSaveService | ||
|
|
@@ -44,6 +45,7 @@ import leets.leenk.domain.user.domain.service.NotionDatabaseService | |
| import leets.leenk.domain.user.domain.service.SlackWebhookService | ||
| import leets.leenk.domain.user.domain.service.blockuser.UserBlockService | ||
| import leets.leenk.domain.user.domain.service.user.UserGetService | ||
| import org.springframework.context.ApplicationEventPublisher | ||
| import org.springframework.data.domain.PageRequest | ||
| import org.springframework.stereotype.Service | ||
| import org.springframework.transaction.annotation.Transactional | ||
|
|
@@ -75,6 +77,7 @@ class FeedUsecase( | |
| private val feedUserMapper: FeedUserMapper, | ||
| private val reactionMapper: ReactionMapper, | ||
| private val commentMapper: CommentMapper, | ||
| private val eventPublisher: ApplicationEventPublisher, | ||
| ) { | ||
| @Transactional(readOnly = true) | ||
| fun getFeeds( | ||
|
|
@@ -211,8 +214,17 @@ class FeedUsecase( | |
| val linkedUsers = getLinkedUsers(author, request.userIds, feed) | ||
| linkedUserSaveService.saveAll(linkedUsers) | ||
|
|
||
| feedNotificationUsecase.saveNewFeedNotification(feed) | ||
| feedNotificationUsecase.saveTagNotification(feed, linkedUsers, author) | ||
| // 태그된 사용자 ID 목록 (작성자 제외) | ||
| val taggedUserIds = request.userIds.filter { it != author.id } | ||
|
|
||
| eventPublisher.publishEvent( | ||
| FeedDomainEvent.created( | ||
| feedId = feed.id!!, | ||
| authorId = author.id!!, | ||
| authorName = author.name, | ||
| taggedUserIds = taggedUserIds, | ||
| ), | ||
|
Comment on lines
219
to
224
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 피드백 받았는데 코틀린에서 단언은 지양한다고 합니당
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵! 좋습니다 형식은 수현님이 해두신 형식 따라가겠습니다 |
||
| ) | ||
| } | ||
|
|
||
| private fun getLinkedUsers( | ||
|
|
@@ -258,7 +270,20 @@ class FeedUsecase( | |
|
|
||
| // Feed를 가져올 때 Fetch Join으로 작성자를 함께 가져와 락이 함께 걸리므로 별도의 락 필요 없음. | ||
| feedUpdateService.updateTotalReaction(feed, reaction, feed.user, request.reactionCount) | ||
| feedNotificationUsecase.saveFirstReactionNotification(reaction) | ||
|
|
||
| // 업데이트된 총 공감 수 계산 | ||
| val totalReactionCount = feed.totalReactionCount + request.reactionCount | ||
|
|
||
| eventPublisher.publishEvent( | ||
| FeedDomainEvent.reacted( | ||
| feedId = feed.id!!, | ||
| feedAuthorId = feed.user.id!!, | ||
| reactorId = user.id!!, | ||
| reactorName = user.name, | ||
| previousReactionCount = previousReactionCount, | ||
| totalReactionCount = totalReactionCount, | ||
| ), | ||
| ) | ||
jj0526 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| val updatedReactionCount = previousReactionCount + request.reactionCount | ||
| notifyIfReachedReactionMilestone(previousReactionCount, updatedReactionCount, feed) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package leets.leenk.domain.feed.domain.event | ||
|
|
||
| /** | ||
| * Feed 도메인의 단일 이벤트 | ||
| * eventType으로 이벤트 종류 구분, data로 필요한 정보 전달 | ||
| */ | ||
| data class FeedDomainEvent( | ||
| val eventType: FeedEventType, | ||
| val data: Map<String, Any>, | ||
| ) { | ||
| companion object { | ||
| /** | ||
| * 피드 생성 이벤트 | ||
| */ | ||
| @JvmStatic | ||
| fun created( | ||
| feedId: Long, | ||
| authorId: Long, | ||
| authorName: String, | ||
| taggedUserIds: List<Long> = emptyList(), | ||
| ) = FeedDomainEvent( | ||
| eventType = FeedEventType.CREATED, | ||
| data = | ||
| mapOf( | ||
| "feedId" to feedId, | ||
| "authorId" to authorId, | ||
| "authorName" to authorName, | ||
| "taggedUserIds" to taggedUserIds, | ||
| ), | ||
| ) | ||
|
|
||
| /** | ||
| * 피드 공감 이벤트 | ||
| */ | ||
| @JvmStatic | ||
| fun reacted( | ||
| feedId: Long, | ||
| feedAuthorId: Long, | ||
| reactorId: Long, | ||
| reactorName: String, | ||
| previousReactionCount: Long, | ||
| totalReactionCount: Long, | ||
| ) = FeedDomainEvent( | ||
| eventType = FeedEventType.REACTED, | ||
| data = | ||
| mapOf( | ||
| "feedId" to feedId, | ||
| "feedAuthorId" to feedAuthorId, | ||
| "reactorId" to reactorId, | ||
| "reactorName" to reactorName, | ||
| "previousReactionCount" to previousReactionCount, | ||
| "totalReactionCount" to totalReactionCount, | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| // 타입 안전한 접근자 | ||
| val feedId: Long get() = data["feedId"] as Long | ||
| val authorId: Long get() = data["authorId"] as Long | ||
| val authorName: String get() = data["authorName"] as String | ||
| val taggedUserIds: List<Long> | ||
| get() = (data["taggedUserIds"] as? List<*>)?.filterIsInstance<Long>() ?: emptyList() | ||
| val feedAuthorId: Long get() = data["feedAuthorId"] as Long | ||
| val reactorId: Long get() = data["reactorId"] as Long | ||
| val reactorName: String get() = data["reactorName"] as String | ||
| val previousReactionCount: Long get() = data["previousReactionCount"] as Long | ||
| val totalReactionCount: Long get() = data["totalReactionCount"] as Long | ||
jj0526 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package leets.leenk.domain.feed.domain.event | ||
|
|
||
| /** | ||
| * Feed 도메인 이벤트 타입 | ||
| */ | ||
| enum class FeedEventType { | ||
| CREATED, // 피드 생성 | ||
| REACTED, // 피드 공감 | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
클래스명에서 이미 Notification이라는 문맥을 알 수 있으니 메서드명에서는 중복을 제거하고 markAsRead로 간결하게 줄이는 게 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋습니다