Add Test for Notification routes
Add @JsonSubTypes on Notification return all creator on request find_follows_article_by_target Add testNotifications task
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package fr.dcproject.component.notification
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies
|
||||
import com.fasterxml.jackson.databind.SerializationFeature
|
||||
@@ -12,6 +14,10 @@ import fr.dcproject.component.article.database.ArticleForView
|
||||
import org.joda.time.DateTime
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type", visible = true)
|
||||
@JsonSubTypes(
|
||||
JsonSubTypes.Type(value = ArticleUpdateNotification::class, name = "article")
|
||||
)
|
||||
open class Notification(
|
||||
val type: String,
|
||||
val createdAt: DateTime = DateTime.now()
|
||||
|
||||
@@ -28,12 +28,12 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
class NotificationsPush private constructor(
|
||||
class NotificationsPush(
|
||||
private val redis: RedisAsyncCommands<String, String>,
|
||||
private val redisConnectionPubSub: StatefulRedisPubSubConnection<String, String>,
|
||||
citizen: CitizenI,
|
||||
incoming: Flow<Notification>,
|
||||
onRecieve: suspend (Notification) -> Unit,
|
||||
onReceive: suspend (Notification) -> Unit,
|
||||
) {
|
||||
class Builder(val redisClient: RedisClient) {
|
||||
private val redisConnection = redisClient.connect() ?: error("Unable to connect to redis")
|
||||
@@ -43,8 +43,8 @@ class NotificationsPush private constructor(
|
||||
fun build(
|
||||
citizen: CitizenI,
|
||||
incoming: Flow<Notification>,
|
||||
onRecieve: suspend (Notification) -> Unit,
|
||||
): NotificationsPush = NotificationsPush(redis, redisConnectionPubSub, citizen, incoming, onRecieve)
|
||||
onReceive: suspend (Notification) -> Unit,
|
||||
): NotificationsPush = NotificationsPush(redis, redisConnectionPubSub, citizen, incoming, onReceive)
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
fun build(ws: DefaultWebSocketServerSession): NotificationsPush {
|
||||
@@ -69,7 +69,7 @@ class NotificationsPush private constructor(
|
||||
override fun message(pattern: String?, channel: String?, message: String?) {
|
||||
runBlocking {
|
||||
getNotifications().collect {
|
||||
onRecieve(it)
|
||||
onReceive(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,10 +85,12 @@ class NotificationsPush private constructor(
|
||||
|
||||
/* Get old notification and sent it to websocket */
|
||||
runBlocking {
|
||||
getNotifications().collect { onRecieve(it) }
|
||||
getNotifications().collect {
|
||||
onReceive(it)
|
||||
}
|
||||
}
|
||||
|
||||
/* Lisen redis event, and sent the new notification into websocket */
|
||||
/* Listen redis event, and sent the new notification into websocket */
|
||||
redisConnectionPubSub.run {
|
||||
addListener(listener)
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ begin
|
||||
f.created_at,
|
||||
f.target_reference,
|
||||
json_build_object('id', f.target_id) as target,
|
||||
json_build_object('id', f.created_by_id) as created_by
|
||||
find_citizen_by_id_with_user(f.created_by_id) as created_by
|
||||
from follow_article as f
|
||||
join article a on f.target_id = a.id
|
||||
where a.version_id = _version_id
|
||||
|
||||
Reference in New Issue
Block a user