Skip to content

Commit 82e16b5

Browse files
authored
Fixed adding new comment (#2915)
1 parent 638ccb2 commit 82e16b5

3 files changed

Lines changed: 15 additions & 16 deletions

File tree

save-cloud-common/src/jvmMain/kotlin/com/saveourtool/save/entitiescosv/LnkVulnerabilityMetadataUser.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ class LnkVulnerabilityMetadataUser(
1414
// Fetching two or more Bags(List) at the same time on an Entity could form a Cartesian Product. Since a Bag doesn't have an order,
1515
// Hibernate would not be able to map the right columns to the right entities. Hence, in this case, it throws a MultipleBagFetchException.
1616
// Link to docs: https://www.baeldung.com/java-hibernate-multiplebagfetchexception#cause-of-multiplebagfetchexception
17-
17+
@Column(name = "vulnerability_metadata_id")
1818
var vulnerabilityMetadataId: Long,
1919

20+
@Column(name = "user_id")
2021
var userId: Long,
2122

2223
) : BaseEntity()

save-cosv/src/main/kotlin/com/saveourtool/save/cosv/event/CommentListener.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package com.saveourtool.save.cosv.event
22

33
import com.saveourtool.save.cosv.repository.LnkVulnerabilityMetadataUserRepository
44
import com.saveourtool.save.cosv.repositorysave.NotificationRepository
5+
import com.saveourtool.save.cosv.service.UserService
56
import com.saveourtool.save.cosv.service.VulnerabilityMetadataService
7+
import com.saveourtool.save.entities.Notification
68
import com.saveourtool.save.entities.User
79
import com.saveourtool.save.evententities.CommentEvent
810
import com.saveourtool.save.utils.orNotFound
@@ -17,6 +19,7 @@ class CommentListener(
1719
private val notificationRepository: NotificationRepository,
1820
private val vulnerabilityMetadataService: VulnerabilityMetadataService,
1921
private val lnkVulnerabilityMetadataUserRepository: LnkVulnerabilityMetadataUserRepository,
22+
private val userService: UserService,
2023
) {
2124
/**
2225
* @param commentEvent new commentEvent
@@ -43,9 +46,14 @@ class CommentListener(
4346
)
4447

4548
val message = messageNewVulnComment(commentOwner, identifier)
46-
recipients.map { userId ->
47-
notificationRepository.saveNotification(message, userId)
49+
val users = userService.findAllByIdIn(recipients)
50+
val notifications = users.map { user ->
51+
Notification(
52+
message = message,
53+
user = user,
54+
)
4855
}
56+
notificationRepository.saveAll(notifications)
4957
}
5058

5159
companion object {

save-cosv/src/main/kotlin/com/saveourtool/save/cosv/repositorysave/NotificationRepository.kt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package com.saveourtool.save.cosv.repositorysave
22

33
import com.saveourtool.save.entities.Notification
44
import com.saveourtool.save.spring.repository.BaseEntityRepository
5-
import org.springframework.data.jpa.repository.Query
6-
import org.springframework.data.repository.query.Param
75
import org.springframework.stereotype.Repository
86

97
/**
@@ -12,16 +10,8 @@ import org.springframework.stereotype.Repository
1210
@Repository
1311
interface NotificationRepository : BaseEntityRepository<Notification> {
1412
/**
15-
* @param message message of notification
16-
* @param userId id of user
17-
* @return save tag
13+
* @param name
14+
* @return list of notification
1815
*/
19-
@Query(
20-
value = "insert into save_cloud.notification (message, user_id) values (:message, :userId)",
21-
nativeQuery = true,
22-
)
23-
fun saveNotification(
24-
@Param("message") message: String,
25-
@Param("userId") userId: Long,
26-
): Notification
16+
fun findByUserName(name: String): List<Notification>
2717
}

0 commit comments

Comments
 (0)