Skip to content

Commit

Permalink
chore: new post make notification to all followers in group
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiin Kim authored and Jiin Kim committed Jan 23, 2025
1 parent 6e320d9 commit 084e099
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
22 changes: 13 additions & 9 deletions src/main/kotlin/com/kogo/content/service/PostService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,19 @@ class PostService(
)
)

pushNotificationService.createPushNotification(
Notification(
recipient = savedPost.group.owner,
sender = author,
title = "A new post in your group!",
body = savedPost.title.take(50) + if (savedPost.title.length > 50) "..." else "",
),
PushNotificationService.linkToGroup(savedPost.group.id!!)
)
savedPost.group.followers.forEach {
if (it.follower.id != author.id) {
pushNotificationService.createPushNotification(
Notification(
recipient = it.follower,
sender = null,
title = "A new post in ${savedPost.group.groupName} group!",
body = savedPost.title.take(50) + if (savedPost.title.length > 50) "..." else "",
),
PushNotificationService.linkToGroup(savedPost.group.id!!)
)
}
}

return savedPost
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class Notification (
val recipient: User,

@DocumentReference
val sender: User,
val sender: User?,

val title: String,

Expand Down
14 changes: 0 additions & 14 deletions src/test/kotlin/com/kogo/content/service/PostServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@ class PostServiceTest {
)

every { postRepository.save(any()) } answers { firstArg() }
every {
pushNotificationService.createPushNotification(
any(),
any()
)
} returns mockk()

val result = postService.create(group, user, postDto)

Expand All @@ -125,7 +119,6 @@ class PostServiceTest {
assertThat(result.author).isEqualTo(user)
verify {
postRepository.save(any())
pushNotificationService.createPushNotification(any(), any())
}
}

Expand Down Expand Up @@ -326,12 +319,6 @@ class PostServiceTest {

every { fileService.uploadImage(testImage) } returns testAttachment
every { postRepository.save(any()) } answers { firstArg() }
every {
pushNotificationService.createPushNotification(
any(),
any()
)
} returns mockk()

val result = postService.create(group, user, postDto)

Expand All @@ -345,7 +332,6 @@ class PostServiceTest {
verify {
fileService.uploadImage(testImage)
postRepository.save(any())
pushNotificationService.createPushNotification(any(), any())
}
}

Expand Down

0 comments on commit 084e099

Please sign in to comment.